From 194fce7da52a84285e560c19e5f2f4186797e2f4 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 1 May 2021 21:49:28 +0200 Subject: [PATCH] Add Unvar and Unglobal and Global --- .../script/command/variable/Global.java | 56 ++++++++++++++++++- .../script/command/variable/Unglobal.java | 33 ++++++++++- .../script/command/variable/Unvar.java | 33 ++++++++++- .../features/script/command/variable/Var.java | 3 + 4 files changed, 122 insertions(+), 3 deletions(-) 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 79b4343f..5ea6ddf6 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 @@ -1,4 +1,58 @@ package de.steamwar.bausystem.features.script.command.variable; -public class Global { +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.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; + +@Linked(LinkageType.SCRIPT_COMMAND) +public class Global implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§eglobal §8<§7Name§8> §8[§7Value§8(§7s§8)§8]", + "", + "Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text." + }; + } + + @Override + public String command() { + return "global"; + } + + @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"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Wert"); + return true; + } + String varName = command[1]; + StringBuilder varValue = new StringBuilder(); + for (int i = 2; i < command.length; i++) { + if (varValue.length() != 0) { + varValue.append(" "); + } + varValue.append(command[i]); + } + try { + long value = Long.parseLong(varValue.toString()); + scriptExecutor.getLocalVariables().putValue(varName, new Value.LongValue(value)); + } catch (NumberFormatException e) { + String s = varValue.toString(); + if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) { + scriptExecutor.getGlobalVariables().putValue(varName, new Value.BooleanValue(s.equalsIgnoreCase("true"))); + } else { + scriptExecutor.getGlobalVariables().putValue(varName, new Value.StringValue(s)); + } + } + return true; + } } 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 b809f6c2..a6515bcb 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 @@ -1,4 +1,35 @@ package de.steamwar.bausystem.features.script.command.variable; -public class Unglobal { +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.script.ScriptExecutor; +import de.steamwar.bausystem.features.script.SpecialCommand; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; + +@Linked(LinkageType.SCRIPT_COMMAND) +public class Unglobal implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "unglobal §8<§7Name§8>", + "", + "Lösche eine Globale variable" + }; + } + + @Override + public String command() { + return "unglobal"; + } + + @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"); + return true; + } + scriptExecutor.getGlobalVariables().removeValue(command[1]); + return true; + } } 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 e3b48e9f..2875508c 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 @@ -1,4 +1,35 @@ package de.steamwar.bausystem.features.script.command.variable; -public class Unvar { +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.script.ScriptExecutor; +import de.steamwar.bausystem.features.script.SpecialCommand; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; + +@Linked(LinkageType.SCRIPT_COMMAND) +public class Unvar implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "unvar §8<§7Name§8>", + "", + "Lösche eine Locale variable" + }; + } + + @Override + public String command() { + return "unvar"; + } + + @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"); + return true; + } + scriptExecutor.getLocalVariables().removeValue(command[1]); + return true; + } } 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 750f583d..e7e4d138 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 @@ -1,5 +1,6 @@ package de.steamwar.bausystem.features.script.command.variable; +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; @@ -26,9 +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"); return true; } if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Wert"); return true; } String varName = command[1];