diff --git a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java index d22914fe..3e49505b 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java +++ b/src/cc/co/evenprime/bukkit/nocheat/NoCheat.java @@ -37,7 +37,7 @@ import org.bukkit.plugin.Plugin; * * @author Evenprime */ -public class NoCheat extends JavaPlugin { +public class NoCheat extends JavaPlugin implements CommandSender { private MovingCheck movingCheck; private BedteleportCheck bedteleportCheck; @@ -70,7 +70,7 @@ public class NoCheat extends JavaPlugin { private Level consoleLevel; private String ircTag; - + public NoCheat() { } @@ -126,7 +126,7 @@ public class NoCheat extends JavaPlugin { // parse the nocheat.yml config file setupConfig(); - + movingCheck = new MovingCheck(this, config); bedteleportCheck = new BedteleportCheck(this, config); speedhackCheck = new SpeedhackCheck(this, config); @@ -136,7 +136,7 @@ public class NoCheat extends JavaPlugin { // just for convenience checks = new Check[] { movingCheck, bedteleportCheck, speedhackCheck, airbuildCheck, itemdupeCheck, bogusitemsCheck }; - + PluginDescriptionFile pdfFile = this.getDescription(); // Get, if available, the Permissions and irc plugin @@ -305,7 +305,7 @@ public class NoCheat extends JavaPlugin { this.config = new NoCheatConfiguration(new File(NoCheatConfiguration.configFile)); else this.config.config(new File(NoCheatConfiguration.configFile)); - + config.setupFileLogger(); try { @@ -360,7 +360,23 @@ public class NoCheat extends JavaPlugin { } public void handleCustomAction(CustomAction a, Player player) { + + Bukkit.getServer().dispatchCommand(this, a.command.replace("[player]", player.getName())); System.out.println("Would execute "+a.command + " now for Player " + player.getName() ); } + + + + @Override + public void sendMessage(String message) { + // we don't receive messages + + } + + @Override + public boolean isOp() { + // We declare ourselves to be OP to be allowed to do more commands + return true; + } } \ No newline at end of file diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/CustomAction.java b/src/cc/co/evenprime/bukkit/nocheat/actions/CustomAction.java index ca9c89e0..ba7c2670 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/actions/CustomAction.java +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/CustomAction.java @@ -18,4 +18,16 @@ public class CustomAction extends Action { public String getName() { return "custom"; } + + public String getValue() { + if(firstAfter <= 1 && repeat) { + return command; + } + else if(repeat) { + return "["+firstAfter+"] "+ command; + } + else { + return "["+firstAfter+","+repeat+"] "+ command; + } + } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/AirbuildCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/AirbuildCheck.java index 306b76ee..e047d9ec 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/AirbuildCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/AirbuildCheck.java @@ -81,7 +81,7 @@ public class AirbuildCheck extends Check { // Execute actions in order for(Action a : actions) { - if(a.firstAfter >= violations) { + if(a.firstAfter <= violations) { if(a.firstAfter == violations || a.repeat) { if(a instanceof LogAction) { final Location l = event.getBlockPlaced().getLocation(); diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java index 36b6c999..36a1546a 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/MovingCheck.java @@ -453,7 +453,7 @@ public class MovingCheck extends Check { for(Action a : actions) { - if(a.firstAfter >= violations) { + if(a.firstAfter <= violations) { if(a.firstAfter == violations || a.repeat) { if(a instanceof LogAction) { // prepare log message if necessary diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/SpeedhackCheck.java b/src/cc/co/evenprime/bukkit/nocheat/checks/SpeedhackCheck.java index 7d1baa8f..4b4cb321 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/SpeedhackCheck.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/SpeedhackCheck.java @@ -128,7 +128,7 @@ public class SpeedhackCheck extends Check { if(actions == null) return; for(Action a : actions) { - if(a.firstAfter >= violations) { + if(a.firstAfter <= violations) { if(a.firstAfter == violations || a.repeat) { if(a instanceof LogAction) { String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck*2, limits[0]); diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/CustomActionOption.java b/src/cc/co/evenprime/bukkit/nocheat/config/CustomActionOption.java index 24846676..0f4afdc9 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/CustomActionOption.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/CustomActionOption.java @@ -15,28 +15,27 @@ public class CustomActionOption extends ChildOption { this.parseCommand(command); } - - private void parseCommand(String command) { + private void parseCommand(String com) { - if(command.matches("\\[[0-9]*,[a-z]*\\] .*")) { - String s[] = command.split(" ", 2); + if(com.matches("\\[[0-9]*,[a-z]*\\] .*")) { + String s[] = com.split(" ", 2); String s2[] = s[0].replace("[", "").replace("]", "").split(","); - this.firstAfter = Integer.parseInt(s2[0]); - this.repeat = Boolean.parseBoolean(s2[1]); - this.command = s[1]; + firstAfter = Integer.parseInt(s2[0]); + repeat = Boolean.parseBoolean(s2[1]); + command = s[1]; } - else if(command.matches("\\[[0-9]*\\] .*")) { - String s[] = command.split(" ", 2); - this.firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", "")); - this.repeat = true; - this.command = s[1]; + else if(com.matches("\\[[0-9]*\\] .*")) { + String s[] = com.split(" ", 2); + firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", "")); + repeat = true; + command = s[1]; } else { - this.command = command; - this.firstAfter = 1; - this.repeat = true; + firstAfter = 1; + repeat = true; + command = com; } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/NoCheatConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/NoCheatConfiguration.java index 4e15fb4e..ae25f6eb 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/NoCheatConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/NoCheatConfiguration.java @@ -4,8 +4,10 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.logging.FileHandler; import java.util.logging.Level; import java.util.logging.Logger; @@ -31,6 +33,8 @@ public class NoCheatConfiguration { private ParentOption root; + private Map actionMap = new HashMap(); + // Our personal logger private final static String loggerName = "cc.co.evenprime.nocheat"; public final Logger logger = Logger.getLogger(loggerName); @@ -208,20 +212,22 @@ public class NoCheatConfiguration { ParentOption bogusitemsNode = new ParentOption("bogusitems"); root.add(bogusitemsNode); } - + /*** CUSTOMACTIONS section ***/ { ParentOption customActionsNode = new ParentOption("customactions"); root.add(customActionsNode); - - customActionsNode.add(new CustomActionOption("mycommand", - CONFIG.getString("customactions.mycommand", "[4,8] TESTCOMMAND"))); - - customActionsNode.add(new CustomActionOption("mycommand2", - CONFIG.getString("customactions.mycommand2", "TESTCOMMAND2"))); - - customActionsNode.add(new CustomActionOption("mycommand3", - CONFIG.getString("customactions.mycommand3", "[7] TESTCOMMAND3"))); + + List customs = CONFIG.getKeys("customactions"); + if(customs != null) { + for(String s : customs) { + + CustomActionOption o = new CustomActionOption(s, CONFIG.getString("customactions."+s, "unknown")); + + customActionsNode.add(o); + actionMap.put(s, o.getCustomActionValue()); + } + } } if(!configurationFile.exists()) { @@ -261,7 +267,7 @@ public class NoCheatConfiguration { } } - public static Action[] stringToActions(String string) { + public Action[] stringToActions(String string) { List as = new LinkedList(); String[] parts = string.split(" "); @@ -273,42 +279,19 @@ public class NoCheatConfiguration { as.add(LogAction.logmed); else if(s.equals("loghigh")) as.add(LogAction.loghigh); - else if(s.equals("deny")) - as.add(CancelAction.cancel); - else if(s.equals("reset")) - as.add(CancelAction.cancel); else if(s.equals("cancel")) as.add(CancelAction.cancel); - else if(s.startsWith("custom")) { - try { - // TODO: Implement Custom Action - //as.add(new CustomAction(Integer.parseInt(s.substring(6)))); - } - catch(Exception e) { - System.out.println("NC: Couldn't parse number of custom action '" + s + "'"); - } - } - else { - System.out.println("NC: Can't parse action "+ s); + else if(actionMap.get(s) != null) + as.add(actionMap.get(s)); + else + { + System.out.println("NC: Couldn't parse custom action '" + s + "'"); } } return as.toArray(new Action[as.size()]); } - private String actionsToString(Action[] actions) { - - StringBuffer s = new StringBuffer(); - - if(actions != null) { - for(Action a : actions) { - s.append(' ').append(a.getName()); - } - } - - return s.toString().trim(); - } - /** * Write configuration file to specific filename * @param f @@ -317,7 +300,7 @@ public class NoCheatConfiguration { try { if(f.getParentFile() != null) f.getParentFile().mkdirs(); - + f.createNewFile(); BufferedWriter w = new BufferedWriter(new FileWriter(f)); @@ -332,8 +315,8 @@ public class NoCheatConfiguration { public Action[] getActionValue(String optionName) throws ConfigurationException { return stringToActions(getStringOption(optionName).getValue()); } - - + + public int getIntegerValue(String optionName) throws ConfigurationException { return getIntegerOption(optionName).getIntegerValue(); }