diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index 9b77e66..2746934 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -42,35 +42,6 @@ public class ScriptListener implements Listener { private static final String scriptPrefix = "§eScriptSystem§8» §7"; - private static final List scriptCommands = new ArrayList<>(); - - static { - scriptCommands.add(new ScriptCommand() { - @Override - public String command() { - return "sleep"; - } - - @Override - public boolean execute(ScriptExecutor scriptExecutor, String[] args) { - int sleepTime = 1; - if (args.length > 0) { - try { - sleepTime = Integer.parseInt(args[0]); - if (sleepTime <= 0) { - scriptExecutor.player.sendMessage(scriptPrefix + "Sleep kleiner gleich 0, default 1 GameTick"); - sleepTime = 1; - } - } catch (NumberFormatException e) { - scriptExecutor.player.sendMessage(scriptPrefix + "Sleep ohne Zahl, default 1 GameTick"); - } - } - Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), scriptExecutor::resume, sleepTime); - return false; - } - }); - } - private Set playerSet = new HashSet<>(); @EventHandler(priority = EventPriority.HIGH) @@ -131,13 +102,9 @@ public class ScriptListener implements Listener { while (index < commands.size()) { String command = commands.get(index++); - for (ScriptCommand scriptCommand : scriptCommands) { - if (command.toLowerCase().startsWith(scriptCommand.command())) { - String[] args = command.substring(scriptCommand.command().length() + 1).split(" "); - if (!scriptCommand.execute(this, args)) { - return; - } - } + if (command.toLowerCase().startsWith("sleep")) { + ScriptListener.sleepCommand(this, generateArgumentArray("sleep", command)); + return; } PlayerCommandPreprocessEvent preprocessEvent = new PlayerCommandPreprocessEvent(player, "/" + command); @@ -153,15 +120,24 @@ public class ScriptListener implements Listener { } - private interface ScriptCommand { - - String command(); - - /** - * Should return {@code true} if execution should not stop, {@code false} otherwise. - */ - boolean execute(ScriptExecutor scriptExecutor, String[] args); + private static String[] generateArgumentArray(String command, String fullCommand) { + return fullCommand.substring(command.length() + 1).split(" "); + } + private static void sleepCommand(ScriptExecutor scriptExecutor, String[] args) { + int sleepTime = 1; + if (args.length > 0) { + try { + sleepTime = Integer.parseInt(args[0]); + if (sleepTime <= 0) { + scriptExecutor.player.sendMessage(scriptPrefix + "Sleep kleiner gleich 0, default 1 GameTick"); + sleepTime = 1; + } + } catch (NumberFormatException e) { + scriptExecutor.player.sendMessage(scriptPrefix + "Sleep ohne Zahl, default 1 GameTick"); + } + } + Bukkit.getScheduler().runTaskLater(BauSystem.getPlugin(), scriptExecutor::resume, sleepTime); } }