SteamWar/BauSystem
Archiviert
13
0

Add VariableHolder

Dieser Commit ist enthalten in:
jojo 2020-12-21 13:15:05 +01:00
Ursprung 60e611a098
Commit 3ad8bc4a06

Datei anzeigen

@ -20,6 +20,12 @@
package de.steamwar.bausystem.world; package de.steamwar.bausystem.world;
import de.steamwar.bausystem.BauSystem; 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 de.steamwar.core.Core;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -182,7 +188,43 @@ public class ScriptListener implements Listener {
} }
private static void infoCommand(ScriptExecutor scriptExecutor, String[] args) { 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<String, Integer> 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);
}
} }
} }