From e1fa8aaefa475bd69aef3beb2b7ac6491576f33e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 5 Oct 2025 11:42:44 +0200 Subject: [PATCH] Add enable/disable functionality for Piston Calculator and update help messages --- .../BauSystem_Main/src/BauSystem.properties | 4 ++- .../src/BauSystem_de.properties | 4 ++- .../features/util/PistonCalculator.java | 13 +++++---- .../util/PistonCalculatorCommand.java | 28 ++++++++++++++++--- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/BauSystem/BauSystem_Main/src/BauSystem.properties b/BauSystem/BauSystem_Main/src/BauSystem.properties index 34681d0d..eabd9de6 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem.properties @@ -980,10 +980,12 @@ SELECT_ITEM_BAUPLATTFORM=§eBuild platform SELECT_ITEM_TESTBLOCK=§eDummy CHESTFILLER_FILLED=§eChest filled CHESTFILLER_COUNT=§7{0}§8: §e§l{1} -PISTON_HELP_1=§7Right click on piston with a slime ball to calculate the moved blocks. +PISTON_HELP_1=§7Right click on piston to calculate the moved blocks. PISTON_HELP_2=§7Count is red, if one unmoveable block is present. PISTON_HELP_3=§7Count is yellow, if too many blocks are present. PISTON_INFO=§7Moved Blocks {0}{1}§8/§712 +PISTON_ENABLED=§aCalculator enabled +PISTON_DISABLED=§cCalculator disabled # Warp WARP_LOC_X=§7X§8: §e{0} WARP_LOC_Y=§7Y§8: §e{0} diff --git a/BauSystem/BauSystem_Main/src/BauSystem_de.properties b/BauSystem/BauSystem_Main/src/BauSystem_de.properties index c5c5ca0a..042d1388 100644 --- a/BauSystem/BauSystem_Main/src/BauSystem_de.properties +++ b/BauSystem/BauSystem_Main/src/BauSystem_de.properties @@ -912,10 +912,12 @@ SELECT_ITEM_BAURAHMEN=§eBaurahmen SELECT_ITEM_BAUPLATTFORM=§eBauplattform SELECT_ITEM_TESTBLOCK=§eTestblock CHESTFILLER_FILLED=§eKiste gefüllt -PISTON_HELP_1=§7Rechts Klick auf Piston mit einem Slime Ball berechnet dir die bewegten Blöcke. +PISTON_HELP_1=§7Rechts Klick auf einen Piston berechnet dir die bewegten Blöcke. PISTON_HELP_2=§7Die Anzahl ist Rot, wenn ein unmovable Block vorhanden ist. PISTON_HELP_3=§7Die Anzahl ist Gelb, wenn zu viele Blöcke vorhanden sind. PISTON_INFO=§7Bewegte Blöcke {0}{1}§8/§712 +PISTON_ENABLED=§aPiston-Berechnung aktiviert +PISTON_DISABLED=§cPiston-Berechnung deaktiviert # Warp WARP_LOC_X=§7X§8: §e{0} WARP_LOC_Y=§7Y§8: §e{0} diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java index b5ba6a00..2b179f14 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculator.java @@ -49,7 +49,8 @@ import java.util.stream.Collectors; @MinVersion(20) public class PistonCalculator implements Listener { - private final Map DEBOUNCE = new HashMap<>(); + private final Map debounce = new HashMap<>(); + protected final Set disablePistonCalculator = new HashSet<>(); @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { @@ -58,15 +59,16 @@ public class PistonCalculator implements Listener { if (event.getItem() == null) { } else if (event.getItem() != null && event.getItem().getType() == Material.SLIME_BALL) { } else if (!event.getItem().getType().isBlock()) { - DEBOUNCE.put(event.getPlayer(), System.currentTimeMillis()); + debounce.put(event.getPlayer(), System.currentTimeMillis()); return; } else return; if (event.getClickedBlock() == null) return; Block clickedBlock = event.getClickedBlock(); Material blockType = clickedBlock.getType(); if (!(blockType == Material.PISTON || blockType == Material.STICKY_PISTON)) return; - if (System.currentTimeMillis() - DEBOUNCE.getOrDefault(event.getPlayer(), 0L) <= 200) return; - DEBOUNCE.put(event.getPlayer(), System.currentTimeMillis()); + if (disablePistonCalculator.contains(event.getPlayer())) return; + if (System.currentTimeMillis() - debounce.getOrDefault(event.getPlayer(), 0L) <= 200) return; + debounce.put(event.getPlayer(), System.currentTimeMillis()); Location location = event.getClickedBlock().getLocation(); if (pistOrders.containsKey(location)) { @@ -143,7 +145,8 @@ public class PistonCalculator implements Listener { @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { - DEBOUNCE.remove(event.getPlayer()); + debounce.remove(event.getPlayer()); + disablePistonCalculator.remove(event.getPlayer()); Set toRemove = new HashSet<>(); pistOrders.forEach((location, pistOrder) -> { diff --git a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java index 510c6050..bf387dd5 100644 --- a/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java +++ b/BauSystem/BauSystem_Main/src/de/steamwar/bausystem/features/util/PistonCalculatorCommand.java @@ -22,21 +22,41 @@ package de.steamwar.bausystem.features.util; import de.steamwar.bausystem.BauSystem; import de.steamwar.command.SWCommand; import de.steamwar.linkage.Linked; +import de.steamwar.linkage.LinkedInstance; import de.steamwar.linkage.MinVersion; import org.bukkit.entity.Player; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + @Linked @MinVersion(20) public class PistonCalculatorCommand extends SWCommand { + @LinkedInstance + public PistonCalculator pistonCalculator; + + private final Set helpMessageShowed = new HashSet<>(); + public PistonCalculatorCommand() { super("piston", "pistoncalculator", "pistoncalc"); } @Register - public void help(@Validator Player player) { - BauSystem.MESSAGE.send("PISTON_HELP_1", player); - BauSystem.MESSAGE.send("PISTON_HELP_2", player); - BauSystem.MESSAGE.send("PISTON_HELP_3", player); + public void genericCommand(@Validator Player player) { + if (pistonCalculator.disablePistonCalculator.contains(player)) { + pistonCalculator.disablePistonCalculator.remove(player); + if (!helpMessageShowed.contains(player.getUniqueId())) { + BauSystem.MESSAGE.send("PISTON_HELP_1", player); + BauSystem.MESSAGE.send("PISTON_HELP_2", player); + BauSystem.MESSAGE.send("PISTON_HELP_3", player); + helpMessageShowed.add(player.getUniqueId()); + } + BauSystem.MESSAGE.send("PISTON_ENABLED", player); + } else { + pistonCalculator.disablePistonCalculator.add(player); + BauSystem.MESSAGE.send("PISTON_DISABLED", player); + } } }