From 3ad8bc4a06bb37aa4189816978039a12ae7735ce Mon Sep 17 00:00:00 2001 From: jojo Date: Mon, 21 Dec 2020 13:15:05 +0100 Subject: [PATCH] Add VariableHolder --- .../bausystem/world/ScriptListener.java | 44 ++++++++++++++++++- 1 file changed, 43 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 98470ea..23b21b5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/world/ScriptListener.java @@ -20,6 +20,12 @@ package de.steamwar.bausystem.world; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.commands.CommandFire; +import de.steamwar.bausystem.commands.CommandFreeze; +import de.steamwar.bausystem.commands.CommandNV; +import de.steamwar.bausystem.commands.CommandTNT; +import de.steamwar.bausystem.tracer.TraceManager; +import de.steamwar.bausystem.tracer.recorder.RecordManager; import de.steamwar.core.Core; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -182,7 +188,43 @@ public class ScriptListener implements Listener { } private static void infoCommand(ScriptExecutor scriptExecutor, String[] args) { - scriptExecutor.player.sendMessage(BauSystem.PREFIX + ChatColor.translateAlternateColorCodes('&', String.join(" ", args))); + scriptExecutor.player.sendMessage("§eInfo§8» §7" + ChatColor.translateAlternateColorCodes('&', String.join(" ", args))); + } + + private class VariableHolder { + + private Map variables = new HashMap<>(); + + public void setValue(String key, String value) { + int internalValue = 0; + if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes")) { + internalValue = 1; + } else if (value.equalsIgnoreCase("false") || value.equalsIgnoreCase("no")) { + internalValue = 0; + } else { + try { + internalValue = Integer.parseInt(value); + } catch (NumberFormatException e) { + internalValue = 0; + } + } + variables.put(key, internalValue); + } + + public int getValue(String key) { + switch (key) { + case "trace": + return RecordManager.getStatus().isTracing() ? 1 : 0; + case "tnt": + return CommandTNT.getInstance().isOn() ? 1 : 0; + case "freeze": + return CommandFreeze.getInstance().isOn() ? 1 : 0; + case "fire": + return CommandFire.getInstance().isOn() ? 1 : 0; + } + return variables.getOrDefault(key, 0); + } + } }