From d385fb6d257ee3b5798b0268fa8f22c4c12c637c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Dec 2021 17:36:46 +0100 Subject: [PATCH 01/36] Update TraceCommand Signed-off-by: yoyosource --- .../features/tracer/TraceCommand.java | 60 ++++--------------- 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 74a957db..92dc5e91 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -114,8 +114,8 @@ public class TraceCommand extends SWCommand { listCommand(p, 0); } - @Register({"record", "list"}) - @Register({"list"}) + @Register(value = {"record", "list"}, noTabComplete = true) + @Register(value = {"list"}, noTabComplete = true) public void listCommand(Player player, int page) { if (!permissionCheck(player)) return; ListChatView.chatView(player, StoredRecords.getRecords(), page, record -> { @@ -139,19 +139,19 @@ public class TraceCommand extends SWCommand { }); } - @Register({"record", "delete"}) + @Register(value = {"record", "delete"}, noTabComplete = true) public void recordDelete(Player p, int id) { if (!permissionCheck(p)) return; StoredRecords.remove(id); BauSystem.MESSAGE.send("TRACE_RECORD_DELETE", p); } - @Register("record") + @Register(value = "record", noTabComplete = true) public void recordList(Player p, int record) { recordList(p, record, 0); } - @Register("record") + @Register(value = "record", noTabComplete = true) public void recordList(Player player, int recordID, int page) { if (!permissionCheck(player)) return; Record traceRecord = StoredRecords.get(recordID); @@ -180,7 +180,7 @@ public class TraceCommand extends SWCommand { }); } - @Register({"record", "tnt", "delete"}) + @Register(value = {"record", "tnt", "delete"}, noTabComplete = true) public void deleteRecordTNT(Player player, int recordID, int tntID) { if (!permissionCheck(player)) return; Record record = StoredRecords.get(recordID); @@ -192,13 +192,13 @@ public class TraceCommand extends SWCommand { BauSystem.MESSAGE.send("TRACE_TNT_DELETE", player); } - @Register("record") - public void recordTNTPositions(Player player, int recordID, @Mapper("tnt") String tnt, int tntID) { + @Register(value = "record", noTabComplete = true) + public void recordTNTPositions(Player player, int recordID, @StaticValue("tnt") String tnt, int tntID) { recordTNTPositions(player, recordID, tnt, tntID, 0); } - @Register("record") - public void recordTNTPositions(Player player, int recordID, @Mapper("tnt") String tnt, int tntID, int page) { + @Register(value = "record", noTabComplete = true) + public void recordTNTPositions(Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, int page) { if (!permissionCheck(player)) return; Record record = StoredRecords.get(recordID); if (record == null) { @@ -225,8 +225,8 @@ public class TraceCommand extends SWCommand { }); } - @Register("record") - public void recordTNTPositions(Player player, int recordID, @Mapper("tnt") String tnt, int tntID, @Mapper("fuse") String fuse, int fuseTicks) { + @Register(value = "record", noTabComplete = true) + public void recordTNTPositions(Player player, int recordID, @StaticValue("tnt") String tnt, int tntID, @StaticValue("fuse") String fuse, int fuseTicks) { if (!permissionCheck(player)) return; Record record = StoredRecords.get(recordID); if (record == null) { @@ -361,40 +361,4 @@ public class TraceCommand extends SWCommand { } return true; } - - @Mapper(value = "tnt", local = true) - public TypeMapper tntTypeMapper() { - return new TypeMapper() { - @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { - if (s.equals("tnt")) { - return "tnt"; - } - return null; - } - - @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return Collections.singletonList("tnt"); - } - }; - } - - @Mapper(value = "fuse", local = true) - public TypeMapper fuseTypeMapper() { - return new TypeMapper() { - @Override - public String map(CommandSender commandSender, String[] previousArguments, String s) { - if (s.equals("fuse")) { - return "fuse"; - } - return null; - } - - @Override - public List tabCompletes(CommandSender commandSender, String[] strings, String s) { - return Collections.singletonList("fuse"); - } - }; - } } From 7a8a690e620d334d7399394d18f4ff68bf748456 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Dec 2021 19:47:22 +0100 Subject: [PATCH 02/36] Update TraceCommand Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tracer/TraceCommand.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 92dc5e91..40732d54 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -40,10 +40,12 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Linked(LinkageType.COMMAND) public class TraceCommand extends SWCommand { From f5cb296cf08a9dfa4cfc9d9128036f5c5494b2c6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 8 Dec 2021 20:08:31 +0100 Subject: [PATCH 03/36] Force rebuild Signed-off-by: yoyosource --- .../steamwar/bausystem/features/autostart/AutostartListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index ce085b38..7b16da9d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -110,5 +110,4 @@ public class AutostartListener implements Listener { RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT3"); }); } - } From 54382c79685c67f272cc66c442d316196cf3ad15 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Dec 2021 21:53:15 +0100 Subject: [PATCH 04/36] Update TNTSimulator Signed-off-by: yoyosource --- .../features/observer/ObserverTracer.java | 2 ++ .../features/simulator/TNTSimulator.java | 35 ++----------------- 2 files changed, 5 insertions(+), 32 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java index fe9f9b44..a5b0bb4c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/observer/ObserverTracer.java @@ -117,6 +117,8 @@ public class ObserverTracer { } private void calculateObserver(Block block) { + // TODO: Implement single Repeater, single Redstone, DetectorRail, PoweredRail, Diagonal Piston + Observer observer = (Observer) block.getBlockData(); for (BlockFace blockFace : ALLOWED) { Location location = block.getLocation().add(blockFace.getModX(), blockFace.getModY(), blockFace.getModZ()); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index 78f38475..f4c162a2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -26,12 +26,10 @@ import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.config.ColorConfig; import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode; import de.steamwar.bausystem.worlddata.SimulatorData; -import de.steamwar.bausystem.worlddata.WorldData; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; -import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; @@ -211,7 +209,6 @@ public class TNTSimulator { List lore = new ArrayList<>(); lore.add("§7TNT-Anzahl§8: §e" + spawn.count); lore.add("§7Tick§8: §e" + spawn.tickOffset); - lore.add("§7Fuse-Tick§8: §e" + spawn.fuseTicks); lore.add(""); lore.add("§7x§8: §e" + spawn.position.getX()); lore.add("§7y§8: §e" + spawn.position.getY()); @@ -313,7 +310,6 @@ public class TNTSimulator { private boolean printed = false; private final Vector position; - private int fuseTicks = 80; private int count = 1; private int tickOffset = 0; private boolean xVelocity = false; @@ -331,7 +327,6 @@ public class TNTSimulator { private TNTSpawn(YAPIONObject yapionObject) { this.position = new Vector(yapionObject.getPlainValueOrDefault("positionX", 0.0), yapionObject.getPlainValueOrDefault("positionY", 0.0), yapionObject.getPlainValueOrDefault("positionZ", 0.0)); this.entity = SimulatorEntityShowMode.createEntity(player, position, false); - this.fuseTicks = yapionObject.getPlainValue("fuseTicks"); this.count = yapionObject.getPlainValue("count"); this.tickOffset = yapionObject.getPlainValue("tickOffset"); this.xVelocity = yapionObject.getPlainValue("xVelocity"); @@ -345,7 +340,6 @@ public class TNTSimulator { yapionObject.add("positionX", position.getX()); yapionObject.add("positionY", position.getY()); yapionObject.add("positionZ", position.getZ()); - yapionObject.add("fuseTicks", fuseTicks); yapionObject.add("count", count); yapionObject.add("tickOffset", tickOffset); yapionObject.add("xVelocity", xVelocity); @@ -371,19 +365,12 @@ public class TNTSimulator { private void spawn() { WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { - tntPrimed.setFuseTicks(fuseTicks); if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); }); } - private void setFuseTicks(int fuseTicks) { - if (fuseTicks < 0) fuseTicks = 0; - if (fuseTicks > 160) fuseTicks = 160; - this.fuseTicks = fuseTicks; - } - private void setCount(int count) { if (count < 1) count = 1; if (count > 400) count = 400; @@ -443,22 +430,6 @@ public class TNTSimulator { editTNT(); })); - // Change FuseTicks - swInventory.setItem(3, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { - setFuseTicks(fuseTicks + 1); - editTNT(); - })); - SWItem fuseTickItem = new SWItem(Material.CLOCK, "§7Lebensdauer §8- §e" + fuseTicks, LORE, false, clickType -> changeCount(player, "Fuse-Ticks", fuseTicks, tick -> { - setFuseTicks(tick); - editTNT(); - }, this::editTNT)); - fuseTickItem.getItemStack().setAmount(Math.max(fuseTicks, 1)); - swInventory.setItem(12, fuseTickItem); - swInventory.setItem(21, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { - setFuseTicks(fuseTicks - 1); - editTNT(); - })); - // Velocity Settings swInventory.setItem(38, Material.TNT, "TNT", clickType -> { }); @@ -525,7 +496,7 @@ public class TNTSimulator { })); // Repeater before Comparator - swInventory.setItem(41, new SWItem(comparator ? SWItem.getMaterial("REDSTONE_COMPARATOR_OFF") : SWItem.getMaterial("DIODE"), "§7Gezündet durch §8- §e" + (comparator ? "Comparator" : "Repeater"), clickType -> { + swInventory.setItem(42, new SWItem(comparator ? SWItem.getMaterial("REDSTONE_COMPARATOR_OFF") : SWItem.getMaterial("DIODE"), "§7Gezündet durch §8- §e" + (comparator ? "Comparator" : "Repeater"), clickType -> { comparator = !comparator; editTNT(); })); @@ -534,7 +505,7 @@ public class TNTSimulator { spawns.add(new TNTSpawn(position, entity)); })); - swInventory.setItem(42, new SWItem(Material.ARROW, "§eZurück", clickType -> { + swInventory.setItem(53, new SWItem(Material.ARROW, "§eZurück", clickType -> { showGUI(); })); @@ -544,7 +515,7 @@ public class TNTSimulator { })); // Delete tnt - swInventory.setItem(43, new SWItem(Material.BARRIER, "§cEntfernen", clickType -> { + swInventory.setItem(44, new SWItem(Material.BARRIER, "§cEntfernen", clickType -> { hide(); spawns.remove(this); player.closeInventory(); From 2d3dc10e230c240a821eda07a72522944f907965 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Dec 2021 22:04:10 +0100 Subject: [PATCH 05/36] Update TimeCommand Signed-off-by: yoyosource --- .../bausystem/features/other/TimeCommand.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java index 27995703..66e916b5 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/other/TimeCommand.java @@ -40,12 +40,20 @@ public class TimeCommand extends SWCommand { addDefaultHelpMessage("OTHER_TIME_HELP"); } + // TODO: Add set as OptionalValue @Register public void genericCommand(@Guard Player p, Time time) { Bukkit.getWorlds().get(0).setTime(time.getValue()); BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p); } + @Register + public void genericCommand(@Guard Player p, @StaticValue(value = "set") String set, Time time) { + Bukkit.getWorlds().get(0).setTime(time.getValue()); + BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p); + } + + // TODO: Add set as OptionalValue @Register public void genericCommand(@Guard Player p, int time) { if (time < 0 || time > 24000) { @@ -56,6 +64,16 @@ public class TimeCommand extends SWCommand { BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p); } + @Register + public void genericCommand(@Guard Player p, @StaticValue(value = "set") String set, int time) { + if (time < 0 || time > 24000) { + BauSystem.MESSAGE.send("OTHER_TIME_INVALID", p); + return; + } + Bukkit.getWorlds().get(0).setTime(time); + BauSystem.MESSAGE.send("OTHER_TIME_RESULT", p); + } + @ClassMapper(value = int.class, local = true) public TypeMapper intTypeMapper() { return SWCommandUtils.createMapper(s -> { From c8ad93a00ff4e1fcf30e4e7fda41cb6a78ce0157 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 9 Dec 2021 23:28:51 +0100 Subject: [PATCH 06/36] Add SimulatorCommand.saveCommand and other Signed-off-by: yoyosource --- .../features/simulator/SimulatorCommand.java | 64 +++++++++++++++++++ .../features/simulator/TNTSimulator.java | 9 +-- .../bausystem/worlddata/SimulatorData.java | 37 +++++++++-- 3 files changed, 98 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java index c718d6c8..cdcaec09 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/SimulatorCommand.java @@ -26,9 +26,14 @@ import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.config.ColorConfig; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.worlddata.SimulatorData; import de.steamwar.command.SWCommand; +import de.steamwar.command.TypeMapper; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.List; + @Linked(LinkageType.COMMAND) public class SimulatorCommand extends SWCommand { @@ -42,6 +47,10 @@ public class SimulatorCommand extends SWCommand { p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator start" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Startet die Simulation"); p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator gui" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Öffnet die GUI"); p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator delete" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Löscht alle TNT"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator save " + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Speichert den Simulator"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator load " + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Lädt den Simulator"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator list" + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Listet alle gespeicherten Simulator"); + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator remove " + ColorConfig.OTHER + " - " + ColorConfig.BASE + "Löscht den Simulator"); } @Register @@ -66,6 +75,44 @@ public class SimulatorCommand extends SWCommand { public void deleteCommand(Player p) { if (cannotUse(p)) return; TNTSimulator.get(p).delete(); + p.sendMessage(ColorConfig.BASE + "Alle TNT wurden gelöscht"); + } + + @Register({"save"}) + public void saveCommand(Player p, String name) { + if (cannotUse(p)) return; + TNTSimulator.get(p).save(); + SimulatorData.saveSimulator(p, name); + p.sendMessage(ColorConfig.BASE + "Simulator " + ColorConfig.HIGHLIGHT + name + ColorConfig.BASE + " wurde gespeichert"); + } + + @Register({"load"}) + public void loadCommand(Player p, @Mapper("SavedSimulators") String name) { + if (cannotUse(p)) return; + TNTSimulator.get(p).delete(); + SimulatorData.loadSimulator(p, name); + p.sendMessage(ColorConfig.BASE + "Simulator " + ColorConfig.HIGHLIGHT + name + ColorConfig.BASE + " wurde geladen"); + } + + @Register({"remove"}) + public void removeCommand(Player p, @Mapper("SavedSimulators") String name) { + if (cannotUse(p)) return; + SimulatorData.removeSimulator(p, name); + p.sendMessage(ColorConfig.BASE + "Simulator " + ColorConfig.HIGHLIGHT + name + ColorConfig.BASE + " wurde gelöscht"); + } + + @Register({"list"}) + public void listCommand(Player p) { + if (cannotUse(p)) return; + List sims = SimulatorData.listSimulator(p); + if (sims.isEmpty()) { + p.sendMessage(ColorConfig.BASE + "Keine gespeicherten Simulatoren"); + return; + } + p.sendMessage(ColorConfig.BASE + "Gespeicherte Simulatoren:"); + for (String s : sims) { + p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "simulator load " + s); + } } private boolean cannotUse(Player player) { @@ -76,4 +123,21 @@ public class SimulatorCommand extends SWCommand { return false; } + @Mapper(value = "SavedSimulators", local = true) + public TypeMapper simulatorListTypeMapper() { + return new TypeMapper() { + @Override + public String map(CommandSender commandSender, String[] previousArguments, String s) { + if (SimulatorData.listSimulator(((Player) commandSender)).contains(s)) { + return s; + } + return null; + } + + @Override + public List tabCompletes(CommandSender commandSender, String[] strings, String s) { + return SimulatorData.listSimulator(((Player) commandSender)); + } + }; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index f4c162a2..eb8d028c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -80,22 +80,19 @@ public class TNTSimulator { simulator.spawns.forEach(tntSpawn -> { yapionArray.add(tntSpawn.output()); }); - if (yapionArray.isEmpty()) { - SimulatorData.removeSimulator(player); - } else { - SimulatorData.saveSimulator(player, new YAPIONObject().add("", yapionArray)); - } + SimulatorData.saveSimulator(player, yapionArray); simulator.hide(); } public void saveAndDelete() { save(); TNT_SIMULATOR_MAP.remove(player); + SimulatorData.removeSimulator(player, ""); } public void delete() { TNTSimulator simulator = TNT_SIMULATOR_MAP.remove(player); - SimulatorData.removeSimulator(player); + SimulatorData.removeSimulator(player, ""); simulator.hide(); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/worlddata/SimulatorData.java b/BauSystem_Main/src/de/steamwar/bausystem/worlddata/SimulatorData.java index dc2695e3..e9ef8f5b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/worlddata/SimulatorData.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/worlddata/SimulatorData.java @@ -25,10 +25,12 @@ import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import yapion.hierarchy.output.FileOutput; +import yapion.hierarchy.types.YAPIONArray; import yapion.hierarchy.types.YAPIONObject; import yapion.parser.YAPIONParser; import java.io.File; +import java.util.List; @UtilityClass public class SimulatorData { @@ -49,7 +51,7 @@ public class SimulatorData { } @SneakyThrows - public void saveSimulator(Player player, YAPIONObject yapionObject) { + private void internalSaveSimulator(Player player, YAPIONObject yapionObject) { File file = getFile(player); yapionObject.toYAPION(new FileOutput(file)).close(); } @@ -60,11 +62,34 @@ public class SimulatorData { yapionObject.toYAPION(new FileOutput(file)).close(); } - public void removeSimulator(Player player) { - File file = getFile(player); - if (file.exists()) { - file.delete(); - } + public List listSimulator(Player player) { + List strings = getSimulator(player).getKeys(); + strings.remove(""); + return strings; + } + + public void saveSimulator(Player player, String name) { + YAPIONObject yapionObject = getSimulator(player); + yapionObject.put(name, yapionObject.getArray("").copy()); + internalSaveSimulator(player, yapionObject); + } + + public void saveSimulator(Player player, YAPIONArray simulator) { + YAPIONObject yapionObject = getSimulator(player); + yapionObject.put("", simulator); + internalSaveSimulator(player, yapionObject); + } + + public void loadSimulator(Player player, String name) { + YAPIONObject yapionObject = getSimulator(player); + yapionObject.put("", yapionObject.getArray(name).copy()); + internalSaveSimulator(player, yapionObject); + } + + public void removeSimulator(Player player, String name) { + YAPIONObject yapionObject = getSimulator(player); + yapionObject.remove(name); + internalSaveSimulator(player, yapionObject); } private File getFile(Player player) { From 45a9686d7173d17ddffddb1724b3d7ac87ea6986 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 10:58:20 +0100 Subject: [PATCH 07/36] Update PowerableActivation Signed-off-by: yoyosource --- .../slaves/panzern/algorithms/PowerableActivation.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/PowerableActivation.java b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/PowerableActivation.java index 121e97c4..1fa366b1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/PowerableActivation.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/slaves/panzern/algorithms/PowerableActivation.java @@ -52,7 +52,15 @@ public class PowerableActivation implements PanzernAlgorithm { if (block.getType() == Material.TNT) { powerable++; } - if (blockFace == BlockFace.DOWN || blockFace == BlockFace.UP) { + if (blockFace == BlockFace.DOWN) { + for (BlockFace otherBlockFace : HORIZONTAL_FACES) { + Block otherBlock = block.getRelative(otherBlockFace); + if (otherBlock.getType() == Material.PISTON) { + powered++; + } + } + } + if (blockFace == BlockFace.UP) { continue; } switch (block.getType()) { From d1b3fa2238e650e28d7b8353c57175bdf6dbd26a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 11:07:37 +0100 Subject: [PATCH 08/36] Fix LinkageUtils Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/linkage/LinkageUtils.java | 2 -- BauSystem_Main/src/de/steamwar/bausystem/linkage/Linked.java | 1 - 2 files changed, 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java index 429d96cc..85f41d5a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java @@ -41,12 +41,10 @@ public class LinkageUtils { public void link() { internalLinkOrUnlink(false, Linked.class); - internalLinkOrUnlink(false, Linked.Linkages.class); internalLinkFields(); } public void unlink() { - internalLinkOrUnlink(true, Linked.Linkages.class); internalLinkOrUnlink(true, Linked.class); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/Linked.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/Linked.java index ff447ed0..2096d1ac 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/Linked.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/Linked.java @@ -30,7 +30,6 @@ import java.lang.annotation.*; public @interface Linked { LinkageType value(); - @IndexAnnotated @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) @interface Linkages { From 6172270a8d96285af9e6ff830739634d24afe3cf Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 11:08:39 +0100 Subject: [PATCH 09/36] Remove Hotfix for Simulator as it is no longer needed Signed-off-by: yoyosource --- .../features/simulator/TNTSimulatorDisable.java | 16 ---------------- .../features/simulator/TNTSimulatorListener.java | 11 ++++++++++- 2 files changed, 10 insertions(+), 17 deletions(-) delete mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorDisable.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorDisable.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorDisable.java deleted file mode 100644 index 4c7e3e24..00000000 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorDisable.java +++ /dev/null @@ -1,16 +0,0 @@ -package de.steamwar.bausystem.features.simulator; - -import de.steamwar.bausystem.linkage.Disable; -import de.steamwar.bausystem.linkage.LinkageType; -import de.steamwar.bausystem.linkage.Linked; - -@Linked(LinkageType.DISABLE_LINK) -public class TNTSimulatorDisable implements Disable { - - @Override - public void disable() { - for (TNTSimulator simulator : TNTSimulator.TNT_SIMULATOR_MAP.values()) { - simulator.save(); - } - } -} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java index f2743fb8..ba3b3763 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -23,6 +23,7 @@ package de.steamwar.bausystem.features.simulator; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.linkage.Disable; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import org.bukkit.FluidCollisionMode; @@ -47,7 +48,8 @@ import static de.steamwar.bausystem.features.simulator.TNTSimulator.WAND; import static de.steamwar.bausystem.features.simulator.TNTSimulator.get; @Linked(LinkageType.LISTENER) -public class TNTSimulatorListener implements Listener { +@Linked(LinkageType.DISABLE_LINK) +public class TNTSimulatorListener implements Listener, Disable { private boolean permissionCheck(Player player) { if (!Permission.hasPermission(player, Permission.WORLD)) { @@ -142,4 +144,11 @@ public class TNTSimulatorListener implements Listener { public void onPlayerQuit(PlayerQuitEvent event) { get(event.getPlayer()).saveAndDelete(); } + + @Override + public void disable() { + for (TNTSimulator simulator : TNTSimulator.TNT_SIMULATOR_MAP.values()) { + simulator.save(); + } + } } From 1c47d8960830e598ea783230d6e3638af9e3776a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 11:36:15 +0100 Subject: [PATCH 10/36] Add SmartPlaceBehaviour Extract behaviours from SmartPlaceListener Signed-off-by: yoyosource --- .../smartplace/SmartPlaceBehaviour.java | 45 ++++++++++ .../smartplace/SmartPlaceListener.java | 88 ++++++------------- .../behaviour/BlockPlaceBehaviour.java | 60 +++++++++++++ .../behaviour/BlockRotatingBehaviour.java | 81 +++++++++++++++++ .../behaviour/ReverseRepeaterBehaviour.java | 55 ++++++++++++ .../bausystem/linkage/LinkageType.java | 11 ++- 6 files changed, 276 insertions(+), 64 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceBehaviour.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockRotatingBehaviour.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/ReverseRepeaterBehaviour.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceBehaviour.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceBehaviour.java new file mode 100644 index 00000000..19ca8d0d --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceBehaviour.java @@ -0,0 +1,45 @@ +/* + * 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.smartplace; + +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public interface SmartPlaceBehaviour { + + enum SmartPlaceResult { + APPLIED, + IGNORED + } + + enum SmartPlaceType { + PLACE, + INTERACT_DIRECT, // Before checking if block is interacteable + INTERACT_INDIRECT, // After checking if block is interacteable + } + + SmartPlaceType getType(); + default SmartPlaceResult place(BlockPlaceEvent event) { + return SmartPlaceResult.IGNORED; + } + default SmartPlaceResult interact(PlayerInteractEvent event) { + return SmartPlaceResult.IGNORED; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java index 74adbee9..b63abbb0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/SmartPlaceListener.java @@ -23,41 +23,39 @@ import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import org.bukkit.GameMode; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Directional; import org.bukkit.block.data.Rotatable; -import org.bukkit.block.data.type.Repeater; -import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.InventoryHolder; + +import java.util.ArrayList; +import java.util.List; @Linked(LinkageType.LISTENER) public class SmartPlaceListener implements Listener { + private static List smartPlaceBehaviours = new ArrayList<>(); + + public static void add(SmartPlaceBehaviour smartPlaceBehaviour) { + smartPlaceBehaviours.add(smartPlaceBehaviour); + } + @EventHandler public void onBlockPlace(BlockPlaceEvent event) { if (event.getPlayer().isSneaking() && Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) { - Block block = event.getBlockPlaced(); - BlockData blockData = block.getBlockData(); - if (blockData instanceof Directional) { - Directional directional = (Directional) blockData; - BlockFace blockFace = directional.getFacing().getOppositeFace(); - if (directional.getFaces().contains(blockFace)) { - directional.setFacing(blockFace); + SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED; + for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) { + if (smartPlaceBehaviour.getType() == SmartPlaceBehaviour.SmartPlaceType.PLACE) { + smartPlaceBehaviour.place(event); + } + if (smartPlaceResult == SmartPlaceBehaviour.SmartPlaceResult.APPLIED) { + break; } - } else if (blockData instanceof Rotatable) { - Rotatable rotatable = (Rotatable) blockData; - rotatable.setRotation(rotatable.getRotation()); } - block.setBlockData(blockData); } } @@ -67,20 +65,14 @@ public class SmartPlaceListener implements Listener { if (event.getPlayer().getGameMode() == GameMode.SPECTATOR) return; if (!Config.getInstance().get(event.getPlayer()).getPlainValueOrDefault("smartPlace", false)) return; - // Reverse repeater - if (event.getPlayer().isSneaking()) { - if (event.getClickedBlock().getType() == Material.REPEATER) { - if (event.getItem() != null && event.getMaterial() != Material.REPEATER) { - return; - } - Repeater repeater = (Repeater) event.getClickedBlock().getBlockData(); - int i = repeater.getDelay() - 1; - if (i <= 0) i += 4; - repeater.setDelay(i); - event.getClickedBlock().setBlockData(repeater); - event.setCancelled(true); + for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) { + SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED; + if (smartPlaceBehaviour.getType() == SmartPlaceBehaviour.SmartPlaceType.INTERACT_DIRECT) { + smartPlaceResult = smartPlaceBehaviour.interact(event); + } + if (smartPlaceResult == SmartPlaceBehaviour.SmartPlaceResult.APPLIED) { + return; } - return; } if (!event.getClickedBlock().getType().isInteractable()) return; @@ -95,38 +87,14 @@ public class SmartPlaceListener implements Listener { return; } - if (event.getClickedBlock().getType() == event.getMaterial() || event.getMaterial() == Material.HOPPER) { - if (!(event.getClickedBlock().getState() instanceof InventoryHolder)) { - return; + for (SmartPlaceBehaviour smartPlaceBehaviour : smartPlaceBehaviours) { + SmartPlaceBehaviour.SmartPlaceResult smartPlaceResult = SmartPlaceBehaviour.SmartPlaceResult.IGNORED; + if (smartPlaceBehaviour.getType() == SmartPlaceBehaviour.SmartPlaceType.INTERACT_INDIRECT) { + smartPlaceResult = smartPlaceBehaviour.interact(event); } - } else { - BlockData blockData = event.getMaterial().createBlockData(); - if (blockData instanceof Directional) { - return; - } - if (blockData instanceof Rotatable) { + if (smartPlaceResult == SmartPlaceBehaviour.SmartPlaceResult.APPLIED) { return; } } - - // TODO: Fix block setting - event.setUseInteractedBlock(Event.Result.DENY); - World world = event.getPlayer().getWorld(); - Block block = world.getBlockAt(event.getClickedBlock().getX() + event.getBlockFace().getModX(), event.getClickedBlock().getY() + event.getBlockFace().getModY(), event.getClickedBlock().getZ() + event.getBlockFace().getModZ()); - block.setType(event.getMaterial()); - BlockData blockData = event.getItem().getType().createBlockData(); - BlockFace blockFace = event.getBlockFace(); - if (block.getType() == Material.HOPPER || block.getType() == Material.OBSERVER) { - blockFace = blockFace.getOppositeFace(); - } - if (blockData instanceof Directional) { - Directional directional = (Directional) blockData; - if (directional.getFaces().contains(blockFace)) { - directional.setFacing(blockFace); - } - } else if (blockData instanceof Rotatable) { - ((Rotatable) blockData).setRotation(blockFace); - } - block.setBlockData(blockData); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java new file mode 100644 index 00000000..8b7ee259 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java @@ -0,0 +1,60 @@ +/* + * 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.smartplace.behaviour; + +import de.steamwar.bausystem.features.smartplace.SmartPlaceBehaviour; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Directional; +import org.bukkit.block.data.Rotatable; +import org.bukkit.event.block.BlockPlaceEvent; + +@Linked(LinkageType.SMART_PLACE) +public class BlockPlaceBehaviour implements SmartPlaceBehaviour { + + @Override + public SmartPlaceType getType() { + return SmartPlaceType.PLACE; + } + + @Override + public SmartPlaceResult place(BlockPlaceEvent event) { + SmartPlaceResult smartPlaceResult = SmartPlaceResult.IGNORED; + Block block = event.getBlockPlaced(); + BlockData blockData = block.getBlockData(); + if (blockData instanceof Directional) { + Directional directional = (Directional) blockData; + BlockFace blockFace = directional.getFacing().getOppositeFace(); + if (directional.getFaces().contains(blockFace)) { + directional.setFacing(blockFace); + } + smartPlaceResult = SmartPlaceResult.APPLIED; + } else if (blockData instanceof Rotatable) { + Rotatable rotatable = (Rotatable) blockData; + rotatable.setRotation(rotatable.getRotation()); + smartPlaceResult = SmartPlaceResult.APPLIED; + } + block.setBlockData(blockData); + return smartPlaceResult; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockRotatingBehaviour.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockRotatingBehaviour.java new file mode 100644 index 00000000..29071148 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockRotatingBehaviour.java @@ -0,0 +1,81 @@ +/* + * 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.smartplace.behaviour; + +import de.steamwar.bausystem.features.smartplace.SmartPlaceBehaviour; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Directional; +import org.bukkit.block.data.Rotatable; +import org.bukkit.event.Event; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.InventoryHolder; + +@Linked(LinkageType.SMART_PLACE) +public class BlockRotatingBehaviour implements SmartPlaceBehaviour { + + @Override + public SmartPlaceType getType() { + return SmartPlaceType.INTERACT_INDIRECT; + } + + @Override + public SmartPlaceResult interact(PlayerInteractEvent event) { + if (event.getClickedBlock().getType() == event.getMaterial() || event.getMaterial() == Material.HOPPER) { + if (!(event.getClickedBlock().getState() instanceof InventoryHolder)) { + return SmartPlaceResult.IGNORED; + } + } else { + BlockData blockData = event.getMaterial().createBlockData(); + if (blockData instanceof Directional) { + return SmartPlaceResult.IGNORED; + } + if (blockData instanceof Rotatable) { + return SmartPlaceResult.IGNORED; + } + } + + // TODO: Fix block setting + event.setUseInteractedBlock(Event.Result.DENY); + World world = event.getPlayer().getWorld(); + Block block = world.getBlockAt(event.getClickedBlock().getX() + event.getBlockFace().getModX(), event.getClickedBlock().getY() + event.getBlockFace().getModY(), event.getClickedBlock().getZ() + event.getBlockFace().getModZ()); + block.setType(event.getMaterial()); + BlockData blockData = event.getItem().getType().createBlockData(); + BlockFace blockFace = event.getBlockFace(); + if (block.getType() == Material.HOPPER || block.getType() == Material.OBSERVER) { + blockFace = blockFace.getOppositeFace(); + } + if (blockData instanceof Directional) { + Directional directional = (Directional) blockData; + if (directional.getFaces().contains(blockFace)) { + directional.setFacing(blockFace); + } + } else if (blockData instanceof Rotatable) { + ((Rotatable) blockData).setRotation(blockFace); + } + block.setBlockData(blockData); + return SmartPlaceResult.APPLIED; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/ReverseRepeaterBehaviour.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/ReverseRepeaterBehaviour.java new file mode 100644 index 00000000..2c4a071a --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/ReverseRepeaterBehaviour.java @@ -0,0 +1,55 @@ +/* + * 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.smartplace.behaviour; + +import de.steamwar.bausystem.features.smartplace.SmartPlaceBehaviour; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.block.data.type.Repeater; +import org.bukkit.event.player.PlayerInteractEvent; + +@Linked(LinkageType.SMART_PLACE) +public class ReverseRepeaterBehaviour implements SmartPlaceBehaviour { + + @Override + public SmartPlaceType getType() { + return SmartPlaceType.INTERACT_DIRECT; + } + + @Override + public SmartPlaceResult interact(PlayerInteractEvent event) { + if (event.getPlayer().isSneaking()) { + if (event.getClickedBlock().getType() == Material.REPEATER) { + if (event.getItem() != null && event.getMaterial() != Material.REPEATER) { + return SmartPlaceResult.APPLIED; + } + Repeater repeater = (Repeater) event.getClickedBlock().getBlockData(); + int i = repeater.getDelay() - 1; + if (i <= 0) i += 4; + repeater.setDelay(i); + event.getClickedBlock().setBlockData(repeater); + event.setCancelled(true); + } + return SmartPlaceResult.APPLIED; + } + return SmartPlaceResult.IGNORED; + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java index 9b501472..ab9f6be6 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java @@ -20,13 +20,15 @@ package de.steamwar.bausystem.linkage; import de.steamwar.bausystem.BauSystem; -import de.steamwar.bausystem.configplayer.ConfigConverter; import de.steamwar.bausystem.configplayer.Config; +import de.steamwar.bausystem.configplayer.ConfigConverter; import de.steamwar.bausystem.features.gui.BauGUI; -import de.steamwar.bausystem.features.slaves.panzern.Panzern; -import de.steamwar.bausystem.features.slaves.panzern.PanzernAlgorithm; import de.steamwar.bausystem.features.script.ScriptExecutor; import de.steamwar.bausystem.features.script.SpecialCommand; +import de.steamwar.bausystem.features.slaves.panzern.Panzern; +import de.steamwar.bausystem.features.slaves.panzern.PanzernAlgorithm; +import de.steamwar.bausystem.features.smartplace.SmartPlaceBehaviour; +import de.steamwar.bausystem.features.smartplace.SmartPlaceListener; import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.linkage.specific.ScoreboardItem; import de.steamwar.command.SWCommand; @@ -58,7 +60,8 @@ public enum LinkageType { SCRIPT_COMMAND(4, false, SpecialCommand.class::isAssignableFrom, o -> ScriptExecutor.SPECIAL_COMMANDS.add((SpecialCommand) o)), CONFIG_CONVERTER(5, false, ConfigConverter.class::isAssignableFrom, o -> Config.addConfigConverter((ConfigConverter) o)), SCOREBOARD(6, false, ScoreboardItem.class::isAssignableFrom, o -> {}), - PANZERN(7, false, PanzernAlgorithm.class::isAssignableFrom, o -> Panzern.add((PanzernAlgorithm) o)); + PANZERN(7, false, PanzernAlgorithm.class::isAssignableFrom, o -> Panzern.add((PanzernAlgorithm) o)), + SMART_PLACE(8, false, SmartPlaceBehaviour.class::isAssignableFrom, o -> SmartPlaceListener.add((SmartPlaceBehaviour) o)); private final int order; From 58537c42f3422b66df468a6808f977d22c0e1a88 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 13:38:19 +0100 Subject: [PATCH 11/36] Add RawEntityShowMode Signed-off-by: yoyosource --- .../features/tracer/TraceCommand.java | 34 ++--- .../show/mode/FactoredEntityShowMode.java | 129 ++++++++++++++++++ .../tracer/show/mode/RawEntityShowMode.java | 32 +++++ .../tracer/show/mode/TraceEntityShowMode.java | 100 +------------- .../bausystem/shared/RoundedPosition.java | 14 ++ 5 files changed, 194 insertions(+), 115 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index 40732d54..a2162612 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -28,13 +28,16 @@ import de.steamwar.bausystem.features.tracer.show.Record; import de.steamwar.bausystem.features.tracer.show.*; import de.steamwar.bausystem.features.tracer.show.mode.BlockShowMode; import de.steamwar.bausystem.features.tracer.show.mode.ParticleShowMode; +import de.steamwar.bausystem.features.tracer.show.mode.RawEntityShowMode; import de.steamwar.bausystem.features.tracer.show.mode.TraceEntityShowMode; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.shared.ShowMode; import de.steamwar.bausystem.utils.ListChatView; import de.steamwar.command.SWCommand; import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; +import lombok.AllArgsConstructor; import lombok.NonNull; import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; @@ -46,6 +49,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.BiFunction; @Linked(LinkageType.COMMAND) public class TraceCommand extends SWCommand { @@ -313,10 +317,19 @@ public class TraceCommand extends SWCommand { internalShow(p, ShowModeType.PARTICLE, showModeParameterTypes); } + @Register({"show", "raw"}) + public void rawShowEntityCommand(Player p, ShowModeParameterType... showModeParameterTypes) { + internalShow(p, ShowModeType.RAW_ENTITY, showModeParameterTypes); + } + + @AllArgsConstructor private enum ShowModeType { - ENTITY, - PARTICLE, - BLOCK + ENTITY(TraceEntityShowMode::new), + RAW_ENTITY(RawEntityShowMode::new), + PARTICLE(ParticleShowMode::new), + BLOCK(BlockShowMode::new); + + private BiFunction> showModeBiFunction; } private void internalShow(Player p, @NonNull ShowModeType showModeType, ShowModeParameterType... showModeParameterTypes) { @@ -325,20 +338,7 @@ public class TraceCommand extends SWCommand { for (ShowModeParameterType showModeParameterType : showModeParameterTypes) { showModeParameterType.getShowModeParameterConsumer().accept(showModeParameter); } - switch (showModeType) { - case BLOCK: - TraceShowManager.show(p, new BlockShowMode(p, showModeParameter)); - break; - case PARTICLE: - TraceShowManager.show(p, new ParticleShowMode(p, showModeParameter)); - break; - case ENTITY: - TraceShowManager.show(p, new TraceEntityShowMode(p, showModeParameter)); - break; - default: - BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW_UNKNOWN", p); - return; - } + TraceShowManager.show(p, showModeType.showModeBiFunction.apply(p, showModeParameter)); BauSystem.MESSAGE.send("TRACE_MESSAGE_SHOW", p); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java new file mode 100644 index 00000000..ed03c9d8 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/FactoredEntityShowMode.java @@ -0,0 +1,129 @@ +/* + * 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.tracer.show.mode; + +import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; +import de.steamwar.bausystem.features.tracer.TNTPosition; +import de.steamwar.bausystem.features.tracer.TNTTracer_15; +import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; +import de.steamwar.bausystem.shared.RoundedPosition; +import de.steamwar.bausystem.shared.ShowMode; +import de.steamwar.core.VersionedCallable; +import org.bukkit.entity.Player; +import org.bukkit.util.Consumer; +import org.bukkit.util.Vector; + +import java.util.HashMap; +import java.util.Map; + +public abstract class FactoredEntityShowMode implements ShowMode { + + private int factor; + + protected final Player player; + protected final ShowModeParameter showModeParameter; + + private final Map tntEntityMap = new HashMap<>(); + private final Map updateEntityMap = new HashMap<>(); + + protected FactoredEntityShowMode(Player player, ShowModeParameter showModeParameter, int factor) { + this.player = player; + this.showModeParameter = showModeParameter; + this.factor = factor; + } + + @Override + public void show(TNTPosition position) { + if (showModeParameter.isExplodeOnly()) { + if (!position.isExploded()) { + return; + } + RoundedPosition roundedPosition = new RoundedPosition(position, factor); + AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true)); + entity.display(player, position.isExploded()); + return; + } + if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { + // Basic + for (TNTPosition pos : position.getRecord().getPositions()) { + RoundedPosition roundedPosition = new RoundedPosition(pos, factor); + tntEntityMap.computeIfPresent(roundedPosition, (p, tnt) -> { + return tnt.hide(player, false) ? null : tnt; + }); + } + // Advanced + for (TNTPosition pos : position.getRecord().getPositions()) { + applyOnPosition(pos, updatePointPosition -> { + updateEntityMap.computeIfPresent(new RoundedPosition(updatePointPosition, factor), (p, point) -> { + return point.hide(player, false) ? null : point; + }); + }); + } + return; + } + + RoundedPosition roundedPosition = new RoundedPosition(position, factor); + AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true)); + entity.display(player, position.isExploded()); + + applyOnPosition(position, updatePointPosition -> { + updateEntityMap.computeIfAbsent(new RoundedPosition(updatePointPosition, factor), pos -> { + return createEntity(player, updatePointPosition, false); + }).display(player, false); + }); + } + + private boolean checkWater(Vector position) { + return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 15)); + } + + public static AbstractTraceEntity createEntity(Player player, Vector position, boolean tnt) { + return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, tnt), 15)); + } + + private void applyOnPosition(TNTPosition position, Consumer function) { + if (position.getPreviousLocation() == null) return; + + if (showModeParameter.isInterpolate_Y()) { + Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); + if (!position.getLocation().equals(updatePointY)) { + function.accept(updatePointY); + } + } + + if (showModeParameter.isInterpolate_XZ()) { + Vector movement = position.getLocation().clone().subtract(position.getPreviousLocation()); + Vector updatePointXZ = Math.abs(movement.getX()) > Math.abs(movement.getZ()) + ? position.getLocation().clone().setZ(position.getPreviousLocation().getZ()) + : position.getLocation().clone().setX(position.getPreviousLocation().getX()); + if (!position.getLocation().equals(updatePointXZ)) { + function.accept(updatePointXZ); + } + } + } + + @Override + public void hide() { + tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); + tntEntityMap.clear(); + updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); + updateEntityMap.clear(); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java new file mode 100644 index 00000000..98e4c6d8 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java @@ -0,0 +1,32 @@ +/* + * + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 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.tracer.show.mode; + +import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; +import org.bukkit.entity.Player; + +public class RawEntityShowMode extends FactoredEntityShowMode { + + public RawEntityShowMode(Player player, ShowModeParameter showModeParameter) { + super(player, showModeParameter, 1000000); + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/TraceEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/TraceEntityShowMode.java index 6e7801ac..a5decb5c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/TraceEntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/TraceEntityShowMode.java @@ -21,108 +21,12 @@ package de.steamwar.bausystem.features.tracer.show.mode; -import de.steamwar.bausystem.features.tracer.AbstractTraceEntity; -import de.steamwar.bausystem.features.tracer.TNTPosition; -import de.steamwar.bausystem.features.tracer.TNTTracer_15; import de.steamwar.bausystem.features.tracer.show.ShowModeParameter; -import de.steamwar.bausystem.shared.RoundedPosition; -import de.steamwar.bausystem.shared.ShowMode; -import de.steamwar.core.VersionedCallable; import org.bukkit.entity.Player; -import org.bukkit.util.Consumer; -import org.bukkit.util.Vector; -import java.util.HashMap; -import java.util.Map; - -public class TraceEntityShowMode implements ShowMode { - - protected final Player player; - protected final ShowModeParameter showModeParameter; - - private final Map tntEntityMap = new HashMap<>(); - private final Map updateEntityMap = new HashMap<>(); +public class TraceEntityShowMode extends FactoredEntityShowMode { public TraceEntityShowMode(Player player, ShowModeParameter showModeParameter) { - this.player = player; - this.showModeParameter = showModeParameter; - } - - @Override - public void show(TNTPosition position) { - if (showModeParameter.isExplodeOnly()) { - if (!position.isExploded()) { - return; - } - RoundedPosition roundedPosition = new RoundedPosition(position); - AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true)); - entity.display(player, position.isExploded()); - return; - } - if (!showModeParameter.isWater() && position.isExploded() && checkWater(position.getLocation())) { - // Basic - for (TNTPosition pos : position.getRecord().getPositions()) { - RoundedPosition roundedPosition = new RoundedPosition(pos); - tntEntityMap.computeIfPresent(roundedPosition, (p, tnt) -> { - return tnt.hide(player, false) ? null : tnt; - }); - } - // Advanced - for (TNTPosition pos : position.getRecord().getPositions()) { - applyOnPosition(pos, updatePointPosition -> { - updateEntityMap.computeIfPresent(new RoundedPosition(updatePointPosition), (p, point) -> { - return point.hide(player, false) ? null : point; - }); - }); - } - return; - } - - RoundedPosition roundedPosition = new RoundedPosition(position); - AbstractTraceEntity entity = tntEntityMap.computeIfAbsent(roundedPosition, pos -> createEntity(player, position.getLocation(), true)); - entity.display(player, position.isExploded()); - - applyOnPosition(position, updatePointPosition -> { - updateEntityMap.computeIfAbsent(new RoundedPosition(updatePointPosition), pos -> { - return createEntity(player, updatePointPosition, false); - }).display(player, false); - }); - } - - private boolean checkWater(Vector position) { - return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_15.inWater(player.getWorld(), position), 15)); - } - - public static AbstractTraceEntity createEntity(Player player, Vector position, boolean tnt) { - return VersionedCallable.call(new VersionedCallable<>(() -> TNTTracer_15.create(player.getWorld(), position, tnt), 15)); - } - - private void applyOnPosition(TNTPosition position, Consumer function) { - if (position.getPreviousLocation() == null) return; - - if (showModeParameter.isInterpolate_Y()) { - Vector updatePointY = position.getPreviousLocation().clone().setY(position.getLocation().getY()); - if (!position.getLocation().equals(updatePointY)) { - function.accept(updatePointY); - } - } - - if (showModeParameter.isInterpolate_XZ()) { - Vector movement = position.getLocation().clone().subtract(position.getPreviousLocation()); - Vector updatePointXZ = Math.abs(movement.getX()) > Math.abs(movement.getZ()) - ? position.getLocation().clone().setZ(position.getPreviousLocation().getZ()) - : position.getLocation().clone().setX(position.getPreviousLocation().getX()); - if (!position.getLocation().equals(updatePointXZ)) { - function.accept(updatePointXZ); - } - } - } - - @Override - public void hide() { - tntEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); - tntEntityMap.clear(); - updateEntityMap.forEach((roundedPosition, abstractTraceEntity) -> abstractTraceEntity.hide(player, true)); - updateEntityMap.clear(); + super(player, showModeParameter, 10); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/shared/RoundedPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/shared/RoundedPosition.java index 55e791d3..c803bb9a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/shared/RoundedPosition.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/shared/RoundedPosition.java @@ -35,16 +35,30 @@ public class RoundedPosition { this(position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ()); } + public RoundedPosition(Position position, int factor) { + this(position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ(), factor); + } + public RoundedPosition(Vector vector) { this(vector.getX(), vector.getY(), vector.getZ()); } + public RoundedPosition(Vector vector, int factor) { + this(vector.getX(), vector.getY(), vector.getZ(), factor); + } + public RoundedPosition(double x, double y, double z) { this.x = (int) (x * factor); this.y = (int) (y * factor); this.z = (int) (z * factor); } + public RoundedPosition(double x, double y, double z, int factor) { + this.x = (int) (x * factor); + this.y = (int) (y * factor); + this.z = (int) (z * factor); + } + @Override public boolean equals(Object o) { if (this == o) return true; From 4aa66e12c40fc8fcd8ccc22788962734edfa750a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 13:52:27 +0100 Subject: [PATCH 12/36] Add RawEntityShowMode Signed-off-by: yoyosource --- .../tracer/show/mode/RawEntityShowMode.java | 2 +- .../bausystem/shared/RoundedPosition.java | 28 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java index 98e4c6d8..22952c0d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/mode/RawEntityShowMode.java @@ -27,6 +27,6 @@ import org.bukkit.entity.Player; public class RawEntityShowMode extends FactoredEntityShowMode { public RawEntityShowMode(Player player, ShowModeParameter showModeParameter) { - super(player, showModeParameter, 1000000); + super(player, showModeParameter, -1); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/shared/RoundedPosition.java b/BauSystem_Main/src/de/steamwar/bausystem/shared/RoundedPosition.java index c803bb9a..23aed77f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/shared/RoundedPosition.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/shared/RoundedPosition.java @@ -25,11 +25,11 @@ import java.util.Objects; public class RoundedPosition { - private static final int factor = 10; + private static final long factor = 10; - private int x; - private int y; - private int z; + private long x; + private long y; + private long z; public RoundedPosition(Position position) { this(position.getLocation().getX(), position.getLocation().getY(), position.getLocation().getZ()); @@ -48,15 +48,21 @@ public class RoundedPosition { } public RoundedPosition(double x, double y, double z) { - this.x = (int) (x * factor); - this.y = (int) (y * factor); - this.z = (int) (z * factor); + this.x = (long) (x * factor); + this.y = (long) (y * factor); + this.z = (long) (z * factor); } - public RoundedPosition(double x, double y, double z, int factor) { - this.x = (int) (x * factor); - this.y = (int) (y * factor); - this.z = (int) (z * factor); + public RoundedPosition(double x, double y, double z, long factor) { + if (factor == -1) { + this.x = Double.doubleToLongBits(x); + this.y = Double.doubleToLongBits(y); + this.z = Double.doubleToLongBits(z); + } else { + this.x = (long) (x * factor); + this.y = (long) (y * factor); + this.z = (long) (z * factor); + } } @Override From 84fd56ddcd1f392a6886ea66ab9e1560b790bc6a Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 14:37:25 +0100 Subject: [PATCH 13/36] Update RecordStateMachine Signed-off-by: yoyosource --- .../features/tracer/record/RecordStateMachine.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java index 8cb5e245..79c169c3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java @@ -19,10 +19,10 @@ package de.steamwar.bausystem.features.tracer.record; -public class RecordStateMachine { - private RecordStateMachine() { - } +import lombok.experimental.UtilityClass; +@UtilityClass +public class RecordStateMachine { private static final TraceAutoHandler autoHandler = new TraceAutoHandler(); private static RecordStatus recordStatus = RecordStatus.IDLE; From 1dcb2641e0cca8da03e9a01081b3af31a524fc02 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 16:30:11 +0100 Subject: [PATCH 14/36] Update internal stuff Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tracer/show/Record.java | 4 ++-- .../bausystem/features/tracer/show/StoredRecords.java | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java index b7ad90ec..c01ce31d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/Record.java @@ -61,14 +61,14 @@ public class Record { tnt.clear(); } - public TNTRecord get(int id) { + public TNTRecord get(long id) { for (TNTRecord record : tnt) { if (record.getId() == id) return record; } return null; } - public void remove(int id) { + public void remove(long id) { tnt.removeIf(record -> record.getId() == id); } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java index de516128..beaf1c1e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/show/StoredRecords.java @@ -40,11 +40,11 @@ public class StoredRecords { records.remove(record); } - public static void remove(int id) { + public static void remove(long id) { records.removeIf(record -> record.getId() == id); } - public static Record get(int id) { + public static Record get(long id) { for (Record record : records) { if (record.getId() == id) return record; } @@ -60,5 +60,4 @@ public class StoredRecords { TraceShowManager.clear(); RecordStateMachine.postClear(); } - } From 572b8bc3c887cc2acbcbf648c81177ff442ba115 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 16:46:14 +0100 Subject: [PATCH 15/36] Update BlockPlaceBehaviour Signed-off-by: yoyosource --- .../features/smartplace/behaviour/BlockPlaceBehaviour.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java index 8b7ee259..5474561c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/smartplace/behaviour/BlockPlaceBehaviour.java @@ -39,6 +39,10 @@ public class BlockPlaceBehaviour implements SmartPlaceBehaviour { @Override public SmartPlaceResult place(BlockPlaceEvent event) { + if (event.getBlockAgainst().getType().isInteractable()) { + return SmartPlaceResult.IGNORED; + } + SmartPlaceResult smartPlaceResult = SmartPlaceResult.IGNORED; Block block = event.getBlockPlaced(); BlockData blockData = block.getBlockData(); From ee45bf8d695a6c7e600c6ac3e306b750bb8ad1ea Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 17:12:58 +0100 Subject: [PATCH 16/36] Hotfix Region.reset Signed-off-by: yoyosource --- BauSystem_Main/src/de/steamwar/bausystem/region/Region.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index ee82e57b..48df628d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -434,7 +434,7 @@ public class Region { int dz = Math.abs(clipboard.getOrigin().getZ() - clipboard.getMinimumPoint().getZ()); if (dz < 2 || dz > prototype.getTestblock().getSizeZ()) { pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2); - } else if (clipboard.getDimensions().getZ() < prototype.getTestblock().getSizeZ()) { + } else if (clipboard.getDimensions().getZ() != prototype.getTestblock().getSizeZ()) { pastePoint = pastePoint.add(0, 0, clipboard.getDimensions().getZ() / 2 - (clipboard.getOrigin().getZ() - clipboard.getMinimumPoint().getZ()) - 1); } else { pastePoint = pastePoint.add(0, 0, prototype.getTestblock().getSizeZ() / 2); From da0e2f20ccf192b88bad4ce9d7dd5e494d2f65d9 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 17:27:08 +0100 Subject: [PATCH 17/36] Change Flag.PROTECT default to Active Signed-off-by: yoyosource --- BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ef2a65f7..4d3b9a2c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/flags/Flag.java @@ -36,7 +36,7 @@ public enum Flag implements EnumDisplay { FIRE("FLAG_FIRE", FireMode.class, FireMode.ALLOW, region -> true), DAMAGE("FLAG_DAMAGE", DamageMode.class, DamageMode.ALLOW, region -> false), FREEZE("FLAG_FREEZE", FreezeMode.class, FreezeMode.INACTIVE, region -> true), - PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.INACTIVE, region -> region.getFloorLevel() != 0); + PROTECT("FLAG_PROTECT", ProtectMode.class, ProtectMode.ACTIVE, region -> region.getFloorLevel() != 0); @Getter private static final Set flags; From eabfead5daa6f1c40e25a6cd994e5536b38f5232 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 22:45:06 +0100 Subject: [PATCH 18/36] Update TNTSimulator once again Signed-off-by: yoyosource --- .../features/simulator/TNTSimulator.java | 75 +++++++++++++------ 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index eb8d028c..ad07eac8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -54,6 +54,10 @@ public class TNTSimulator { private static final Vector Y_VECTOR = new Vector(0, 0.0625, 0); private static final Vector Z_VECTOR = new Vector(0, 0, 0.0625); + private static final Vector FX_VECTOR = new Vector(1, 0, 0); + private static final Vector FY_VECTOR = new Vector(0, 1, 0); + private static final Vector FZ_VECTOR = new Vector(0, 0, 1); + private static final World WORLD = Bukkit.getWorlds().get(0); private static final List LORE = Collections.singletonList("§eZum Ändern klicken"); private static final List EMPTY = new ArrayList<>(); @@ -215,7 +219,10 @@ public class TNTSimulator { return new SWListInv.SWListEntry<>(swItem, spawn); }).sorted(Comparator.comparing(SWListInv.SWListEntry::getObject)).collect(Collectors.toList()); - SWListInv swListInv = new SWListInv<>(player, "Kanonensimulator", false, swListEntryList, (clickType, spawn) -> spawn.editTNT()); + SWListInv swListInv = new SWListInv<>(player, "Kanonensimulator", false, swListEntryList, (clickType, spawn) -> { + + spawn.editTNT(); + }); swListInv.setItem(51, new SWItem(Material.BARRIER, "§cTNT löschen", clickType -> { delete(); player.closeInventory(); @@ -307,6 +314,7 @@ public class TNTSimulator { private boolean printed = false; private final Vector position; + private int fuseTicks = 80; private int count = 1; private int tickOffset = 0; private boolean xVelocity = false; @@ -324,6 +332,7 @@ public class TNTSimulator { private TNTSpawn(YAPIONObject yapionObject) { this.position = new Vector(yapionObject.getPlainValueOrDefault("positionX", 0.0), yapionObject.getPlainValueOrDefault("positionY", 0.0), yapionObject.getPlainValueOrDefault("positionZ", 0.0)); this.entity = SimulatorEntityShowMode.createEntity(player, position, false); + this.fuseTicks = yapionObject.getPlainValue("fuseTicks"); this.count = yapionObject.getPlainValue("count"); this.tickOffset = yapionObject.getPlainValue("tickOffset"); this.xVelocity = yapionObject.getPlainValue("xVelocity"); @@ -337,6 +346,7 @@ public class TNTSimulator { yapionObject.add("positionX", position.getX()); yapionObject.add("positionY", position.getY()); yapionObject.add("positionZ", position.getZ()); + yapionObject.add("fuseTicks", fuseTicks); yapionObject.add("count", count); yapionObject.add("tickOffset", tickOffset); yapionObject.add("xVelocity", xVelocity); @@ -362,12 +372,19 @@ public class TNTSimulator { private void spawn() { WORLD.spawn(position.toLocation(WORLD), TNTPrimed.class, tntPrimed -> { + tntPrimed.setFuseTicks(fuseTicks); if (!xVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setX(0)); if (!yVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setY(0)); if (!zVelocity) tntPrimed.setVelocity(tntPrimed.getVelocity().setZ(0)); }); } + private void setFuseTicks(int fuseTicks) { + if (fuseTicks < 0) fuseTicks = 0; + if (fuseTicks > 160) fuseTicks = 160; + this.fuseTicks = fuseTicks; + } + private void setCount(int count) { if (count < 1) count = 1; if (count > 400) count = 400; @@ -396,8 +413,8 @@ public class TNTSimulator { SWInventory swInventory = new SWInventory(player, 54, "TNT konfigurieren"); // Change Count of spawned TNT - swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { - setCount(count + 1); + swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e-10"), false, clickType -> { + setCount(count + (clickType.isShiftClick() ? 10 : 1)); editTNT(); })); SWItem countItem = new SWItem(Material.TNT, "§7TNT-Anzahl §8- §e" + count, LORE, false, clickType -> changeCount(player, "Anzahl TNT", count, c -> { @@ -406,14 +423,14 @@ public class TNTSimulator { }, this::editTNT)); countItem.getItemStack().setAmount(count); swInventory.setItem(10, countItem); - swInventory.setItem(19, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { - setCount(count - 1); + swInventory.setItem(19, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-10"), false, clickType -> { + setCount(count - (clickType.isShiftClick() ? 10 : 1)); editTNT(); })); // Change TickOffset - swInventory.setItem(2, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { - setTickOffset(tickOffset + 1); + swInventory.setItem(2, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+5"), false, clickType -> { + setTickOffset(count + (clickType.isShiftClick() ? 5 : 1)); editTNT(); })); SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), "§7Tick §8- §e" + tickOffset, LORE, false, clickType -> changeCount(player, "Tick Offset", tickOffset, tick -> { @@ -422,8 +439,24 @@ public class TNTSimulator { }, this::editTNT)); tickItem.getItemStack().setAmount(Math.max(tickOffset, 1)); swInventory.setItem(11, tickItem); - swInventory.setItem(20, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { - setTickOffset(tickOffset - 1); + swInventory.setItem(20, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { + setTickOffset(count - (clickType.isShiftClick() ? 5 : 1)); + editTNT(); + })); + + // Change FuseTicks + swInventory.setItem(3, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { + setFuseTicks(fuseTicks + 1); + editTNT(); + })); + SWItem fuseTickItem = new SWItem(Material.CLOCK, "§7Lebensdauer §8- §e" + fuseTicks, LORE, false, clickType -> changeCount(player, "Fuse-Ticks", fuseTicks, tick -> { + setFuseTicks(tick); + editTNT(); + }, this::editTNT)); + fuseTickItem.getItemStack().setAmount(Math.max(fuseTicks, 1)); + swInventory.setItem(12, fuseTickItem); + swInventory.setItem(21, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { + setFuseTicks(fuseTicks - 1); editTNT(); })); @@ -445,8 +478,8 @@ public class TNTSimulator { // Position Settings // X Position - swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§7+0,0625", clickType -> { - position.add(X_VECTOR); + swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§7+0,0625", Arrays.asList("§eShift §7Click für §e+1"), false, clickType -> { + position.add(clickType.isShiftClick() ? FX_VECTOR : X_VECTOR); editTNT(); })); swInventory.setItem(14, new SWItem(Material.PAPER, "§7x-Position §8- §e" + position.getX(), LORE, false, clickType -> { @@ -455,14 +488,14 @@ public class TNTSimulator { editTNT(); }, this::editTNT); })); - swInventory.setItem(23, new SWItem(SWItem.getDye(1), "§7-0,0625", clickType -> { - position.subtract(X_VECTOR); + swInventory.setItem(23, new SWItem(SWItem.getDye(1), "§7-0,0625", Arrays.asList("§eShift §7Click für §e-1"), false, clickType -> { + position.subtract(clickType.isShiftClick() ? FX_VECTOR : X_VECTOR); editTNT(); })); // Y Position - swInventory.setItem(6, new SWItem(SWItem.getDye(10), "§7+0,0625", clickType -> { - position.add(Y_VECTOR); + swInventory.setItem(6, new SWItem(SWItem.getDye(10), "§7+0,0625", Arrays.asList("§eShift §7Click für §e+1"), false, clickType -> { + position.add(clickType.isShiftClick() ? FY_VECTOR : Y_VECTOR); editTNT(); })); swInventory.setItem(15, new SWItem(Material.PAPER, "§7y-Position §8- §e" + position.getY(), LORE, false, clickType -> { @@ -471,14 +504,14 @@ public class TNTSimulator { editTNT(); }, this::editTNT); })); - swInventory.setItem(24, new SWItem(SWItem.getDye(1), "§7-0,0625", clickType -> { - position.subtract(Y_VECTOR); + swInventory.setItem(24, new SWItem(SWItem.getDye(1), "§7-0,0625", Arrays.asList("§eShift §7Click für §e-1"), false, clickType -> { + position.subtract(clickType.isShiftClick() ? FY_VECTOR : Y_VECTOR); editTNT(); })); // Z Position - swInventory.setItem(7, new SWItem(SWItem.getDye(10), "§7+0,0625", clickType -> { - position.add(Z_VECTOR); + swInventory.setItem(7, new SWItem(SWItem.getDye(10), "§7+0,0625", Arrays.asList("§eShift §7Click für §e+1"), false, clickType -> { + position.add(clickType.isShiftClick() ? FZ_VECTOR : Z_VECTOR); editTNT(); })); swInventory.setItem(16, new SWItem(Material.PAPER, "§7z-Position §8- §e" + position.getZ(), LORE, false, clickType -> { @@ -487,8 +520,8 @@ public class TNTSimulator { editTNT(); }, this::editTNT); })); - swInventory.setItem(25, new SWItem(SWItem.getDye(1), "§7-0,0625", clickType -> { - position.subtract(Z_VECTOR); + swInventory.setItem(25, new SWItem(SWItem.getDye(1), "§7-0,0625", Arrays.asList("§eShift §7Click für §e-1"), false, clickType -> { + position.subtract(clickType.isShiftClick() ? FZ_VECTOR : Z_VECTOR); editTNT(); })); From a90e75e182047823bae9b8a963279d3c01a3b8c8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 22:48:12 +0100 Subject: [PATCH 19/36] Update TNTSimulator once again Signed-off-by: yoyosource --- .../features/simulator/TNTSimulator.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index ad07eac8..6efa9600 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -413,8 +413,8 @@ public class TNTSimulator { SWInventory swInventory = new SWInventory(player, 54, "TNT konfigurieren"); // Change Count of spawned TNT - swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e-10"), false, clickType -> { - setCount(count + (clickType.isShiftClick() ? 10 : 1)); + swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { + setCount(count + (clickType.isShiftClick() ? 5 : 1)); editTNT(); })); SWItem countItem = new SWItem(Material.TNT, "§7TNT-Anzahl §8- §e" + count, LORE, false, clickType -> changeCount(player, "Anzahl TNT", count, c -> { @@ -423,8 +423,8 @@ public class TNTSimulator { }, this::editTNT)); countItem.getItemStack().setAmount(count); swInventory.setItem(10, countItem); - swInventory.setItem(19, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-10"), false, clickType -> { - setCount(count - (clickType.isShiftClick() ? 10 : 1)); + swInventory.setItem(19, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { + setCount(count - (clickType.isShiftClick() ? 5 : 1)); editTNT(); })); @@ -445,8 +445,8 @@ public class TNTSimulator { })); // Change FuseTicks - swInventory.setItem(3, new SWItem(SWItem.getDye(10), "§7+1", clickType -> { - setFuseTicks(fuseTicks + 1); + swInventory.setItem(3, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+5"), false, clickType -> { + setFuseTicks(fuseTicks + (clickType.isShiftClick() ? 5 : 1)); editTNT(); })); SWItem fuseTickItem = new SWItem(Material.CLOCK, "§7Lebensdauer §8- §e" + fuseTicks, LORE, false, clickType -> changeCount(player, "Fuse-Ticks", fuseTicks, tick -> { @@ -455,8 +455,8 @@ public class TNTSimulator { }, this::editTNT)); fuseTickItem.getItemStack().setAmount(Math.max(fuseTicks, 1)); swInventory.setItem(12, fuseTickItem); - swInventory.setItem(21, new SWItem(SWItem.getDye(1), "§7-1", clickType -> { - setFuseTicks(fuseTicks - 1); + swInventory.setItem(21, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { + setFuseTicks(fuseTicks - (clickType.isShiftClick() ? 5 : 1)); editTNT(); })); From e947224c1b13b8d087ea1b8194fd7a675783d4c7 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 22:50:11 +0100 Subject: [PATCH 20/36] Update TNTSimulator once again Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/simulator/TNTSimulator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index 6efa9600..ff5d44a3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -413,7 +413,7 @@ public class TNTSimulator { SWInventory swInventory = new SWInventory(player, 54, "TNT konfigurieren"); // Change Count of spawned TNT - swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { + swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+5"), false, clickType -> { setCount(count + (clickType.isShiftClick() ? 5 : 1)); editTNT(); })); From 873b97f70d93e9a4bfb1e284511f73a3ea6cab34 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 22:53:02 +0100 Subject: [PATCH 21/36] Update TNTSimulator once again Signed-off-by: yoyosource --- .../bausystem/features/simulator/TNTSimulator.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index ff5d44a3..36a70ef0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -461,7 +461,17 @@ public class TNTSimulator { })); // Velocity Settings - swInventory.setItem(38, Material.TNT, "TNT", clickType -> { + swInventory.setItem(38, Material.TNT, "§7TNT", clickType -> { + if (xVelocity || yVelocity || zVelocity) { + xVelocity = false; + yVelocity = false; + zVelocity = false; + } else { + xVelocity = true; + yVelocity = true; + zVelocity = true; + } + editTNT(); }); swInventory.setItem(46, new SWItem(getWool(xVelocity), getColor(xVelocity), "§7TNT §eSprung X §8- " + active(xVelocity), clickType -> { xVelocity = !xVelocity; From 161341da72142e8d422f8e4993668399bd401ac3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 10 Dec 2021 22:58:13 +0100 Subject: [PATCH 22/36] Update TNTSimulator once again Signed-off-by: yoyosource --- .../bausystem/features/simulator/TNTSimulator.java | 9 +++++++-- .../features/simulator/TNTSimulatorListener.java | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index 36a70ef0..08a08783 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -100,6 +100,11 @@ public class TNTSimulator { simulator.hide(); } + public void remove() { + TNTSimulator simulator = TNT_SIMULATOR_MAP.remove(player); + simulator.hide(); + } + private final Set spawns = new HashSet<>(); private final Player player; @@ -430,7 +435,7 @@ public class TNTSimulator { // Change TickOffset swInventory.setItem(2, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+5"), false, clickType -> { - setTickOffset(count + (clickType.isShiftClick() ? 5 : 1)); + setTickOffset(tickOffset + (clickType.isShiftClick() ? 5 : 1)); editTNT(); })); SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), "§7Tick §8- §e" + tickOffset, LORE, false, clickType -> changeCount(player, "Tick Offset", tickOffset, tick -> { @@ -440,7 +445,7 @@ public class TNTSimulator { tickItem.getItemStack().setAmount(Math.max(tickOffset, 1)); swInventory.setItem(11, tickItem); swInventory.setItem(20, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { - setTickOffset(count - (clickType.isShiftClick() ? 5 : 1)); + setTickOffset(tickOffset - (clickType.isShiftClick() ? 5 : 1)); editTNT(); })); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java index ba3b3763..4e0359df 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulatorListener.java @@ -119,7 +119,6 @@ public class TNTSimulatorListener implements Listener, Disable { if (event.getItem() == null || !event.getItem().isSimilar(WAND)) { return; } - System.out.println(event); event.setCancelled(true); if (!permissionCheck(event.getPlayer())) { @@ -142,7 +141,8 @@ public class TNTSimulatorListener implements Listener, Disable { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - get(event.getPlayer()).saveAndDelete(); + get(event.getPlayer()).save(); + get(event.getPlayer()).remove(); } @Override From d76f499a4eb4380c4f0305c615685678f7e1a2db Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 11 Dec 2021 12:16:19 +0100 Subject: [PATCH 23/36] Update TNTSimulator Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 3 + .../features/simulator/TNTSimulator.java | 170 ++++++++++++------ .../features/tracer/TraceCommand.java | 13 +- .../tracer/record/RecordStateMachine.java | 22 ++- .../features/tracer/record/RecordStatus.java | 5 +- 5 files changed, 151 insertions(+), 62 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index bd612c1c..fced1b13 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -521,13 +521,16 @@ BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht # Trace TRACE_RECORD=§aan TRACE_RECORD-AUTO=§aan +TRACE_RECORD-SINGLE=§aan TRACE_IDLE=§caus TRACE_IDLE-AUTO=§eauto +TRACE_IDLE-SINGLE=§esingle TRACE_MESSAGE-AUTO_RECORD=§cTNT-Tracer muss gestoppt werden TRACE_MESSAGE-AUTO_RECORD-AUTO=§cTNT-Tracer darf nicht aufnehmen TRACE_MESSAGE-AUTO_IDLE=§cAuto-Tracer gestoppt TRACE_MESSAGE-AUTO_IDLE-AUTO = §aAuto-Tracer gestartet TRACE_MESSAGE_START = §aTNT-Tracer gestartet +TRACE_MESSAGE_SINGLE = §aSingle-Tracer gestartet TRACE_MESSAGE_STOP = §cTNT-Tracer gestoppt TRACE_MESSAGE_DELETE = §cAlle TNT-Positionen gelöscht TRACE_MESSAGE_SHOW = §aAlle TNT-Positionen angezeigt diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index 08a08783..f39bb9a0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -24,7 +24,9 @@ package de.steamwar.bausystem.features.simulator; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.configplayer.Config; import de.steamwar.bausystem.features.simulator.show.SimulatorEntityShowMode; +import de.steamwar.bausystem.features.tracer.record.RecordStateMachine; import de.steamwar.bausystem.worlddata.SimulatorData; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; @@ -88,12 +90,6 @@ public class TNTSimulator { simulator.hide(); } - public void saveAndDelete() { - save(); - TNT_SIMULATOR_MAP.remove(player); - SimulatorData.removeSimulator(player, ""); - } - public void delete() { TNTSimulator simulator = TNT_SIMULATOR_MAP.remove(player); SimulatorData.removeSimulator(player, ""); @@ -159,7 +155,7 @@ public class TNTSimulator { return; } if (tntSpawns.size() == 1) { - tntSpawns.get(0).editTNT(); + tntSpawns.get(0).editTNT(spawns); } else { showGUI(new HashSet<>(tntSpawns)); } @@ -181,6 +177,12 @@ public class TNTSimulator { } public void start() { + boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); + if (simulatorAutoTrace) { + RecordStateMachine.commandSingle(); + player.performCommand("trace show"); + } + Map> first = new HashMap<>(); Map> second = new HashMap<>(); int lastTick = 0; @@ -225,8 +227,7 @@ public class TNTSimulator { }).sorted(Comparator.comparing(SWListInv.SWListEntry::getObject)).collect(Collectors.toList()); SWListInv swListInv = new SWListInv<>(player, "Kanonensimulator", false, swListEntryList, (clickType, spawn) -> { - - spawn.editTNT(); + spawn.editTNT(tntSpawns); }); swListInv.setItem(51, new SWItem(Material.BARRIER, "§cTNT löschen", clickType -> { delete(); @@ -236,9 +237,72 @@ public class TNTSimulator { start(); player.closeInventory(); })); + boolean simulatorAutoTrace = Config.getInstance().get(player).getPlainValueOrDefault("simulatorAutoTrace", false); + swListInv.setItem(48, new SWItem(simulatorAutoTrace ? Material.CHAIN_COMMAND_BLOCK : Material.COMMAND_BLOCK, "§eAutoTrace§8: §7" + simulatorAutoTrace, clickType -> { + Config.getInstance().get(player).put("simulatorAutoTrace", !simulatorAutoTrace); + showGUI(tntSpawns); + })); + swListInv.setItem(49, new SWItem(Material.MAGENTA_GLAZED_TERRACOTTA, "§eAlle Verschieben", clickType -> { + move(tntSpawns); + })); swListInv.open(); } + private void move(Set tntSpawns) { + SWInventory swInventory = new SWInventory(player, 54, "TNT Verschieben"); + + // Position Settings + // X Position + swInventory.setItem(12, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+0,0625"), false, clickType -> { + updatePosition(tntSpawns, vector -> vector.add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR)); + move(tntSpawns); + })); + swInventory.setItem(21, new SWItem(Material.PAPER, "§7x-Position", clickType -> { + })); + swInventory.setItem(30, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-0,0625"), false, clickType -> { + updatePosition(tntSpawns, vector -> vector.subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR)); + move(tntSpawns); + })); + + // Y Position + swInventory.setItem(13, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+0,0625"), false, clickType -> { + updatePosition(tntSpawns, vector -> vector.add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR)); + move(tntSpawns); + })); + swInventory.setItem(22, new SWItem(Material.PAPER, "§7y-Position", clickType -> { + })); + swInventory.setItem(31, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-0,0625"), false, clickType -> { + updatePosition(tntSpawns, vector -> vector.subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR)); + move(tntSpawns); + })); + + // Z Position + swInventory.setItem(14, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+0,0625"), false, clickType -> { + updatePosition(tntSpawns, vector -> vector.add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR)); + move(tntSpawns); + })); + swInventory.setItem(23, new SWItem(Material.PAPER, "§7z-Position", clickType -> { + })); + swInventory.setItem(32, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-0,0625"), false, clickType -> { + updatePosition(tntSpawns, vector -> vector.subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR)); + move(tntSpawns); + })); + + swInventory.setItem(53, new SWItem(Material.ARROW, "§eZurück", clickType -> { + showGUI(tntSpawns); + })); + swInventory.open(); + } + + private void updatePosition(Set tntSpawns, Consumer positionChanger) { + Set vectors = new HashSet<>(); + for (TNTSpawn tntSpawn : tntSpawns) { + if (vectors.add(tntSpawn.position)) { + positionChanger.accept(tntSpawn.position); + } + } + } + private List getEntity(Entity entity) { List tntSpawns = new ArrayList<>(); for (TNTSpawn spawn : spawns) { @@ -331,7 +395,7 @@ public class TNTSimulator { this.position = position; this.entity = entity; show(); - editTNT(); + editTNT(spawns); } private TNTSpawn(YAPIONObject yapionObject) { @@ -411,7 +475,7 @@ public class TNTSimulator { return -Integer.compare(tickOffset, tntSpawn.tickOffset); } - private void editTNT() { + private void editTNT(Set tntSpawns) { hide(); entity.setPosition(position); show(); @@ -420,49 +484,49 @@ public class TNTSimulator { // Change Count of spawned TNT swInventory.setItem(1, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+5"), false, clickType -> { setCount(count + (clickType.isShiftClick() ? 5 : 1)); - editTNT(); + editTNT(tntSpawns); })); SWItem countItem = new SWItem(Material.TNT, "§7TNT-Anzahl §8- §e" + count, LORE, false, clickType -> changeCount(player, "Anzahl TNT", count, c -> { setCount(c); - editTNT(); - }, this::editTNT)); + editTNT(tntSpawns); + }, () -> editTNT(tntSpawns))); countItem.getItemStack().setAmount(count); swInventory.setItem(10, countItem); swInventory.setItem(19, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { setCount(count - (clickType.isShiftClick() ? 5 : 1)); - editTNT(); + editTNT(tntSpawns); })); // Change TickOffset swInventory.setItem(2, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+5"), false, clickType -> { setTickOffset(tickOffset + (clickType.isShiftClick() ? 5 : 1)); - editTNT(); + editTNT(tntSpawns); })); SWItem tickItem = new SWItem(SWItem.getMaterial("DIODE"), "§7Tick §8- §e" + tickOffset, LORE, false, clickType -> changeCount(player, "Tick Offset", tickOffset, tick -> { setTickOffset(tick); - editTNT(); - }, this::editTNT)); + editTNT(tntSpawns); + }, () -> editTNT(tntSpawns))); tickItem.getItemStack().setAmount(Math.max(tickOffset, 1)); swInventory.setItem(11, tickItem); swInventory.setItem(20, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { setTickOffset(tickOffset - (clickType.isShiftClick() ? 5 : 1)); - editTNT(); + editTNT(tntSpawns); })); // Change FuseTicks swInventory.setItem(3, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+5"), false, clickType -> { setFuseTicks(fuseTicks + (clickType.isShiftClick() ? 5 : 1)); - editTNT(); + editTNT(tntSpawns); })); SWItem fuseTickItem = new SWItem(Material.CLOCK, "§7Lebensdauer §8- §e" + fuseTicks, LORE, false, clickType -> changeCount(player, "Fuse-Ticks", fuseTicks, tick -> { setFuseTicks(tick); - editTNT(); - }, this::editTNT)); + editTNT(tntSpawns); + }, () -> editTNT(tntSpawns))); fuseTickItem.getItemStack().setAmount(Math.max(fuseTicks, 1)); swInventory.setItem(12, fuseTickItem); swInventory.setItem(21, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-5"), false, clickType -> { setFuseTicks(fuseTicks - (clickType.isShiftClick() ? 5 : 1)); - editTNT(); + editTNT(tntSpawns); })); // Velocity Settings @@ -476,74 +540,74 @@ public class TNTSimulator { yVelocity = true; zVelocity = true; } - editTNT(); + editTNT(tntSpawns); }); swInventory.setItem(46, new SWItem(getWool(xVelocity), getColor(xVelocity), "§7TNT §eSprung X §8- " + active(xVelocity), clickType -> { xVelocity = !xVelocity; - editTNT(); + editTNT(tntSpawns); })); swInventory.setItem(29, new SWItem(getWool(yVelocity), getColor(yVelocity), "§7TNT §eSprung Y §8- " + active(yVelocity), clickType -> { yVelocity = !yVelocity; - editTNT(); + editTNT(tntSpawns); })); swInventory.setItem(48, new SWItem(getWool(zVelocity), getColor(zVelocity), "§7TNT §eSprung Z §8- " + active(zVelocity), clickType -> { zVelocity = !zVelocity; - editTNT(); + editTNT(tntSpawns); })); // Position Settings // X Position - swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§7+0,0625", Arrays.asList("§eShift §7Click für §e+1"), false, clickType -> { - position.add(clickType.isShiftClick() ? FX_VECTOR : X_VECTOR); - editTNT(); + swInventory.setItem(5, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+0,0625"), false, clickType -> { + position.add(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); + editTNT(tntSpawns); })); swInventory.setItem(14, new SWItem(Material.PAPER, "§7x-Position §8- §e" + position.getX(), LORE, false, clickType -> { changePosition(player, position.getX(), x -> { position.setX(clamp(x)); - editTNT(); - }, this::editTNT); + editTNT(tntSpawns); + }, () -> editTNT(tntSpawns)); })); - swInventory.setItem(23, new SWItem(SWItem.getDye(1), "§7-0,0625", Arrays.asList("§eShift §7Click für §e-1"), false, clickType -> { - position.subtract(clickType.isShiftClick() ? FX_VECTOR : X_VECTOR); - editTNT(); + swInventory.setItem(23, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-0,0625"), false, clickType -> { + position.subtract(clickType.isShiftClick() ? X_VECTOR : FX_VECTOR); + editTNT(tntSpawns); })); // Y Position - swInventory.setItem(6, new SWItem(SWItem.getDye(10), "§7+0,0625", Arrays.asList("§eShift §7Click für §e+1"), false, clickType -> { - position.add(clickType.isShiftClick() ? FY_VECTOR : Y_VECTOR); - editTNT(); + swInventory.setItem(6, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+0,0625"), false, clickType -> { + position.add(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); + editTNT(tntSpawns); })); swInventory.setItem(15, new SWItem(Material.PAPER, "§7y-Position §8- §e" + position.getY(), LORE, false, clickType -> { changePosition(player, position.getY(), y -> { position.setY(clamp(y)); - editTNT(); - }, this::editTNT); + editTNT(tntSpawns); + }, () -> editTNT(tntSpawns)); })); - swInventory.setItem(24, new SWItem(SWItem.getDye(1), "§7-0,0625", Arrays.asList("§eShift §7Click für §e-1"), false, clickType -> { - position.subtract(clickType.isShiftClick() ? FY_VECTOR : Y_VECTOR); - editTNT(); + swInventory.setItem(24, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-0,0625"), false, clickType -> { + position.subtract(clickType.isShiftClick() ? Y_VECTOR : FY_VECTOR); + editTNT(tntSpawns); })); // Z Position - swInventory.setItem(7, new SWItem(SWItem.getDye(10), "§7+0,0625", Arrays.asList("§eShift §7Click für §e+1"), false, clickType -> { - position.add(clickType.isShiftClick() ? FZ_VECTOR : Z_VECTOR); - editTNT(); + swInventory.setItem(7, new SWItem(SWItem.getDye(10), "§7+1", Arrays.asList("§eShift §7Click für §e+0,0625"), false, clickType -> { + position.add(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); + editTNT(tntSpawns); })); swInventory.setItem(16, new SWItem(Material.PAPER, "§7z-Position §8- §e" + position.getZ(), LORE, false, clickType -> { changePosition(player, position.getZ(), z -> { position.setZ(clamp(z)); - editTNT(); - }, this::editTNT); + editTNT(tntSpawns); + }, () -> editTNT(tntSpawns)); })); - swInventory.setItem(25, new SWItem(SWItem.getDye(1), "§7-0,0625", Arrays.asList("§eShift §7Click für §e-1"), false, clickType -> { - position.subtract(clickType.isShiftClick() ? FZ_VECTOR : Z_VECTOR); - editTNT(); + swInventory.setItem(25, new SWItem(SWItem.getDye(1), "§7-1", Arrays.asList("§eShift §7Click für §e-0,0625"), false, clickType -> { + position.subtract(clickType.isShiftClick() ? Z_VECTOR : FZ_VECTOR); + editTNT(tntSpawns); })); // Repeater before Comparator swInventory.setItem(42, new SWItem(comparator ? SWItem.getMaterial("REDSTONE_COMPARATOR_OFF") : SWItem.getMaterial("DIODE"), "§7Gezündet durch §8- §e" + (comparator ? "Comparator" : "Repeater"), clickType -> { comparator = !comparator; - editTNT(); + editTNT(tntSpawns); })); swInventory.setItem(33, new SWItem(Material.TNT, "§eZündphase hinzufügen", clickType -> { @@ -551,7 +615,7 @@ public class TNTSimulator { })); swInventory.setItem(53, new SWItem(Material.ARROW, "§eZurück", clickType -> { - showGUI(); + showGUI(tntSpawns); })); swInventory.setItem(51, new SWItem(Material.DISPENSER, "§eTNT hinzufügen", clickType -> { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java index a2162612..ce66267a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/TraceCommand.java @@ -263,6 +263,13 @@ public class TraceCommand extends SWCommand { BauSystem.MESSAGE.send("TRACE_MESSAGE_START", p); } + @Register({"single"}) + public void singleCommand(Player p) { + if (!permissionCheck(p)) return; + RecordStateMachine.commandSingle(); + BauSystem.MESSAGE.send("TRACE_MESSAGE_SINGLE", p); + } + @Register({"stop"}) public void stopCommand(Player p) { if (!permissionCheck(p)) return; @@ -270,12 +277,8 @@ public class TraceCommand extends SWCommand { BauSystem.MESSAGE.send("TRACE_MESSAGE_STOP", p); } - @Register({"toggleauto"}) - public void toggleAutoCommand(Player p) { - autoCommand(p); - } - @Register({"auto"}) + @Register({"toggleauto"}) public void autoCommand(Player p) { if (!permissionCheck(p)) return; RecordStateMachine.commandAuto(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java index 79c169c3..d83ab71d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStateMachine.java @@ -53,14 +53,32 @@ public class RecordStateMachine { } } + public static void commandSingle() { + if (recordStatus.isTracing()) + return; + + if (recordStatus != RecordStatus.IDLE_SINGLE) { + recordStatus = RecordStatus.IDLE_SINGLE; + autoHandler.enable(); + } + } + static void autoRecord() { recordStart(); - recordStatus = RecordStatus.RECORD_AUTO; + if (recordStatus == RecordStatus.IDLE_AUTO) { + recordStatus = RecordStatus.RECORD_AUTO; + } else { + recordStatus = RecordStatus.RECORD_SINGLE; + } } static void autoIdle() { recordStop(); - recordStatus = RecordStatus.IDLE_AUTO; + if (recordStatus == RecordStatus.RECORD_AUTO) { + recordStatus = RecordStatus.IDLE_AUTO; + } else { + recordStatus = RecordStatus.IDLE; + } } private static void recordStart() { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStatus.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStatus.java index f5d37e2e..e1198b11 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStatus.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/RecordStatus.java @@ -23,8 +23,10 @@ public enum RecordStatus { RECORD("TRACE_RECORD", true, "TRACE_MESSAGE-AUTO_RECORD"), RECORD_AUTO("TRACE_RECORD-AUTO", true, "TRACE_MESSAGE-AUTO_RECORD-AUTO"), + RECORD_SINGLE("TRACE_RECORD-SINGLE", true, ""), IDLE("TRACE_IDLE", false, "TRACE_MESSAGE-AUTO_IDLE"), - IDLE_AUTO("TRACE_IDLE-AUTO", false, "TRACE_MESSAGE-AUTO_IDLE-AUTO"); + IDLE_AUTO("TRACE_IDLE-AUTO", false, "TRACE_MESSAGE-AUTO_IDLE-AUTO"), + IDLE_SINGLE("TRACE_IDLE-SINGLE", false, ""); String name; boolean tracing; @@ -51,5 +53,4 @@ public enum RecordStatus { public String getAutoMessage() { return autoMessage; } - } From 52b3ded99c1c14d74b782e4fcdc3e5dbe68b80bc Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 11 Dec 2021 14:04:39 +0100 Subject: [PATCH 24/36] Fix NPE Signed-off-by: yoyosource --- .../bausystem/features/tracer/record/TraceAutoHandler.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceAutoHandler.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceAutoHandler.java index f95a75a4..298dde87 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceAutoHandler.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tracer/record/TraceAutoHandler.java @@ -63,8 +63,10 @@ public class TraceAutoHandler implements Listener { if (lastExplosion > 80) { RecordStateMachine.autoIdle(); - task.cancel(); - task = null; + if (task != null) { + task.cancel(); + task = null; + } } } } From 57128a95b03c49ef6330d662b5966cb90b22bbc6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sun, 12 Dec 2021 15:43:40 +0100 Subject: [PATCH 25/36] Hotfix TNTSimulator Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/simulator/TNTSimulator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index f39bb9a0..bd5820ed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -401,7 +401,7 @@ public class TNTSimulator { private TNTSpawn(YAPIONObject yapionObject) { this.position = new Vector(yapionObject.getPlainValueOrDefault("positionX", 0.0), yapionObject.getPlainValueOrDefault("positionY", 0.0), yapionObject.getPlainValueOrDefault("positionZ", 0.0)); this.entity = SimulatorEntityShowMode.createEntity(player, position, false); - this.fuseTicks = yapionObject.getPlainValue("fuseTicks"); + this.fuseTicks = yapionObject.getPlainValueOrDefault("fuseTicks", 80); this.count = yapionObject.getPlainValue("count"); this.tickOffset = yapionObject.getPlainValue("tickOffset"); this.xVelocity = yapionObject.getPlainValue("xVelocity"); From 9cc26634c930ef50308d1e8e03e9fe9beeeb1a23 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Dec 2021 01:32:30 +0100 Subject: [PATCH 26/36] Update TNTSimulator Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/simulator/TNTSimulator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java index bd5820ed..1907dee0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/simulator/TNTSimulator.java @@ -367,7 +367,7 @@ public class TNTSimulator { } } - if (player.isSneaking()) { + if (!player.isSneaking()) { pos.setX(pos.getBlockX() + 0.5); if (face == null || face.getModY() == 0) pos.setY(pos.getBlockY() + 0.0); From 6a6907bb431b5492d2f5154ece234ee6ae4c1180 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Dec 2021 11:55:22 +0100 Subject: [PATCH 27/36] Fix TPSLimitCommand Signed-off-by: yoyosource --- .../bausystem/features/tpslimit/TPSLimitCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java index 7a56e37f..c7316bd1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java @@ -30,8 +30,11 @@ import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; +import net.minecraft.server.v1_15_R1.WorldServer; import org.bukkit.Bukkit; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.entity.Player; +import yapion.utils.ReflectionsUtils; import java.util.ArrayList; import java.util.Arrays; @@ -86,10 +89,11 @@ public class TPSLimitCommand extends SWCommand implements Enable { @ClassMapper(value = double.class, local = true) public TypeMapper doubleTypeMapper() { return SWCommandUtils.createMapper(s -> { + if (s.equalsIgnoreCase("nan")) return -1D; try { return Double.parseDouble(s.replace(',', '.')); } catch (NumberFormatException e) { - return 0D; + return -1D; } }, s -> tabCompletions); } From 5ae5fe3de3eb5ec68b9e3a4a7d5d4677b4b8f4fa Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Dec 2021 14:19:33 +0100 Subject: [PATCH 28/36] Add OtherListener Signed-off-by: yoyosource --- .../features/region/OtherListener.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/region/OtherListener.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/region/OtherListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/region/OtherListener.java new file mode 100644 index 00000000..d55e3986 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/region/OtherListener.java @@ -0,0 +1,46 @@ +/* + * 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.region; + +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockFadeEvent; +import org.bukkit.event.block.BlockFormEvent; + +@Linked(LinkageType.LISTENER) +public class OtherListener implements Listener { + + @EventHandler + public void onBlockForm(BlockFormEvent event) { + if (event.getBlock().getType() == Material.SNOW_BLOCK || event.getBlock().getType() == Material.SNOW) { + event.setCancelled(true); + } + } + + @EventHandler + public void onBlockFade(BlockFadeEvent event) { + if (event.getBlock().getType() == Material.SNOW_BLOCK || event.getBlock().getType() == Material.SNOW) { + event.setCancelled(true); + } + } +} From bae41e807d0008f725c0f6f7222b74f3d63ec713 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Dec 2021 15:49:06 +0100 Subject: [PATCH 29/36] Add FreezeUtils Add TickCommand Signed-off-by: yoyosource --- .../features/tpslimit/FreezeUtils.java | 72 +++++++++++++++ .../features/tpslimit/TPSLimitCommand.java | 16 +++- .../features/tpslimit/TPSLimitUtils.java | 1 - .../features/tpslimit/TPSWarpUtils.java | 2 +- .../features/tpslimit/TickCommand.java | 92 +++++++++++++++++++ 5 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java new file mode 100644 index 00000000..75703f76 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java @@ -0,0 +1,72 @@ +/* + * 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.tpslimit; + +import lombok.experimental.UtilityClass; +import net.minecraft.server.v1_15_R1.WorldServer; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import yapion.utils.ReflectionsUtils; + +import java.lang.reflect.Field; + +@UtilityClass +public class FreezeUtils { + + private static final Field field; + public static final boolean freezeEnabled; + + static { + field = ReflectionsUtils.getField(WorldServer.class, "freezed"); + if (field != null) field.setAccessible(true); + freezeEnabled = field != null; + } + + public static void freeze(World world) { + setFreeze(world, true); + } + + public static void unfreeze(World world) { + setFreeze(world, false); + } + + public static boolean frozen(World world) { + if (freezeEnabled) { + try { + return (boolean) field.get(((CraftWorld) world).getHandle()); + } catch (IllegalAccessException e) { + // Ignored; + } + } + return false; + } + + private void setFreeze(World world, boolean state) { + if (freezeEnabled) { + try { + System.out.println(state + " " + frozen(world)); + field.set(((CraftWorld) world).getHandle(), state); + System.out.println(state + " " + frozen(world)); + } catch (IllegalAccessException e) { + // Ignored; + } + } + } +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java index c7316bd1..c4ac11ed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java @@ -30,11 +30,8 @@ import de.steamwar.command.SWCommandUtils; import de.steamwar.command.TypeMapper; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.TextComponent; -import net.minecraft.server.v1_15_R1.WorldServer; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import org.bukkit.entity.Player; -import yapion.utils.ReflectionsUtils; import java.util.ArrayList; import java.util.Arrays; @@ -53,6 +50,9 @@ public class TPSLimitCommand extends SWCommand implements Enable { tabCompletions.add(i + ""); } } + if (FreezeUtils.freezeEnabled) { + tabCompletions.add("0"); + } } @Override @@ -77,10 +77,18 @@ public class TPSLimitCommand extends SWCommand implements Enable { @Register public void valueCommand(Player p, /*@DoubleRange(min = 0.5, max = 60)*/ double tpsLimitDouble) { if (!permissionCheck(p)) return; + if (FreezeUtils.freezeEnabled && tpsLimitDouble == 0) { + FreezeUtils.freeze(p.getWorld()); + TPSLimitUtils.currentTPSLimit = 20; + TPSLimitUtils.tpsLimiter(); + sendNewTPSLimitMessage(); + return; + } if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) { sendInvalidArgumentMessage(p); return; } + FreezeUtils.unfreeze(p.getWorld()); TPSLimitUtils.currentTPSLimit = tpsLimitDouble; TPSLimitUtils.tpsLimiter(); sendNewTPSLimitMessage(); @@ -112,6 +120,6 @@ public class TPSLimitCommand extends SWCommand implements Enable { } private void sendInvalidArgumentMessage(Player player) { - player.sendMessage(BauSystem.PREFIX + ColorConfig.DISABLE + "Nur Zahlen zwischen 0,5 und " + (TPSWarpUtils.isWarpAllowed() ? 60 : 20) + ", und 'default' erlaubt."); + player.sendMessage(BauSystem.PREFIX + ColorConfig.DISABLE + "Nur Zahlen zwischen 0,5 und " + (TPSWarpUtils.isWarpAllowed() ? 60 : 20) + ", und 'default'" + (FreezeUtils.freezeEnabled ? " und '0'" : "") + " erlaubt."); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java index a7952d08..7d4d6e9b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitUtils.java @@ -86,5 +86,4 @@ public class TPSLimitUtils { currentTPSLimit = d; tpsLimiter(); } - } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java index 997ae238..28fbbc02 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSWarpUtils.java @@ -44,7 +44,7 @@ public class TPSWarpUtils { public static void setTPS(double tps) { double d = 50 - (50 / (tps / 20.0)); - nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 37500000)); + nanoDOffset = Math.max(0, Math.min((long) (d * 1000000), 375000000)); if (Core.getVersion() != 15) { return; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java new file mode 100644 index 00000000..2f7fb020 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java @@ -0,0 +1,92 @@ +/* + * 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.tpslimit; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.command.SWCommand; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +import java.util.concurrent.atomic.AtomicInteger; + +@Linked(LinkageType.COMMAND) +public class TickCommand extends SWCommand { + + private AtomicInteger ticksLeft = null; + private Runnable disableTask = null; + + public TickCommand() { + super("tick"); + if (!FreezeUtils.freezeEnabled) { + unregister(); + return; + } + + new BukkitRunnable() { + @Override + public void run() { + if (ticksLeft == null) { + return; + } + + if (ticksLeft.getAndDecrement() < 0) { + disableTask.run(); + disableTask = null; + ticksLeft = null; + } + } + }.runTaskTimer(BauSystem.getInstance(), 0L, 1L); + } + + @Register({"step"}) + public void stepCommand(Player p, @OptionalValue("1") int ticks) { + if (ticksLeft != null) { + return; + } + FreezeUtils.unfreeze(p.getWorld()); + ticksLeft = new AtomicInteger(ticks); + disableTask = () -> { + FreezeUtils.freeze(p.getWorld()); + }; + } + + @Register({"warp"}) + public void warpCommand(Player p, int ticks) { + if (ticksLeft != null) { + return; + } + boolean frozen = FreezeUtils.frozen(p.getWorld()); + double currentTPSLimit = TPSLimitUtils.currentTPSLimit; + TPSLimitUtils.currentTPSLimit = 120; + TPSLimitUtils.tpsLimiter(); + + FreezeUtils.unfreeze(p.getWorld()); + ticksLeft = new AtomicInteger(ticks); + disableTask = () -> { + if (frozen) { + FreezeUtils.freeze(p.getWorld()); + } + TPSLimitUtils.currentTPSLimit = currentTPSLimit; + TPSLimitUtils.tpsLimiter(); + }; + } +} From dccae06a36ec9aafe382f68a25064e641f9bbf28 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Dec 2021 16:02:04 +0100 Subject: [PATCH 30/36] Fix TickCommand Signed-off-by: yoyosource --- .../de/steamwar/bausystem/features/tpslimit/TickCommand.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java index 2f7fb020..14a1012c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java @@ -57,6 +57,11 @@ public class TickCommand extends SWCommand { }.runTaskTimer(BauSystem.getInstance(), 0L, 1L); } + @Register({"step"}) + public void stepCommand(Player p) { + stepCommand(p, 1); + } + @Register({"step"}) public void stepCommand(Player p, @OptionalValue("1") int ticks) { if (ticksLeft != null) { From a04cc76bbe6e2c8c5833d2d0585c5d295cfe5390 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Dec 2021 16:26:45 +0100 Subject: [PATCH 31/36] Update messages Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 18 +++++++++- .../features/tpslimit/TPSLimitBauGuiItem.java | 8 ++--- .../features/tpslimit/TPSLimitCommand.java | 35 ++++++++++--------- .../bausystem/features/tpslimit/TPSUtils.java | 1 - .../features/tpslimit/TickCommand.java | 18 +++++++--- 5 files changed, 53 insertions(+), 27 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index fced1b13..f5415457 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -518,6 +518,23 @@ BLOCK_COUNTER_MESSAGE = §e{0} §7Blöcke §e{1} §7TNT §e{2} §7Blöcke/TNT BLOCK_COUNTER_ENABLE = §7BlockCounter angemacht BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht +# TPSLimit +TICK_STEP_HELP = §8/§etick step §8<§7Ticks§8> §8- §7Spule n Ticks vor +TICK_STEP_SINGLE_HELP = §8/§etick step §8- §7Spule einen Ticks vor +TICK_WARP_HELP = §8/§etick warp §8<§7Ticks§8> §8- §7Warpe n Ticks vor +TICK_STEP = §eSpult {0} Ticks vor +TICK_WARP = §eWarpe {0} Ticks vor +TPSLIMIT_GUI_ITEM_NAME = §eTPS Limiter +TPSLIMIT_GUI_ITEM_LORE = §7Aktuell: §e{0} +TPSLIMIT_ANVIL_GUI = Neues TPS Limit +TPSLIMIT_HELP = §8/§etpslimit §8[§7TPS§8|§edefault§8] §8- §7Setzte die TPS auf dem Bau +TPSLIMIT_CURRENT = §7Jetziges TPS limit§8: §e{0} +TPSLIMIT_NO_PERMS = §cDu darfst hier nicht den TPS-Limiter nutzen +TPSLIMIT_SET = §eTPS limit auf {0} gesetzt. +TPSLIMIT_FROZEN = §eTPS eingefroren. +TPSLIMIT_INVALID = §cNur Zahlen zwischen 0,5 und {0}, und 'default'{1} erlaubt. +TPSLIMIT_INVALID_FROZEN = §c und '0' + # Trace TRACE_RECORD=§aan TRACE_RECORD-AUTO=§aan @@ -534,7 +551,6 @@ TRACE_MESSAGE_SINGLE = §aSingle-Tracer gestartet TRACE_MESSAGE_STOP = §cTNT-Tracer gestoppt TRACE_MESSAGE_DELETE = §cAlle TNT-Positionen gelöscht TRACE_MESSAGE_SHOW = §aAlle TNT-Positionen angezeigt -TRACE_MESSAGE_SHOW_UNKNOWN = §cUnbekannter Show Mode TRACE_MESSAGE_HIDE = §cAlle TNT-Positionen ausgeblendet TRACE_MESSAGE_DISALLOWED = §cDu darfst hier nicht den TNT-Tracer nutzen diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitBauGuiItem.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitBauGuiItem.java index bf72ef38..8451bf5a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitBauGuiItem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitBauGuiItem.java @@ -19,11 +19,11 @@ package de.steamwar.bausystem.features.tpslimit; +import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.config.ColorConfig; -import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; +import de.steamwar.bausystem.linkage.specific.BauGuiItem; import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWItem; import org.bukkit.Material; @@ -42,14 +42,14 @@ public class TPSLimitBauGuiItem extends BauGuiItem { @Override public ItemStack getItem(Player player) { - return new SWItem(Material.CLOCK, ColorConfig.HIGHLIGHT + "TPS Limiter", Arrays.asList(ColorConfig.BASE + "Aktuell: " + ColorConfig.HIGHLIGHT + TPSLimitUtils.getCurrentTPSLimit()), false, clickType -> { + return new SWItem(Material.CLOCK, BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_NAME", player), Arrays.asList(BauSystem.MESSAGE.parse("TPSLIMIT_GUI_ITEM_LORE", player, TPSLimitUtils.getCurrentTPSLimit())), false, clickType -> { }).getItemStack(); } @Override public boolean click(ClickType click, Player p) { p.closeInventory(); - SWAnvilInv inv = new SWAnvilInv(p, "Neues TPS Limit"); + SWAnvilInv inv = new SWAnvilInv(p, BauSystem.MESSAGE.parse("TPSLIMIT_ANVIL_GUI", p)); inv.setItem(Material.CLOCK); inv.setCallback(s -> p.performCommand("tpslimit " + s)); inv.open(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java index c4ac11ed..042ba479 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java @@ -21,15 +21,13 @@ package de.steamwar.bausystem.features.tpslimit; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; -import de.steamwar.bausystem.config.ColorConfig; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.linkage.Enable; 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 net.md_5.bungee.api.ChatMessageType; -import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -53,6 +51,7 @@ public class TPSLimitCommand extends SWCommand implements Enable { if (FreezeUtils.freezeEnabled) { tabCompletions.add("0"); } + addDefaultHelpMessage("TPSLIMIT_HELP"); } @Override @@ -60,18 +59,16 @@ public class TPSLimitCommand extends SWCommand implements Enable { TPSWarpUtils.init(); } - @Register(help = true) - public void genericHelp(Player p, String... args) { - p.sendMessage(BauSystem.PREFIX + "Jetziges TPS limit: " + TPSLimitUtils.currentTPSLimit); - p.sendMessage(ColorConfig.OTHER + "/" + ColorConfig.HIGHLIGHT + "tpslimit " + ColorConfig.OTHER + "[" + ColorConfig.BASE + "TPS" + ColorConfig.OTHER + "|" + ColorConfig.HIGHLIGHT + "default" + ColorConfig.OTHER + "] - " + ColorConfig.BASE + "Setzte die TPS auf dem Bau"); + @Register + public void checkCommand(Player p) { + if (!permissionCheck(p)) return; + BauSystem.MESSAGE.send("TPSLIMIT_CURRENT", p, TPSLimitUtils.currentTPSLimit); } @Register({"default"}) public void defaultCommand(Player p) { if (!permissionCheck(p)) return; - TPSLimitUtils.currentTPSLimit = 20; - TPSLimitUtils.tpsLimiter(); - sendNewTPSLimitMessage(); + valueCommand(p, 20D); } @Register @@ -81,7 +78,7 @@ public class TPSLimitCommand extends SWCommand implements Enable { FreezeUtils.freeze(p.getWorld()); TPSLimitUtils.currentTPSLimit = 20; TPSLimitUtils.tpsLimiter(); - sendNewTPSLimitMessage(); + sendNewTPSLimitMessage(true); return; } if (tpsLimitDouble < 0.5 || tpsLimitDouble > (TPSWarpUtils.isWarpAllowed() ? 60 : 20)) { @@ -91,7 +88,7 @@ public class TPSLimitCommand extends SWCommand implements Enable { FreezeUtils.unfreeze(p.getWorld()); TPSLimitUtils.currentTPSLimit = tpsLimitDouble; TPSLimitUtils.tpsLimiter(); - sendNewTPSLimitMessage(); + sendNewTPSLimitMessage(false); } @ClassMapper(value = double.class, local = true) @@ -109,17 +106,23 @@ public class TPSLimitCommand extends SWCommand implements Enable { @SuppressWarnings("BooleanMethodIsAlwaysInverted") private boolean permissionCheck(Player player) { if (!Permission.hasPermission(player, Permission.WORLD)) { - player.sendMessage(BauSystem.PREFIX + ColorConfig.DISABLE + "Du darfst hier nicht den TPS-Limiter nutzen"); + BauSystem.MESSAGE.send("TPSLIMIT_NO_PERMS", player); return false; } return true; } - private void sendNewTPSLimitMessage() { - Bukkit.getOnlinePlayers().forEach(p -> p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ColorConfig.HIGHLIGHT + "TPS limit auf " + TPSLimitUtils.currentTPSLimit + " gesetzt."))); + private void sendNewTPSLimitMessage(boolean frozen) { + Bukkit.getOnlinePlayers().forEach(player -> { + if (frozen) { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_FROZEN", player)); + } else { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TPSLIMIT_SET", player, TPSLimitUtils.currentTPSLimit)); + } + }); } private void sendInvalidArgumentMessage(Player player) { - player.sendMessage(BauSystem.PREFIX + ColorConfig.DISABLE + "Nur Zahlen zwischen 0,5 und " + (TPSWarpUtils.isWarpAllowed() ? 60 : 20) + ", und 'default'" + (FreezeUtils.freezeEnabled ? " und '0'" : "") + " erlaubt."); + BauSystem.MESSAGE.send("TPSLIMIT_INVALID", player, TPSWarpUtils.isWarpAllowed() ? 60 : 20, FreezeUtils.freezeEnabled ? BauSystem.MESSAGE.parse("TPSLIMIT_INVALID_FROZEN", player) : ""); } } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java index 0ea3903f..7a2e3a0e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSUtils.java @@ -34,5 +34,4 @@ public class TPSUtils { static { Bukkit.getScheduler().runTaskTimer(BauSystem.getInstance(), () -> ticksSinceServerStart++, 1, 1); } - } \ No newline at end of file diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java index 14a1012c..556ef5e3 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java @@ -20,9 +20,11 @@ package de.steamwar.bausystem.features.tpslimit; import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.SWUtils; import de.steamwar.bausystem.linkage.LinkageType; import de.steamwar.bausystem.linkage.Linked; import de.steamwar.command.SWCommand; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -48,7 +50,7 @@ public class TickCommand extends SWCommand { return; } - if (ticksLeft.getAndDecrement() < 0) { + if (ticksLeft.getAndDecrement() <= 0) { disableTask.run(); disableTask = null; ticksLeft = null; @@ -57,16 +59,19 @@ public class TickCommand extends SWCommand { }.runTaskTimer(BauSystem.getInstance(), 0L, 1L); } - @Register({"step"}) + @Register(value = {"step"}, description = "TICK_STEP_SINGLE_HELP") public void stepCommand(Player p) { stepCommand(p, 1); } - @Register({"step"}) - public void stepCommand(Player p, @OptionalValue("1") int ticks) { + @Register(value = {"step"}, description = "TICK_STEP_HELP") + public void stepCommand(Player p, @OptionalValue("1") int ticks) { // TODO: Fix OptionalValue if (ticksLeft != null) { return; } + Bukkit.getOnlinePlayers().forEach(player -> { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TICK_STEP", player, ticks)); + }); FreezeUtils.unfreeze(p.getWorld()); ticksLeft = new AtomicInteger(ticks); disableTask = () -> { @@ -74,11 +79,14 @@ public class TickCommand extends SWCommand { }; } - @Register({"warp"}) + @Register(value = {"warp"}, description = "TICK_WARP_HELP") public void warpCommand(Player p, int ticks) { if (ticksLeft != null) { return; } + Bukkit.getOnlinePlayers().forEach(player -> { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TICK_WARP", player, ticks)); + }); boolean frozen = FreezeUtils.frozen(p.getWorld()); double currentTPSLimit = TPSLimitUtils.currentTPSLimit; TPSLimitUtils.currentTPSLimit = 120; From 5e774ad874cec46be7b4765a2095df55363331e0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Dec 2021 21:03:05 +0100 Subject: [PATCH 32/36] Update messages Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 1 + .../features/tpslimit/FreezeUtils.java | 26 +++++++++---------- .../features/tpslimit/TPSLimitCommand.java | 4 +-- .../features/tpslimit/TickCommand.java | 14 +++++----- .../features/world/BauScoreboard.java | 7 ++++- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index f5415457..ee3a1402 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -40,6 +40,7 @@ SCOREBOARD_REGION = Region SCOREBOARD_TRACE = Trace SCOREBOARD_LOADER = Loader SCOREBOARD_TPS = TPS +SCOREBOARD_TPS_FROZEN = §e Eingefroren SCOREBOARD_TRACE_TICKS = Ticks diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java index 75703f76..e0d5804d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/FreezeUtils.java @@ -19,8 +19,10 @@ package de.steamwar.bausystem.features.tpslimit; +import lombok.Getter; import lombok.experimental.UtilityClass; import net.minecraft.server.v1_15_R1.WorldServer; +import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; import yapion.utils.ReflectionsUtils; @@ -33,37 +35,35 @@ public class FreezeUtils { private static final Field field; public static final boolean freezeEnabled; + @Getter + private static boolean frozen = false; + + private static final World world; + static { field = ReflectionsUtils.getField(WorldServer.class, "freezed"); if (field != null) field.setAccessible(true); freezeEnabled = field != null; + world = Bukkit.getWorlds().get(0); } - public static void freeze(World world) { + public static void freeze() { setFreeze(world, true); } - public static void unfreeze(World world) { + public static void unfreeze() { setFreeze(world, false); } - public static boolean frozen(World world) { - if (freezeEnabled) { - try { - return (boolean) field.get(((CraftWorld) world).getHandle()); - } catch (IllegalAccessException e) { - // Ignored; - } - } - return false; + public static boolean frozen() { + return freezeEnabled && frozen; } private void setFreeze(World world, boolean state) { if (freezeEnabled) { try { - System.out.println(state + " " + frozen(world)); field.set(((CraftWorld) world).getHandle(), state); - System.out.println(state + " " + frozen(world)); + frozen = state; } catch (IllegalAccessException e) { // Ignored; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java index 042ba479..a5a849e1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java @@ -75,7 +75,7 @@ public class TPSLimitCommand extends SWCommand implements Enable { public void valueCommand(Player p, /*@DoubleRange(min = 0.5, max = 60)*/ double tpsLimitDouble) { if (!permissionCheck(p)) return; if (FreezeUtils.freezeEnabled && tpsLimitDouble == 0) { - FreezeUtils.freeze(p.getWorld()); + FreezeUtils.freeze(); TPSLimitUtils.currentTPSLimit = 20; TPSLimitUtils.tpsLimiter(); sendNewTPSLimitMessage(true); @@ -85,7 +85,7 @@ public class TPSLimitCommand extends SWCommand implements Enable { sendInvalidArgumentMessage(p); return; } - FreezeUtils.unfreeze(p.getWorld()); + FreezeUtils.unfreeze(); TPSLimitUtils.currentTPSLimit = tpsLimitDouble; TPSLimitUtils.tpsLimiter(); sendNewTPSLimitMessage(false); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java index 556ef5e3..b7dff9a1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java @@ -72,11 +72,9 @@ public class TickCommand extends SWCommand { Bukkit.getOnlinePlayers().forEach(player -> { SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TICK_STEP", player, ticks)); }); - FreezeUtils.unfreeze(p.getWorld()); + FreezeUtils.unfreeze(); ticksLeft = new AtomicInteger(ticks); - disableTask = () -> { - FreezeUtils.freeze(p.getWorld()); - }; + disableTask = FreezeUtils::freeze; } @Register(value = {"warp"}, description = "TICK_WARP_HELP") @@ -87,16 +85,16 @@ public class TickCommand extends SWCommand { Bukkit.getOnlinePlayers().forEach(player -> { SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TICK_WARP", player, ticks)); }); - boolean frozen = FreezeUtils.frozen(p.getWorld()); + boolean frozen = FreezeUtils.frozen(); double currentTPSLimit = TPSLimitUtils.currentTPSLimit; - TPSLimitUtils.currentTPSLimit = 120; + TPSLimitUtils.currentTPSLimit = 240; TPSLimitUtils.tpsLimiter(); - FreezeUtils.unfreeze(p.getWorld()); + FreezeUtils.unfreeze(); ticksLeft = new AtomicInteger(ticks); disableTask = () -> { if (frozen) { - FreezeUtils.freeze(p.getWorld()); + FreezeUtils.freeze(); } TPSLimitUtils.currentTPSLimit = currentTPSLimit; TPSLimitUtils.tpsLimiter(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java index 17865922..eb3144d2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/world/BauScoreboard.java @@ -2,6 +2,7 @@ package de.steamwar.bausystem.features.world; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.features.loader.Loader; +import de.steamwar.bausystem.features.tpslimit.FreezeUtils; import de.steamwar.bausystem.features.tpslimit.TPSLimitUtils; import de.steamwar.bausystem.features.tpslimit.TPSUtils; import de.steamwar.bausystem.features.tpslimit.TPSWarpUtils; @@ -85,7 +86,11 @@ public class BauScoreboard implements Listener { strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_LOADER", p) + "§8: " + BauSystem.MESSAGE.parse(loader != null ? loader.getStage().getChatValue() : "LOADER_OFF", p)); strings.add("§5"); - strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8 " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); + if (FreezeUtils.frozen()) { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + BauSystem.MESSAGE.parse("SCOREBOARD_TPS_FROZEN", p)); + } else { + strings.add(colorCode + BauSystem.MESSAGE.parse("SCOREBOARD_TPS", p) + "§8 " + tpsColor() + TPSWarpUtils.getTps(TPSWatcher.TPSType.ONE_SECOND) + tpsLimit()); + } int i = strings.size(); HashMap result = new HashMap<>(); From c8c4ef694e05404042f01a8bd8f369d5fca38fcb Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Dec 2021 21:21:30 +0100 Subject: [PATCH 33/36] Fix permissions for TickCommand Signed-off-by: yoyosource --- .../steamwar/bausystem/features/tpslimit/TPSLimitCommand.java | 2 +- .../de/steamwar/bausystem/features/tpslimit/TickCommand.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java index a5a849e1..7950e401 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TPSLimitCommand.java @@ -104,7 +104,7 @@ public class TPSLimitCommand extends SWCommand implements Enable { } @SuppressWarnings("BooleanMethodIsAlwaysInverted") - private boolean permissionCheck(Player player) { + protected static boolean permissionCheck(Player player) { if (!Permission.hasPermission(player, Permission.WORLD)) { BauSystem.MESSAGE.send("TPSLIMIT_NO_PERMS", player); return false; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java index b7dff9a1..ffd34cda 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java @@ -66,6 +66,7 @@ public class TickCommand extends SWCommand { @Register(value = {"step"}, description = "TICK_STEP_HELP") public void stepCommand(Player p, @OptionalValue("1") int ticks) { // TODO: Fix OptionalValue + if (!TPSLimitCommand.permissionCheck(p)) return; if (ticksLeft != null) { return; } @@ -79,6 +80,7 @@ public class TickCommand extends SWCommand { @Register(value = {"warp"}, description = "TICK_WARP_HELP") public void warpCommand(Player p, int ticks) { + if (!TPSLimitCommand.permissionCheck(p)) return; if (ticksLeft != null) { return; } From 0f24ae298a92a2a93f051f5f0668adbb9f6cf7f8 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 13 Dec 2021 22:37:11 +0100 Subject: [PATCH 34/36] Fix prototypes3.yapion Signed-off-by: yoyosource --- yapion/prototypes3.yapion | 2 ++ 1 file changed, 2 insertions(+) diff --git a/yapion/prototypes3.yapion b/yapion/prototypes3.yapion index 38c4ecb2..37bf6f2d 100644 --- a/yapion/prototypes3.yapion +++ b/yapion/prototypes3.yapion @@ -21,6 +21,7 @@ sizeX(63) sizeY(256) sizeZ(120) + floorOffset(45) testblock{ offsetX(13) offsetY(44) @@ -37,6 +38,7 @@ sizeX(133) sizeY(255) sizeZ(214) + floorOffset(45) testblock{ offsetX(33) offsetY(44) From f3a6319e4a6d1eb0dd34e29ed336f8b001c64425 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 14 Dec 2021 19:49:31 +0100 Subject: [PATCH 35/36] Fix BlockCounterListener Signed-off-by: yoyosource --- .../features/testblock/blockcounter/BlockCounterListener.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java index d4ab3412..f910f935 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/testblock/blockcounter/BlockCounterListener.java @@ -38,6 +38,9 @@ public class BlockCounterListener implements Listener { @EventHandler public void onEntityExplode(EntityExplodeEvent event) { Region region = Region.getRegion(event.getLocation()); + if (region.isGlobal()) { + return; + } List blockList = event.blockList(); blockList = blockList.stream().filter(block -> region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)).collect(Collectors.toList()); if (blockList.isEmpty()) { From b3d0dd0f96879d073777e97b547f11f8e99e7915 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 15 Dec 2021 15:21:32 +0100 Subject: [PATCH 36/36] Update TickCommand Signed-off-by: yoyosource --- BauSystem_Main/src/BauSystem.properties | 6 +++ .../features/tpslimit/TickCommand.java | 39 +++++++++++++++---- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/BauSystem.properties b/BauSystem_Main/src/BauSystem.properties index ee3a1402..5d654d65 100644 --- a/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem_Main/src/BauSystem.properties @@ -523,8 +523,14 @@ BLOCK_COUNTER_DISABLE = §7BlockCounter ausgemacht TICK_STEP_HELP = §8/§etick step §8<§7Ticks§8> §8- §7Spule n Ticks vor TICK_STEP_SINGLE_HELP = §8/§etick step §8- §7Spule einen Ticks vor TICK_WARP_HELP = §8/§etick warp §8<§7Ticks§8> §8- §7Warpe n Ticks vor +TICK_CANCEL_HELP = §8/§etick cancel §8- §7Cancelt den Tick Warp oder Step +TICK_ERROR = §cDu kannst keinen weiteren §8'§e/tick step§8'§c oder §8'§e/tick warp§8'§c anmachen +TICK_CANCEL_ERROR = §cDu hast keinen §8'§e/tick step§8'§c oder §8'§e/tick warp§8'§c aktiv TICK_STEP = §eSpult {0} Ticks vor +TICK_STEP_LEFT = §eSpult noch {0} Ticks vor TICK_WARP = §eWarpe {0} Ticks vor +TICK_WARP_LEFT = §eWarpe noch {0} Ticks vor +TICK_CANCEL = §eWarps und Steps abgebrochen TPSLIMIT_GUI_ITEM_NAME = §eTPS Limiter TPSLIMIT_GUI_ITEM_LORE = §7Aktuell: §e{0} TPSLIMIT_ANVIL_GUI = Neues TPS Limit diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java index ffd34cda..8e4b7c86 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/tpslimit/TickCommand.java @@ -29,12 +29,14 @@ import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; @Linked(LinkageType.COMMAND) public class TickCommand extends SWCommand { private AtomicInteger ticksLeft = null; private Runnable disableTask = null; + private Consumer ticksLeftActionBar = null; public TickCommand() { super("tick"); @@ -55,19 +57,18 @@ public class TickCommand extends SWCommand { disableTask = null; ticksLeft = null; } + if (ticksLeftActionBar != null && ticksLeft != null) { + ticksLeftActionBar.accept(ticksLeft.get()); + } } }.runTaskTimer(BauSystem.getInstance(), 0L, 1L); } - @Register(value = {"step"}, description = "TICK_STEP_SINGLE_HELP") - public void stepCommand(Player p) { - stepCommand(p, 1); - } - - @Register(value = {"step"}, description = "TICK_STEP_HELP") - public void stepCommand(Player p, @OptionalValue("1") int ticks) { // TODO: Fix OptionalValue + @Register(value = {"step"}, description = {"TICK_STEP_SINGLE_HELP", "TICK_STEP_HELP"}) + public void stepCommand(Player p, @OptionalValue("1") int ticks) { if (!TPSLimitCommand.permissionCheck(p)) return; if (ticksLeft != null) { + BauSystem.MESSAGE.send("TICK_ERROR", p); return; } Bukkit.getOnlinePlayers().forEach(player -> { @@ -76,12 +77,18 @@ public class TickCommand extends SWCommand { FreezeUtils.unfreeze(); ticksLeft = new AtomicInteger(ticks); disableTask = FreezeUtils::freeze; + ticksLeftActionBar = currentTicksLeft -> { + Bukkit.getOnlinePlayers().forEach(player -> { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TICK_STEP_LEFT", player, currentTicksLeft)); + }); + }; } @Register(value = {"warp"}, description = "TICK_WARP_HELP") public void warpCommand(Player p, int ticks) { if (!TPSLimitCommand.permissionCheck(p)) return; if (ticksLeft != null) { + BauSystem.MESSAGE.send("TICK_ERROR", p); return; } Bukkit.getOnlinePlayers().forEach(player -> { @@ -101,5 +108,23 @@ public class TickCommand extends SWCommand { TPSLimitUtils.currentTPSLimit = currentTPSLimit; TPSLimitUtils.tpsLimiter(); }; + ticksLeftActionBar = currentTicksLeft -> { + Bukkit.getOnlinePlayers().forEach(player -> { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TICK_WARP_LEFT", player, currentTicksLeft)); + }); + }; + } + + @Register(value = {"cancel"}, description = "TICK_CANCEL_HELP") + public void cancelCommand(Player p) { + if (!TPSLimitCommand.permissionCheck(p)) return; + if (ticksLeft == null) { + BauSystem.MESSAGE.send("TICK_CANCEL_ERROR", p); + return; + } + ticksLeft.set(0); + Bukkit.getOnlinePlayers().forEach(player -> { + SWUtils.sendToActionbar(player, BauSystem.MESSAGE.parse("TICK_CANCEL", player)); + }); } }