diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java index dd98229c..eb7a1d33 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/bau/InfoCommand.java @@ -41,9 +41,14 @@ public class InfoCommand extends SWCommand { public void sendBauInfo(Player p) { p.sendMessage(BauSystem.PREFIX + "Besitzer: §e" + SteamwarUser.get(bauServer.getOwnerID()).getUserName()); Region region = Region.getRegion(p.getLocation()); - p.sendMessage(BauSystem.PREFIX + "§eTNT§8: " + region.get(Flag.TNT).getChatValue().toUpperCase() + " §eFire§8: " + region.get(Flag.FIRE).getChatValue().toUpperCase() + " §eFreeze§8: " + region.get(Flag.FREEZE).getChatValue().toUpperCase()); - if (region.getFloorLevel() != 0) { - p.sendMessage(BauSystem.PREFIX + "§eProtect§8: " + region.get(Flag.PROTECT).getChatValue().toUpperCase()); + for (Flag flag : Flag.getFlags()) { + if (flag == Flag.PROTECT && region.getFloorLevel() == 0) { + continue; + } + Flag.Value value = region.get(flag); + if (value != null) { + p.sendMessage(BauSystem.PREFIX + "§e" + flag.getChatValue() + "§8: §7" + value.getChatValue()); + } } List members = BauweltMember.getMembers(bauServer.getOwnerID()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java index a4bda941..a7ea193f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/RegionCommand.java @@ -7,6 +7,7 @@ import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.linkage.LinkedInstance; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.flags.flagvalues.ColorMode; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; @@ -53,7 +54,7 @@ public class RegionCommand extends SWCommand { if(checkGlobalRegion(region, p)) return; if (region.undo()) { - p.sendMessage(BauSystem.PREFIX + "Letzte Aktion rückgangig gemacht"); + RegionUtils.message(region, BauSystem.PREFIX + "§7Letzte Aktion rückgangig gemacht"); } else { p.sendMessage(BauSystem.PREFIX + "§cNichts zum rückgängig machen"); } @@ -70,7 +71,7 @@ public class RegionCommand extends SWCommand { } if (region.redo()) { - p.sendMessage(BauSystem.PREFIX + "Letzte Aktion wiederhohlt"); + RegionUtils.message(region, BauSystem.PREFIX + "§7Letzte Aktion wiederhohlt"); } else { p.sendMessage(BauSystem.PREFIX + "§cNichts zum wiederhohlen"); } @@ -94,7 +95,7 @@ public class RegionCommand extends SWCommand { try { region.reset(null, RegionType.NORMAL, RegionExtensionType.NORMAL, true); - p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + RegionUtils.message(region, BauSystem.PREFIX + "§7Region zurückgesetzt"); } catch (IOException e) { p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); @@ -114,7 +115,7 @@ public class RegionCommand extends SWCommand { } try { region.reset(schem, RegionType.NORMAL, RegionExtensionType.NORMAL, true); - p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + RegionUtils.message(region, BauSystem.PREFIX + "§7Region zurückgesetzt"); } catch (IOException e) { p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java index 0790938a..7eba9b1b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/ResetCommand.java @@ -6,6 +6,7 @@ import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.command.SWCommand; import de.steamwar.sql.Schematic; @@ -35,7 +36,7 @@ public class ResetCommand extends SWCommand { if (region == null) return; try { region.reset(null, RegionType.NORMAL); - p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + RegionUtils.message(region, BauSystem.PREFIX + "§7Region zurückgesetzt"); } catch (IOException e) { p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); @@ -54,7 +55,7 @@ public class ResetCommand extends SWCommand { } try { region.reset(schem, RegionType.NORMAL); - p.sendMessage(BauSystem.PREFIX + "§7Region zurückgesetzt"); + RegionUtils.message(region, BauSystem.PREFIX + "§7Region zurückgesetzt"); } catch (IOException e) { p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen der Region"); Bukkit.getLogger().log(Level.WARNING, "Failed reset", e); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java index b2145d12..fbf6a320 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/TestblockCommand.java @@ -5,6 +5,7 @@ import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.bausystem.region.Region; +import de.steamwar.bausystem.region.RegionUtils; import de.steamwar.bausystem.region.utils.RegionExtensionType; import de.steamwar.bausystem.region.utils.RegionType; import de.steamwar.command.SWCommand; @@ -46,14 +47,13 @@ public class TestblockCommand extends SWCommand { if (region == null) return; try { region.reset(RegionType.TESTBLOCK, regionExtensionType); - p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); + RegionUtils.message(region, BauSystem.PREFIX + "§7Testblock zurückgesetzt"); } catch (IOException e) { p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks"); Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); } } - @Register public void schematicTestblockCommand(Player p, String s) { schematicTestblockCommand(p, s, RegionExtensionType.NORMAL); @@ -76,7 +76,7 @@ public class TestblockCommand extends SWCommand { } try { region.reset(schem, RegionType.TESTBLOCK, regionExtensionType); - p.sendMessage(BauSystem.PREFIX + "§7Testblock zurückgesetzt"); + RegionUtils.message(region, BauSystem.PREFIX + "§7Testblock zurückgesetzt"); } catch (IOException e) { p.sendMessage(BauSystem.PREFIX + "§cFehler beim Zurücksetzen des Testblocks"); Bukkit.getLogger().log(Level.WARNING, "Failed testblock", e); @@ -111,5 +111,4 @@ public class TestblockCommand extends SWCommand { } return region; } - } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java index 4b4a862a..0c098f8a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java @@ -106,17 +106,19 @@ public final class ScriptExecutor { variables.addAll(Constants.allVariables()); variables.addAll(globalVariables.allVariables()); - for (String variable : variables) { - s = s.replace("<" + variable + ">", getValue(variable) + ""); - } - for (String constVariable : Constants.allVariables()) { - s = s.replace("", getConstant(constVariable) + ""); - } - for (String localVariable : localVariables.allVariables()) { - s = s.replace("", getLocal(localVariable) + ""); - } - for (String globalVariable : globalVariables.allVariables()) { - s = s.replace("", getGlobal(globalVariable) + ""); + for (int i = 0; i < 2; i++) { + for (String variable : variables) { + s = s.replace("<" + variable + ">", getValue(variable) + ""); + } + for (String constVariable : Constants.allVariables()) { + s = s.replace("", getConstant(constVariable) + ""); + } + for (String localVariable : localVariables.allVariables()) { + s = s.replace("", getLocal(localVariable) + ""); + } + for (String globalVariable : globalVariables.allVariables()) { + s = s.replace("", getGlobal(globalVariable) + ""); + } } return s.split(" "); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptVarsCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptVarsCommand.java new file mode 100644 index 00000000..a3b615a9 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptVarsCommand.java @@ -0,0 +1,141 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2021 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bausystem.features.script; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.features.script.variables.Context; +import de.steamwar.bausystem.features.script.variables.Value; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import de.steamwar.command.SWCommandUtils; +import de.steamwar.command.TypeMapper; +import org.bukkit.entity.Player; + +import java.util.*; + +@Linked(LinkageType.COMMAND) +public class ScriptVarsCommand extends SWCommand { + + public ScriptVarsCommand() { + super("scriptvars"); + } + + @Register(help = true) + public void genericHelp(Player p, String... args) { + p.sendMessage("§8/§escriptvars §8- §7Zähle alle globalen Variablen auf"); + p.sendMessage("§8/§escriptvars §8[§7Variable§8] §8- §7Gebe den Wert der Variable zurück"); + p.sendMessage("§8/§escriptvars §8[§7Variable§8] §8[§7Value§8] §8- §7Setzte eine Variable auf einen Wert"); + p.sendMessage("§8/§escriptvars §8[§7Variable§8] §8<§7remove§8|§7delete§8|§7clear§8> §8- §7Lösche eine Variable"); + } + + @Register + public void genericCommand(Player p) { + Context context = ScriptListener.getGlobalContext(p); + if (context.allVariables().isEmpty()) { + p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert"); + return; + } + int i = 0; + p.sendMessage(BauSystem.PREFIX + context.allVariables().size() + " Variable(n)"); + for (Map.Entry var : context.entrySet()) { + if (i++ >= 40) break; + p.sendMessage("- " + var.getKey() + "=" + var.getValue().asString()); + } + } + + @Register + public void getCommand(Player p, String varName) { + Context context = ScriptListener.getGlobalContext(p); + if (context.allVariables().isEmpty()) { + p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert"); + return; + } + if (!context.hasValue(varName)) { + p.sendMessage(BauSystem.PREFIX + "§cUnbekannte Variable"); + return; + } + p.sendMessage(BauSystem.PREFIX + varName + "=" + context.getValue(varName).asString()); + } + + @Register + public void setValueCommand(Player p, String varName, long value) { + Context context = ScriptListener.getGlobalContext(p); + context.putValue(varName, new Value.LongValue(value)); + p.sendMessage(BauSystem.PREFIX + varName + " auf " + value + " gesetzt"); + } + + @Register + public void setValueCommand(Player p, String varName, boolean value) { + Context context = ScriptListener.getGlobalContext(p); + context.putValue(varName, new Value.BooleanValue(value)); + p.sendMessage(BauSystem.PREFIX + varName + " auf " + value + " gesetzt"); + } + + @Register + public void setValueCommand(Player p, String varName, String... value) { + Context context = ScriptListener.getGlobalContext(p); + String s = String.join(" ", value); + context.putValue(varName, new Value.StringValue(s)); + p.sendMessage(BauSystem.PREFIX + varName + " auf " + s + " gesetzt"); + } + + @Register + public void removeCommand(Player p, String varName, @Mapper(value = "Delete") String remove) { + Context context = ScriptListener.getGlobalContext(p); + if (context.allVariables().isEmpty()) { + p.sendMessage(BauSystem.PREFIX + "§cKeine globalen Variablen definiert"); + return; + } + context.removeValue(varName); + p.sendMessage(BauSystem.PREFIX + "Variable " + varName + " gelöscht"); + } + + @ClassMapper(value = String.class, local = true) + public TypeMapper stringTypeMapper() { + return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> { + if (commandSender instanceof Player) { + Player player = (Player) commandSender; + return new ArrayList<>(ScriptListener.getGlobalContext(player).allVariables()); + } + return null; + }); + } + + @Mapper(value = "Delete", local = true) + public TypeMapper clearStringTypeMapper() { + List tabCompletes = Arrays.asList("delete", "clear", "remove"); + return SWCommandUtils.createMapper(s -> { + if (s.equalsIgnoreCase("delete") || s.equalsIgnoreCase("clear") || s.equalsIgnoreCase("remove")) { + return s; + } + return null; + }, s -> tabCompletes); + } + + @ClassMapper(value = boolean.class, local = true) + public TypeMapper integerTypeMapper() { + List tabCompletes = Arrays.asList("true", "false"); + return SWCommandUtils.createMapper(s -> { + if (s.equalsIgnoreCase("remove") || s.equalsIgnoreCase("clear") || s.equalsIgnoreCase("delete")) return null; + return s.equalsIgnoreCase("true"); + }, s -> tabCompletes); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Add.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Add.java index 8729c931..4f65b91a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Add.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Add.java @@ -1,4 +1,53 @@ package de.steamwar.bausystem.features.script.command.arithmetic; -public class Add { +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 Add implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§eadd §8<§7Variable§8> §8<§7Variable§8>", + "§eadd §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>", + "", + "Addition zwischen den letzten beiden Variablen und schreibe es in die erste." + }; + } + + @Override + public String command() { + return "add"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + if (v1.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können addiert werden"); + return true; + } + if (v2.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können addiert werden"); + return true; + } + + scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(v1.asLong() + v2.asLong())); + return true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Div.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Div.java index 469c8b45..1b2a1f91 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Div.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Div.java @@ -1,4 +1,53 @@ package de.steamwar.bausystem.features.script.command.arithmetic; -public class Div { +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 Div implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§ediv §8<§7Variable§8> §8<§7Variable§8>", + "§ediv §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>", + "", + "Division zwischen den letzten beiden Variablen und schreibe es in die erste." + }; + } + + @Override + public String command() { + return "div"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + if (v1.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können dividiert werden"); + return true; + } + if (v2.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können dividiert werden"); + return true; + } + + scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(v1.asLong() / v2.asLong())); + return true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Mul.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Mul.java index 229381a9..038212bd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Mul.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Mul.java @@ -1,4 +1,53 @@ package de.steamwar.bausystem.features.script.command.arithmetic; -public class Mul { +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 Mul implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§emul §8<§7Variable§8> §8<§7Variable§8>", + "§emul §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>", + "", + "Multiplikation zwischen den letzten beiden Variablen und schreibe es in die erste." + }; + } + + @Override + public String command() { + return "mul"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + if (v1.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können multipliziert werden"); + return true; + } + if (v2.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können multipliziert werden"); + return true; + } + + scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(v1.asLong() * v2.asLong())); + return true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Sub.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Sub.java index f0c1ac63..afd5677c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Sub.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/arithmetic/Sub.java @@ -1,4 +1,53 @@ package de.steamwar.bausystem.features.script.command.arithmetic; -public class Sub { +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 Sub implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§esub §8<§7Variable§8> §8<§7Variable§8>", + "§esub §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>", + "", + "Subtraktion zwischen den letzten beiden Variablen und schreibe es in die erste." + }; + } + + @Override + public String command() { + return "sub"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + if (v1.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können subtrahiert werden"); + return true; + } + if (v2.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können subtrahiert werden"); + return true; + } + + scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(v1.asLong() - v2.asLong())); + return true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java index c6ef40ac..192604be 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/io/Input.java @@ -4,9 +4,12 @@ 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; import de.steamwar.inventory.SWAnvilInv; import org.bukkit.ChatColor; +@Linked(LinkageType.SCRIPT_COMMAND) public class Input implements SpecialCommand { @Override @@ -26,7 +29,7 @@ public class Input implements SpecialCommand { @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"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); return true; } StringBuilder st = new StringBuilder(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/And.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/And.java index 7e8f3d2b..55be7bc5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/And.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/And.java @@ -1,4 +1,59 @@ package de.steamwar.bausystem.features.script.command.logic; -public class And { +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 And implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§eand §8<§7Variable§8> §8<§7Variable§8>", + "§eand §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>", + "", + "Das logische Und zwischen den letzten beiden Variablen und schreibe es in die erste." + }; + } + + @Override + public String command() { + return "and"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + if (v1.getClass() != Value.BooleanValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können verglichen werden"); + return true; + } + if (v2.getClass() != Value.BooleanValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können verglichen werden"); + return true; + } + Value result; + if (v1.asBoolean() && v2.asBoolean()) { + result = new Value.BooleanValue(true); + } else { + result = new Value.BooleanValue(false); + } + + scriptExecutor.getLocalVariables().putValue(command[1], result); + return true; + } } 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..941a82bc 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 eine Variable sein"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + Value result; + if (v1.getClass() != v2.getClass()) { + result = new Value.BooleanValue(false); + } else if (v1.asString().equals(v2.asString())) { + result = new Value.BooleanValue(true); + } else { + result = new Value.BooleanValue(false); + } + + scriptExecutor.getLocalVariables().putValue(command[1], result); + return true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Greater.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Greater.java index bfae8d10..628b0a84 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Greater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Greater.java @@ -1,4 +1,59 @@ package de.steamwar.bausystem.features.script.command.logic; -public class Greater { +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 Greater implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§egreater §8<§7Variable§8> §8<§7Variable§8>", + "§egreater §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 "greater"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + if (v1.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können verglichen werden"); + return true; + } + if (v2.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können verglichen werden"); + return true; + } + Value result; + if (v1.asLong() > v2.asLong()) { + result = new Value.BooleanValue(true); + } else { + result = new Value.BooleanValue(false); + } + + scriptExecutor.getLocalVariables().putValue(command[1], result); + return true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Less.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Less.java index 78cc49d6..6052f313 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Less.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Less.java @@ -1,4 +1,59 @@ package de.steamwar.bausystem.features.script.command.logic; -public class Less { +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 Less implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§eless §8<§7Variable§8> §8<§7Variable§8>", + "§eless §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 "less"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + if (v1.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können verglichen werden"); + return true; + } + if (v2.getClass() != Value.LongValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können verglichen werden"); + return true; + } + Value result; + if (v1.asLong() < v2.asLong()) { + result = new Value.BooleanValue(true); + } else { + result = new Value.BooleanValue(false); + } + + scriptExecutor.getLocalVariables().putValue(command[1], result); + return true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Not.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Not.java index bd9c5d8d..9d3cb70c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Not.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Not.java @@ -1,4 +1,43 @@ package de.steamwar.bausystem.features.script.command.logic; -public class Not { +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 Not implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§enot §8<§7Variable§8>", + "§enot §8<§7Variable§8> §8<§7Variable§8>", + "", + "Das logische Nicht von der letzten Variable und schreibe es in die erste." + }; + } + + @Override + public String command() { + return "not"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + if (v1.getClass() != Value.BooleanValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können genichtet werden"); + return true; + } + scriptExecutor.getLocalVariables().putValue(command[1], new Value.BooleanValue(!v1.asBoolean())); + return true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Or.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Or.java index 1a8a7f74..5060632c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Or.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/logic/Or.java @@ -1,4 +1,59 @@ package de.steamwar.bausystem.features.script.command.logic; -public class Or { +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 Or implements SpecialCommand { + + @Override + public String[] description() { + return new String[]{ + "§eor §8<§7Variable§8> §8<§7Variable§8>", + "§eor §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>", + "", + "Das logische Oder zwischen den letzten beiden Variablen und schreibe es in die erste." + }; + } + + @Override + public String command() { + return "or"; + } + + @Override + public boolean execute(String[] command, ScriptExecutor scriptExecutor) { + if (command.length <= 1) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); + return true; + } + if (command.length <= 2) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein"); + return true; + } + + Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]); + Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]); + if (v1.getClass() != Value.BooleanValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können verglichen werden"); + return true; + } + if (v2.getClass() != Value.BooleanValue.class) { + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können verglichen werden"); + return true; + } + Value result; + if (v1.asBoolean() || v2.asBoolean()) { + result = new Value.BooleanValue(true); + } else { + result = new Value.BooleanValue(false); + } + + scriptExecutor.getLocalVariables().putValue(command[1], result); + return true; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/.gitkeep similarity index 100% rename from BauSystem_Main/src/de/steamwar/bausystem/features/testblock/.gitkeep rename to BauSystem_Main/src/de/steamwar/bausystem/features/script/command/string/.gitkeep diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java index f30dc4db..1497ae42 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Global.java @@ -13,7 +13,7 @@ public class Global implements SpecialCommand { @Override public String[] description() { return new String[]{ - "§eglobal §8<§7Name§8> §8[§7Value§8(§7s§8)§8]", + "§eglobal §8<§7Variable§8> §8[§7Value§8(§7s§8)§8]", "", "Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text." }; @@ -27,7 +27,7 @@ public class Global implements SpecialCommand { @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"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); return true; } if (command.length <= 2) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java index 65eddd8a..5c7ae176 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unglobal.java @@ -12,7 +12,7 @@ public class Unglobal implements SpecialCommand { @Override public String[] description() { return new String[]{ - "§eunglobal §8<§7Name§8>", + "§eunglobal §8<§7Variable§8>", "", "§7Lösche eine Globale variable." }; @@ -26,7 +26,7 @@ public class Unglobal implements SpecialCommand { @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"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); return true; } scriptExecutor.getGlobalVariables().removeValue(command[1]); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java index b0db54cd..9cac9000 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Unvar.java @@ -12,7 +12,7 @@ public class Unvar implements SpecialCommand { @Override public String[] description() { return new String[]{ - "§eunvar §8<§7Name§8>", + "§eunvar §8<§7Variable§8>", "", "§7Lösche eine Locale variable." }; @@ -26,7 +26,7 @@ public class Unvar implements SpecialCommand { @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"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); return true; } scriptExecutor.getLocalVariables().removeValue(command[1]); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java index 878cb9ec..108a1808 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java @@ -13,7 +13,7 @@ public class Var implements SpecialCommand { @Override public String[] description() { return new String[]{ - "§evar §8<§7Name§8> §8[§7Value§8(§7s§8)§8]", + "§evar §8<§7Variable§8> §8[§7Value§8(§7s§8)§8]", "", "Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text." }; @@ -27,7 +27,7 @@ public class Var implements SpecialCommand { @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"); + scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein"); return true; } if (command.length <= 2) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java index 8b0c94d0..a5bb62f8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/variables/Context.java @@ -27,4 +27,8 @@ public class Context { public Set allVariables() { return variables.keySet(); } + + public Set> entrySet() { + return variables.entrySet(); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java index 761f4e4a..1a50ce3f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/Depth.java @@ -33,6 +33,7 @@ import java.util.Set; public class Depth { + private int tntCount = 1; private Vector minVector = null; private Vector maxVector = null; @@ -62,7 +63,7 @@ public class Depth { dimensions.setZ(Math.abs(dimensions.getZ())); if (dimensions.getX() != 0 && dimensions.getY() != 0 && dimensions.getZ() != 0) { - RegionUtils.message(region, player -> DepthCounter.getMessage(player, dimensions.getBlockX(), dimensions.getBlockY(), dimensions.getBlockZ())); + RegionUtils.message(region, player -> DepthCounter.getMessage(player, dimensions.getBlockX() + 1, dimensions.getBlockY() + 1, dimensions.getBlockZ() + 1, tntCount)); } Set depthSet = DepthCounter.depthMap.get(region); @@ -74,11 +75,11 @@ public class Depth { DepthCounter.depthMap.remove(region); } } - }, 2, 2); + }, 1, 1); } public boolean update(List blocks) { - boolean expand = blocks.stream().anyMatch(block -> { + long overlappingBlocks = blocks.stream().filter(block -> { Vector vector = DepthCounter.blockVector(block.getLocation().toVector()); return vector.getX() >= minVector.getX() && vector.getY() >= minVector.getY() @@ -86,12 +87,13 @@ public class Depth { && vector.getX() <= maxVector.getX() && vector.getY() <= maxVector.getY() && vector.getZ() <= maxVector.getZ(); - }); - if (!expand) { + }).count(); + if (overlappingBlocks < 4) { return false; } lastUpdate = TPSUtils.currentTick.get(); blocks.forEach(this::internalUpdate); + tntCount++; return true; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java index 03cd8df0..4402bbca 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/depthcounter/DepthCounter.java @@ -97,7 +97,7 @@ public class DepthCounter { return values.stream().max(Integer::compare).orElse(0); } - public String getMessage(Player player, int x, int y, int z) { + public String getMessage(Player player, int x, int y, int z, int tntCount) { final boolean xActive = DepthCounter.isActive(player, CountMode.X); final boolean yActive = DepthCounter.isActive(player, CountMode.Y); final boolean zActive = DepthCounter.isActive(player, CountMode.Z); @@ -106,7 +106,7 @@ public class DepthCounter { return null; } - final StringBuilder result = new StringBuilder(BauSystem.PREFIX).append("Schadensdimensionen ").append(ColorConfig.OTHER).append("> ").append(ColorConfig.BASE); + final StringBuilder result = new StringBuilder(BauSystem.PREFIX).append("Schaden ").append(ColorConfig.OTHER).append("> ").append(ColorConfig.BASE); final Set dimensions = new HashSet<>(); if (xActive) { @@ -145,6 +145,7 @@ public class DepthCounter { } } + result.append(ColorConfig.BASE).append("TNT").append(ColorConfig.OTHER).append(": ").append(ColorConfig.HIGHLIGHT).append(tntCount); return result.toString(); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/generator/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/generator/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java index 22ba7226..56ceab69 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/RamUsage.java @@ -44,9 +44,9 @@ public class RamUsage implements Listener { long presumableFreeMemory = Runtime.getRuntime().maxMemory() - allocatedMemory; double percentageFree = presumableFreeMemory / (double) Runtime.getRuntime().maxMemory(); bossBar.setProgress(1 - percentageFree); - if (mode && percentageFree > 0.7) { + if (mode && percentageFree > 0.6) { mode = false; - } else if (!mode && percentageFree < 0.5) { + } else if (!mode && percentageFree < 0.4) { mode = true; } if (mode) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 8f086715..b169fc43 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -140,7 +140,7 @@ public class Region { this.maxPointTestblock = this.minPointTestblock.add(prototype.getTestblock().getSizeX() - 1, prototype.getTestblock().getSizeY() - 1, prototype.getTestblock().getSizeZ() - 1); this.minPointTestblockExtension = this.minPointTestblock.substract(prototype.getTestblock().getExtensionNegativeX(), prototype.getTestblock().getExtensionNegativeY(), prototype.getTestblock().getExtensionNegativeZ()); - this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX() - 1, prototype.getTestblock().getExtensionPositiveY() - 1, prototype.getTestblock().getExtensionPositiveZ() - 1); + this.maxPointTestblockExtension = this.maxPointTestblock.add(prototype.getTestblock().getExtensionPositiveX(), prototype.getTestblock().getExtensionPositiveY(), prototype.getTestblock().getExtensionPositiveZ()); } if (prototype.getBuild() != null) { @@ -148,7 +148,7 @@ public class Region { this.maxPointBuild = this.minPointBuild.add(prototype.getBuild().getSizeX() - 1, prototype.getBuild().getSizeY() - 1, prototype.getBuild().getSizeZ() - 1); this.minPointBuildExtension = this.minPointBuild.substract(prototype.getBuild().getExtensionNegativeX(), prototype.getBuild().getExtensionNegativeY(), prototype.getBuild().getExtensionNegativeZ()); - this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX() - 1, prototype.getBuild().getExtensionPositiveY() - 1, prototype.getBuild().getExtensionPositiveZ() - 1); + this.maxPointBuildExtension = this.maxPointBuild.add(prototype.getBuild().getExtensionPositiveX(), prototype.getBuild().getExtensionPositiveY(), prototype.getBuild().getExtensionPositiveZ()); } if (prototype.getFloorOffset() != 0) { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java index 6e6ba124..c56dff91 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -27,13 +27,13 @@ import de.steamwar.bausystem.shared.EnumDisplay; import lombok.Getter; @Getter -public enum Flag { +public enum Flag implements EnumDisplay { - COLOR(ColorMode.class, ColorMode.YELLOW), - TNT(TNTMode.class, TNTMode.ONLY_TB), - FIRE(FireMode.class, FireMode.ALLOW), - FREEZE(FreezeMode.class, FreezeMode.INACTIVE), - PROTECT(ProtectMode.class, ProtectMode.INACTIVE); + COLOR("Color", ColorMode.class, ColorMode.YELLOW), + TNT("TNT", TNTMode.class, TNTMode.ONLY_TB), + FIRE("Fire", FireMode.class, FireMode.ALLOW), + FREEZE("Freeze", FreezeMode.class, FreezeMode.INACTIVE), + PROTECT("Protect", ProtectMode.class, ProtectMode.INACTIVE); @Getter private static final Set flags; @@ -42,11 +42,13 @@ public enum Flag { flags = EnumSet.allOf(Flag.class); } + private final String chatValue; private final Class> valueType; private final Flag.Value defaultValue; private final Value[] values; - & Value> Flag(final Class> valueType, final Flag.Value defaultValue) { + & Value> Flag(String chatValue, final Class> valueType, final Flag.Value defaultValue) { + this.chatValue = chatValue; this.valueType = valueType; this.defaultValue = defaultValue; this.values = defaultValue.getValues(); @@ -56,11 +58,18 @@ public enum Flag { return this.defaultValue.getValueOf(name); } + + @Override public String toString() { return this.name().toLowerCase(); } + @Override + public String getChatValue() { + return chatValue; + } + public interface Value & Value> extends EnumDisplay { T getValue();