diff --git a/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java b/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java new file mode 100644 index 00000000..2680ee71 --- /dev/null +++ b/src/cc/co/evenprime/bukkit/nocheat/actions/types/DummyAction.java @@ -0,0 +1,13 @@ +package cc.co.evenprime.bukkit.nocheat.actions.types; + +/** + * This is only used to not lose config entries in case an action isn't defined correctly + * + */ +public class DummyAction extends Action { + + public DummyAction(String name, int delay, int repeat) { + super(name, delay, repeat); + } + +} diff --git a/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java b/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java index 50c3949b..1ee6b6fd 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java +++ b/src/cc/co/evenprime/bukkit/nocheat/checks/Check.java @@ -9,6 +9,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.actions.types.Action; import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard; import cc.co.evenprime.bukkit.nocheat.actions.types.ConsolecommandAction; +import cc.co.evenprime.bukkit.nocheat.actions.types.DummyAction; import cc.co.evenprime.bukkit.nocheat.actions.types.LogAction; import cc.co.evenprime.bukkit.nocheat.actions.types.SpecialAction; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; @@ -51,6 +52,8 @@ public abstract class Check { special = true; } else if(ac instanceof ConsolecommandAction) { executeConsoleCommand((ConsolecommandAction) ac, this, player, cc); + } else if(ac instanceof DummyAction) { + // nothing - it's a "DummyAction" after all } } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java index 66f3c5d0..122d5ac3 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/FlatFileConfiguration.java @@ -7,8 +7,11 @@ import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; +import java.util.LinkedList; +import java.util.List; import cc.co.evenprime.bukkit.nocheat.actions.types.Action; +import cc.co.evenprime.bukkit.nocheat.actions.types.DummyAction; import cc.co.evenprime.bukkit.nocheat.config.util.ActionList; import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper; import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode; @@ -100,8 +103,20 @@ public class FlatFileConfiguration extends Configuration { al = new ActionList(); } int th = Integer.parseInt(treshold); - al.setActions(th, action.getActions(value.split("\\s+"))); + List actions = new LinkedList(); + + for(String name : value.split("\\s+")) { + Action a2 = action.getAction(name); + if(a2 == null) { + System.out.println("Nocheat: Action with name " + name + " isn't defined. You need to define it in your actions.txt file to make it work."); + actions.add(new DummyAction(name, 0, 0)); + } else { + actions.add(action.getAction(name)); + } + } + + al.setActions(th, actions.toArray(new Action[actions.size()])); return al; } @@ -184,6 +199,7 @@ public class FlatFileConfiguration extends Configuration { for(String line : explainationLines) { w.write("# " + line); + w.newLine(); } } diff --git a/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java b/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java index 167deaf6..46c1be5f 100644 --- a/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java +++ b/src/cc/co/evenprime/bukkit/nocheat/config/util/ActionMapper.java @@ -30,4 +30,9 @@ public class ActionMapper { return result; } + + public Action getAction(String actionName) { + + return this.actions.get(actionName.toLowerCase()); + } }