From 932da846a27b8ed114b35d9de87ada9302e6631f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 1 Apr 2021 21:56:31 +0200 Subject: [PATCH] Update CommandScriptVars to new SWCommand system --- .../bausystem/commands/CommandScriptVars.java | 35 ++++++++----------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java index 1b420dc..45c2d79 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandScriptVars.java @@ -5,8 +5,6 @@ import de.steamwar.bausystem.world.ScriptListener; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.*; @@ -47,18 +45,13 @@ public class CommandScriptVars extends SWCommand { } @Register - public void booleanValueCommand(Player p, String varName, @Mapper(value = "BooleanString") int value) { - valueCommand(p, varName, value); - } - - @Register - public void valueCommand(Player p, String varName, int value) { + public void booleanValueCommand(Player p, String varName, int value) { ScriptListener.GLOBAL_VARIABLES.computeIfAbsent(p, player -> new HashMap<>()).put(varName, value); p.sendMessage(BauSystem.PREFIX + varName + " auf " + value + " gesetzt"); } @Register - public void removeCommand(Player p, String varName, @Mapper(value = "ClearString") String remove) { + public void removeCommand(Player p, String varName, @Mapper(value = "Delete") String remove) { if (!ScriptListener.GLOBAL_VARIABLES.containsKey(p)) { p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert"); return; @@ -78,23 +71,23 @@ public class CommandScriptVars extends SWCommand { }); } - @Mapper(value = "ClearString", local = true) + @Mapper(value = "Delete", local = true) public TypeMapper clearStringTypeMapper() { List tabCompletes = Arrays.asList("delete", "clear", "remove"); - return SWCommandUtils.createMapper(s -> s, s -> tabCompletes); - } - - @Mapper(value = "BooleanString", local = true) - public TypeMapper booleanStringTypeMapper() { - List tabCompletes = Arrays.asList("yes", "no", "true", "false"); return SWCommandUtils.createMapper(s -> { - if (s.equalsIgnoreCase("yes") || s.equals("true")) { - return 1; - } - if (s.equalsIgnoreCase("no") || s.equals("false")) { - return 0; + if (s.equalsIgnoreCase("delete") || s.equalsIgnoreCase("clear") || s.equalsIgnoreCase("remove")) { + return s; } return null; }, s -> tabCompletes); } + + @ClassMapper(value = int.class, local = true) + public TypeMapper integerTypeMapper() { + List tabCompletes = Arrays.asList("true", "false", "yes", "no"); + return SWCommandUtils.createMapper(s -> { + if (s.equalsIgnoreCase("remove") || s.equalsIgnoreCase("clear") || s.equalsIgnoreCase("delete")) return null; + return ScriptListener.parseValue(s); + }, s -> tabCompletes); + } }