forked from SteamWar/SteamWar
Add enable/disable functionality for Piston Calculator and update help messages
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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}
|
||||
|
||||
+8
-5
@@ -49,7 +49,8 @@ import java.util.stream.Collectors;
|
||||
@MinVersion(20)
|
||||
public class PistonCalculator implements Listener {
|
||||
|
||||
private final Map<Player, Long> DEBOUNCE = new HashMap<>();
|
||||
private final Map<Player, Long> debounce = new HashMap<>();
|
||||
protected final Set<Player> 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<Location> toRemove = new HashSet<>();
|
||||
pistOrders.forEach((location, pistOrder) -> {
|
||||
|
||||
+24
-4
@@ -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<UUID> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user