diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Equal.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Equal.java index 86ce535d..b8d42710 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Equal.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Equal.java @@ -1,4 +1,53 @@ package de.steamwar.bausystem.features.script.command.logic; -public class Equal { +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 Equal implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§eequal §8<§7Variable§8> §8<§7Variable§8>", + "§eequal §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>", + "", + "Vergleiche die letzten beiden Variablen und schreibe es in die erste." + }; + } + + @Override + public String command() { + return "equal"; + } + + @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; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte ein Name sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + Value result = null; + if (v1.getClass() != v2.getClass()) { + result = new Value.BooleanValue(false); + } else if (v1.asString().equals(v2.asString())) { + result = new Value.BooleanValue(true); + } else if (command.length > 4) { + result = new Value.BooleanValue(false); + } + + scriptExecutor.getLocalVariables().putValue(command[1], result); + return true; + } }