From 25ab6a66597f40ad58a877bcfe9f34b0cd97d011 Mon Sep 17 00:00:00 2001 From: Evenprime Date: Sat, 9 Jul 2011 18:32:07 +0200 Subject: [PATCH] Added option to limit reach for block destruction + configuration file will get default values for missing boolean options instead of always false. --- plugin.yml | 2 +- .../co/evenprime/bukkit/nocheat/checks/NukeCheck.java | 10 ++++++++-- .../bukkit/nocheat/config/NoCheatConfiguration.java | 2 ++ .../bukkit/nocheat/wizard/gui/Explainations.java | 2 ++ .../co/evenprime/bukkit/nocheat/yaml/SimpleYaml.java | 9 ++++++++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/plugin.yml b/plugin.yml index 31885cd1..4ffecdc9 100644 --- a/plugin.yml +++ b/plugin.yml @@ -3,7 +3,7 @@ name: NoCheat author: Evenprime main: cc.co.evenprime.bukkit.nocheat.NoCheat -version: 1.08a +version: 1.08b softdepend: [ Permissions, CraftIRC ] diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/NukeCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/NukeCheck.java index c16666ec..554e2dbb 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/NukeCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/NukeCheck.java @@ -26,6 +26,8 @@ public class NukeCheck extends Check { private String kickMessage; private String logMessage; + private boolean limitReach; + public NukeCheck(NoCheat plugin, NoCheatConfiguration config) { super(plugin, "nuke", PermissionData.PERMISSION_NUKE, config); @@ -42,6 +44,8 @@ public class NukeCheck extends Check { logMessage = config.getStringValue("nuke.logmessage"). replace("[player]", "%1$s"); + limitReach = config.getBooleanValue("nuke.limitreach"); + setActive(config.getBooleanValue("active.nuke")); } catch (ConfigurationException e) { setActive(false); @@ -72,9 +76,11 @@ public class NukeCheck extends Check { final double y2 = y1 + 2; final double z2 = z1 + 2; - double factor = new Vector(x1 + 1, y1 + 1, z1 + 1).length(); + double factor = new Vector(x1 + 1, y1 + 1, z1 + 1).length(); - if(factor * direction.getX() >= x1 && factor * direction.getY() >= y1 && factor * direction.getZ() >= z1 && + boolean tooFarAway = limitReach && factor > 4.85D; + + if(!tooFarAway && factor * direction.getX() >= x1 && factor * direction.getY() >= y1 && factor * direction.getZ() >= z1 && factor * direction.getX() <= x2 && factor * direction.getY() <= y2 && factor * direction.getZ() <= z2) { if(data.counter > 0) { data.counter--; diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/NoCheatConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/NoCheatConfiguration.java index bda5a061..29674321 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/NoCheatConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/NoCheatConfiguration.java @@ -244,6 +244,8 @@ public class NoCheatConfiguration { SimpleYaml.getString("nuke.logmessage", "Nuke: [player] tried to nuke the world", yamlContent))); nukeNode.add(new LongStringOption("kickmessage", SimpleYaml.getString("nuke.kickmessage", "No nuking allowed", yamlContent))); + nukeNode.add(new BooleanOption("limitreach", + SimpleYaml.getBoolean("nuke.limitreach", true, yamlContent))); } diff --git a/src/cc/co/evenprime/bukkit/nocheat/wizard/gui/Explainations.java b/src/cc/co/evenprime/bukkit/nocheat/wizard/gui/Explainations.java index ba10054f..89e9b183 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/wizard/gui/Explainations.java +++ b/src/cc/co/evenprime/bukkit/nocheat/wizard/gui/Explainations.java @@ -182,6 +182,8 @@ public class Explainations { set("nuke.kickmessage", "The message that is shown to players that get kicked for nuking"); set("nuke.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("nuke.limitreach", "Deny blockbreaking over longer distances than the standard minecraft\n" + + "client allows."); } private static void set(String id, String text) { diff --git a/src/cc/co/evenprime/bukkit/nocheat/yaml/SimpleYaml.java b/src/cc/co/evenprime/bukkit/nocheat/yaml/SimpleYaml.java index ff727bf2..2a4178bd 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/yaml/SimpleYaml.java +++ b/src/cc/co/evenprime/bukkit/nocheat/yaml/SimpleYaml.java @@ -121,7 +121,14 @@ public class SimpleYaml { public static boolean getBoolean(String path, boolean defaultValue, Map node) { try { - return Boolean.parseBoolean((String)getProperty(path, node)); + if(((String)getProperty(path, node)).equals("true")) { + return true; + } else if(((String)getProperty(path, node)).equals("false")) { + return false; + } + else { + return defaultValue; + } } catch(Exception e) { //e.printStackTrace();