Detect and kick players that activate the infinite durability hack

This commit is contained in:
Evenprime 2011-08-20 21:33:47 +02:00
parent 624e04393f
commit bc35207828
7 changed files with 134 additions and 8 deletions

View File

@ -3,7 +3,7 @@ name: NoCheat
author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheat
version: 1.13c
version: 1.14
softdepend: [ Permissions, CraftIRC ]
@ -33,6 +33,7 @@ permissions:
nocheat.flying: true
nocheat.fakesneak: true
nocheat.fastswim: true
nocheat.infinitedurability: true
nocheat.moving:
description: Allow to player to move/fly without getting checked at all
default: op
@ -60,6 +61,6 @@ permissions:
nocheat.fastswim:
description: Allow the player to swim at normal walking speed
default: op
nocheat.infinitedurability:
description: Allow the player to use a known infinite item durability hack
default: op

View File

@ -17,6 +17,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.CustomAction;
import cc.co.evenprime.bukkit.nocheat.checks.AirbuildCheck;
import cc.co.evenprime.bukkit.nocheat.checks.BogusitemsCheck;
import cc.co.evenprime.bukkit.nocheat.checks.Check;
import cc.co.evenprime.bukkit.nocheat.checks.InfinitedurabilityCheck;
import cc.co.evenprime.bukkit.nocheat.checks.NukeCheck;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
import cc.co.evenprime.bukkit.nocheat.checks.SpeedhackCheck;
@ -70,12 +71,14 @@ public class NoCheat extends JavaPlugin {
private Level consoleLevel;
private String ircTag;
private NukeCheck nukeCheck;
private InfinitedurabilityCheck infiniteCheck;
private DataManager dataManager;
private CustomCommandSender sender;
private boolean showStartupMessages = true;
public NoCheat() {
}
@ -152,9 +155,10 @@ public class NoCheat extends JavaPlugin {
airbuildCheck = new AirbuildCheck(this, config);
bogusitemsCheck = new BogusitemsCheck(this, config);
nukeCheck = new NukeCheck(this, config);
infiniteCheck = new InfinitedurabilityCheck(this, config);
// just for convenience
checks = new Check[] {movingCheck, speedhackCheck, airbuildCheck, bogusitemsCheck, nukeCheck};
checks = new Check[] {movingCheck, speedhackCheck, airbuildCheck, bogusitemsCheck, nukeCheck, infiniteCheck};
if(!this.getServer().getAllowFlight() && movingCheck.isActive()) {
Logger.getLogger("Minecraft").warning("[NoCheat] you have set \"allow-flight=false\" in your server.properties file. That builtin anti-flying-mechanism will likely conflict with this plugin. Please consider deactivating it by setting it to \"true\"");

View File

@ -0,0 +1,75 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.NoCheatConfiguration;
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
import cc.co.evenprime.bukkit.nocheat.listeners.InfinitedurabilityListener;
public class InfinitedurabilityCheck extends Check {
private String logMessage;
private String kickMessage;
private boolean kick;
public InfinitedurabilityCheck(NoCheat plugin, NoCheatConfiguration config) {
super(plugin, "infinitedurability", PermissionData.PERMISSION_INFINITEDURABILITY, config);
}
public void check(PlayerItemHeldEvent event) {
if(skipCheck(event.getPlayer()))
return;
if(event.getNewSlot() == 9) {
Player player = event.getPlayer();
String logString = String.format(logMessage, player.getName());
plugin.log(Level.SEVERE, logString);
if(kick) {
player.kickPlayer(kickMessage);
}
}
}
@Override
public void configure(NoCheatConfiguration config) {
try {
setActive(config.getBooleanValue("active.infinitedurability"));
logMessage = config.getStringValue("infinitedurability.logmessage");
logMessage = logMessage.replace("[player]", "%1$s");
kickMessage = config.getStringValue("infinitedurability.kickmessage");
kick = config.getBooleanValue("infinitedurability.kick");
} catch(ConfigurationException e) {
setActive(false);
e.printStackTrace();
}
}
@Override
protected void registerListeners() {
PluginManager pm = Bukkit.getServer().getPluginManager();
// Register listeners for itemdupe check
Listener bogusitemsPlayerListener = new InfinitedurabilityListener(this);
// Register listeners for itemdupe check
pm.registerEvent(Event.Type.PLAYER_ITEM_HELD, bogusitemsPlayerListener, Priority.Lowest, plugin);
}
}

View File

@ -97,6 +97,7 @@ public class NoCheatConfiguration {
activeNode.add(new BooleanOption("airbuild", SimpleYaml.getBoolean("active.airbuild", false, yamlContent)));
activeNode.add(new BooleanOption("bogusitems", SimpleYaml.getBoolean("active.bogusitems", false, yamlContent)));
activeNode.add(new BooleanOption("nuke", SimpleYaml.getBoolean("active.nuke", false, yamlContent)));
activeNode.add(new BooleanOption("infinitedurability", SimpleYaml.getBoolean("active.infinitedurability", true, yamlContent)));
}
/*** SPEEDHACK section ***/
@ -219,6 +220,18 @@ public class NoCheatConfiguration {
}
/*** INFINITE_DURABILITY section ***/
{
ParentOption nukeNode = new ParentOption("infinitedurability", false);
root.add(nukeNode);
nukeNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("infinitedurability.checkops", false, yamlContent)));
nukeNode.add(new LongStringOption("logmessage", SimpleYaml.getString("infinitedurability.logmessage", "InfDur: [player] tries to use an infinite durability hack", yamlContent)));
nukeNode.add(new LongStringOption("kickmessage", SimpleYaml.getString("infinitedurability.kickmessage", "No infinite durability hacks allowed", yamlContent)));
nukeNode.add(new BooleanOption("kick", SimpleYaml.getBoolean("infinitedurability.kick", true, yamlContent)));
}
/*** CUSTOMACTIONS section ***/
{
ParentOption customActionsNode = new ParentOption("customactions", true);

View File

@ -2,10 +2,11 @@ package cc.co.evenprime.bukkit.nocheat.data;
public class PermissionData {
public final long lastUpdate[] = new long[11];
public final boolean cache[] = new boolean[11];
private static final int size = 12;
public final long lastUpdate[] = new long[size];
public final boolean cache[] = new boolean[size];
public static final String[] permissionNames = new String[11];
public static final String[] permissionNames = new String[size];
public static final int PERMISSION_MOVING = 0;
public static final int PERMISSION_FLYING = 1;
@ -18,6 +19,7 @@ public class PermissionData {
public static final int PERMISSION_FAKESNEAK = 8;
public static final int PERMISSION_FASTSWIM = 9;
public static final int PERMISSION_NUKE = 10;
public static final int PERMISSION_INFINITEDURABILITY = 11;
static {
permissionNames[PERMISSION_AIRBUILD] = "nocheat.airbuild";
@ -31,5 +33,6 @@ public class PermissionData {
permissionNames[PERMISSION_FAKESNEAK] = "nocheat.fakesneak";
permissionNames[PERMISSION_FASTSWIM] = "nocheat.fastswim";
permissionNames[PERMISSION_NUKE] = "nocheat.nuke";
permissionNames[PERMISSION_INFINITEDURABILITY] = "nocheat.infinitedurability";
}
}

View File

@ -0,0 +1,21 @@
package cc.co.evenprime.bukkit.nocheat.listeners;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.event.player.PlayerListener;
import cc.co.evenprime.bukkit.nocheat.checks.InfinitedurabilityCheck;
public class InfinitedurabilityListener extends PlayerListener {
private final InfinitedurabilityCheck check;
public InfinitedurabilityListener(InfinitedurabilityCheck check) {
this.check = check;
}
@Override
public void onItemHeldChange(PlayerItemHeldEvent event) {
check.check(event);
}
}

View File

@ -36,6 +36,7 @@ public class Explainations {
"Because this is done by most 'nuke' hack-clients, it is easy to prevent (for now). If a player tries destroying\n" +
"blocks that are outside his field of sight, he'll get kicked from the server.\n" +
"This is only a temporary solution (and will probably not hold for long), but it's better than nothing, I guess...");
set("active.infinitedurability", "If activated, it will be detected when players activate the infinite durability hack.");
set("newpermsystem", "If activated, NoCheat will fully rely on the new Permission system of Bukkit, introduced with build 1000.\n" +
"This only makes sense if you also have a permission plugin that is capable of managing permissions in the new system.");
@ -207,6 +208,14 @@ public class Explainations {
"to not check them, e.g. they got the relevant permission from a Permissions plugin.");
set("nuke.limitreach", "Deny blockbreaking over longer distances than the standard minecraft\n" +
"client allows.");
set("infinitedurability.logmessage", "The message that appears in your logs if somebody tries to use the hack");
set("infinitedurability.kickmessage", "The message that is shown to players that get kicked for hacking");
set("infinitedurability.checkops", "Also check players with OP-status, unless there is another reason\n" +
"to not check them, e.g. they got the relevant permission from a Permissions plugin.");
set("infinitedurability.kick", "Kick the player if hacking. Please not that if you decide to not kick players,\n" +
"the log message about hacking will only appear once, not every time they use the infinite durability\n" +
"item. It is strongly recommended to kick the players!");
}
private static void set(String id, String text) {