diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java index 7fcfd937..5a44dbe9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java @@ -25,4 +25,20 @@ public interface SpecialCommand { default String asString(String value) { return value; } + + default void jumpToIndex(ScriptExecutor scriptExecutor, String jumpPoint) { + scriptExecutor.jumpPoints.computeIfPresent(jumpPoint, (s, integer) -> { + scriptExecutor.setIndex(integer); + return integer; + }); + } + + default void jumpToIndexWithMessage(ScriptExecutor scriptExecutor, String jumpPoint, String message) { + Integer jp = scriptExecutor.jumpPoints.getOrDefault(jumpPoint, null); + if (jp == null) { + scriptExecutor.getPlayer().sendMessage(message); + return; + } + scriptExecutor.setIndex(jp); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java index 95bd48ed..7f5db48e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java @@ -42,12 +42,13 @@ public class If implements SpecialCommand { if (command[2].equals("exists")) { if (scriptExecutor.isVariable(command[1])) { - setIndex(scriptExecutor, command[3]); + jumpToIndex(scriptExecutor, command[3]); } else { if (command.length > 4) { - setIndex(scriptExecutor, command[4]); + jumpToIndex(scriptExecutor, command[4]); } } + return true; } Value v1 = scriptExecutor.getOrItselfValue(command[1]); @@ -55,20 +56,15 @@ public class If implements SpecialCommand { if (v1.getClass() != v2.getClass()) { // This is intended if (command.length > 4) { - scriptExecutor.setIndex((int) asLong(command[4])); + jumpToIndex(scriptExecutor, command[4]); } return true; } if (v1.asString().equals(v2.asString())) { - setIndex(scriptExecutor, command[3]); + jumpToIndex(scriptExecutor, command[3]); } else if (command.length > 4) { - setIndex(scriptExecutor, command[4]); + jumpToIndex(scriptExecutor, command[4]); } return true; } - - private void setIndex(ScriptExecutor scriptExecutor, String name) { - Integer jp = scriptExecutor.jumpPoints.getOrDefault(name, null); - if (jp != null) scriptExecutor.setIndex(jp); - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java index 60bb28a4..9c9bcbdc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java @@ -29,12 +29,7 @@ public class Jump implements SpecialCommand { scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt"); return true; } - Integer jumpPoint = scriptExecutor.jumpPoints.getOrDefault(command[1], null); - if (jumpPoint == null) { - scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDer Jump-Point (" + command[1] + ") ist nicht definiert."); - return true; - } - scriptExecutor.setIndex(jumpPoint); + jumpToIndexWithMessage(scriptExecutor, command[1], BauSystem.PREFIX + "§cDer Jump-Point (" + command[1] + ") ist nicht definiert."); return true; } }