From 570de88059d914f53871463a9fca071e7877e1a5 Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 29 Dec 2020 21:24:58 +0100 Subject: [PATCH] Add variable replacing for every command --- .../de/steamwar/bausystem/world/ScriptListener.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java index e7a1978..071720a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -150,6 +150,12 @@ public class ScriptListener implements Listener { continue; } + // Variable Replaces in commands. + String[] commandArgs = command.split(" "); + String[] args = Arrays.copyOfRange(commandArgs, 1, commandArgs.length); + replaceVariables(this, args); + command = commandArgs[0] + String.join(" ", args); + Bukkit.getLogger().log(Level.INFO, player.getName() + " dispatched command: " + command); Bukkit.getServer().dispatchCommand(player, command); } @@ -185,12 +191,16 @@ public class ScriptListener implements Listener { return scriptExecutor.jumpPoints.getOrDefault(args[0], -1); } - private static void infoCommand(ScriptExecutor scriptExecutor, String[] args) { + private static void replaceVariables(ScriptExecutor scriptExecutor, String[] args) { for (int i = 0; i < args.length; i++) { if (args[i].startsWith("$") && isVariable(scriptExecutor, args[i].substring(1))) { args[i] = getValue(scriptExecutor, args[i].substring(1)) + ""; } } + } + + private static void infoCommand(ScriptExecutor scriptExecutor, String[] args) { + replaceVariables(scriptExecutor, args); scriptExecutor.player.sendMessage("§eInfo§8» §7" + ChatColor.translateAlternateColorCodes('&', String.join(" ", args))); }