diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java index ffe62a2d..c6ef40ac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java @@ -1,4 +1,56 @@ package de.steamwar.bausystem.features.script.command.io; -public class Input { +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.script.ScriptExecutor; +import de.steamwar.bausystem.features.script.SpecialCommand; +import de.steamwar.bausystem.features.script.variables.Value; +import de.steamwar.inventory.SWAnvilInv; +import org.bukkit.ChatColor; + +public class Input implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§einput §8<§7Variable§8> §8<§7Text§8>", + "", + "§7Fordere eine Eingabe von dem Spieler, welche in die Variable geschrieben wird. Der Text ist optional." + }; + } + + @Override + public String command() { + return "input"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name sein"); + return true; + } + StringBuilder st = new StringBuilder(); + for (int i = 2; i < command.length; i++) { + if (i != 2) { + st.append(" "); + } + st.append(command[i]); + } + SWAnvilInv swAnvilInv = new SWAnvilInv(scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString())); + swAnvilInv.setCallback(s -> { + try { + long value = Long.parseLong(s); + scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(value)); + } catch (NumberFormatException e) { + if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) { + scriptExecutor.getLocalVariables().putValue(command[1], new Value.BooleanValue(s.equalsIgnoreCase("true"))); + } else { + scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(s)); + } + } + scriptExecutor.resume(); + }); + swAnvilInv.addCloseCallback(scriptExecutor::resume); + return false; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java index ba4ab8db..f30dc4db 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java @@ -27,11 +27,11 @@ public class Global implements SpecialCommand { @Override public boolean execute(String[] command, ScriptExecutor scriptExecutor) { if (command.length <= 1) { - scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name sein"); return true; } if (command.length <= 2) { - scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert sein"); return true; } String varName = command[1]; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java index d0ab5560..65eddd8a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java @@ -26,7 +26,7 @@ public class Unglobal implements SpecialCommand { @Override public boolean execute(String[] command, ScriptExecutor scriptExecutor) { if (command.length <= 1) { - scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name sein"); return true; } scriptExecutor.getGlobalVariables().removeValue(command[1]); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java index 3186f296..b0db54cd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java @@ -26,7 +26,7 @@ public class Unvar implements SpecialCommand { @Override public boolean execute(String[] command, ScriptExecutor scriptExecutor) { if (command.length <= 1) { - scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name sein"); return true; } scriptExecutor.getLocalVariables().removeValue(command[1]); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java index b43ce079..878cb9ec 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java @@ -27,11 +27,11 @@ public class Var implements SpecialCommand { @Override public boolean execute(String[] command, ScriptExecutor scriptExecutor) { if (command.length <= 1) { - scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name sein"); return true; } if (command.length <= 2) { - scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Wert sein"); return true; } String varName = command[1];