forked from SteamWar/SteamWar
Merge pull request 'Add enable/disable/clear functionality for Piston Calculator' (#160) from BauSystem/piston-calculator-enable into main
Reviewed-on: SteamWar/SteamWar#160 Reviewed-by: YoyoNow <yoyonow@noreply.localhost>
This commit is contained in:
@@ -980,10 +980,12 @@ SELECT_ITEM_BAUPLATTFORM=§eBuild platform
|
|||||||
SELECT_ITEM_TESTBLOCK=§eDummy
|
SELECT_ITEM_TESTBLOCK=§eDummy
|
||||||
CHESTFILLER_FILLED=§eChest filled
|
CHESTFILLER_FILLED=§eChest filled
|
||||||
CHESTFILLER_COUNT=§7{0}§8: §e§l{1}
|
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_2=§7Count is red, if one unmoveable block is present.
|
||||||
PISTON_HELP_3=§7Count is yellow, if too many blocks are present.
|
PISTON_HELP_3=§7Count is yellow, if too many blocks are present.
|
||||||
PISTON_INFO=§7Moved Blocks {0}{1}§8/§712
|
PISTON_INFO=§7Moved Blocks {0}{1}§8/§712
|
||||||
|
PISTON_ENABLED=§aCalculator enabled
|
||||||
|
PISTON_DISABLED=§cCalculator disabled
|
||||||
# Warp
|
# Warp
|
||||||
WARP_LOC_X=§7X§8: §e{0}
|
WARP_LOC_X=§7X§8: §e{0}
|
||||||
WARP_LOC_Y=§7Y§8: §e{0}
|
WARP_LOC_Y=§7Y§8: §e{0}
|
||||||
|
|||||||
@@ -912,10 +912,12 @@ SELECT_ITEM_BAURAHMEN=§eBaurahmen
|
|||||||
SELECT_ITEM_BAUPLATTFORM=§eBauplattform
|
SELECT_ITEM_BAUPLATTFORM=§eBauplattform
|
||||||
SELECT_ITEM_TESTBLOCK=§eTestblock
|
SELECT_ITEM_TESTBLOCK=§eTestblock
|
||||||
CHESTFILLER_FILLED=§eKiste gefüllt
|
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_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_HELP_3=§7Die Anzahl ist Gelb, wenn zu viele Blöcke vorhanden sind.
|
||||||
PISTON_INFO=§7Bewegte Blöcke {0}{1}§8/§712
|
PISTON_INFO=§7Bewegte Blöcke {0}{1}§8/§712
|
||||||
|
PISTON_ENABLED=§aPiston-Berechnung aktiviert
|
||||||
|
PISTON_DISABLED=§cPiston-Berechnung deaktiviert
|
||||||
# Warp
|
# Warp
|
||||||
WARP_LOC_X=§7X§8: §e{0}
|
WARP_LOC_X=§7X§8: §e{0}
|
||||||
WARP_LOC_Y=§7Y§8: §e{0}
|
WARP_LOC_Y=§7Y§8: §e{0}
|
||||||
|
|||||||
+11
-6
@@ -49,7 +49,8 @@ import java.util.stream.Collectors;
|
|||||||
@MinVersion(20)
|
@MinVersion(20)
|
||||||
public class PistonCalculator implements Listener {
|
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
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
@@ -58,15 +59,16 @@ public class PistonCalculator implements Listener {
|
|||||||
if (event.getItem() == null) {
|
if (event.getItem() == null) {
|
||||||
} else if (event.getItem() != null && event.getItem().getType() == Material.SLIME_BALL) {
|
} else if (event.getItem() != null && event.getItem().getType() == Material.SLIME_BALL) {
|
||||||
} else if (!event.getItem().getType().isBlock()) {
|
} else if (!event.getItem().getType().isBlock()) {
|
||||||
DEBOUNCE.put(event.getPlayer(), System.currentTimeMillis());
|
debounce.put(event.getPlayer(), System.currentTimeMillis());
|
||||||
return;
|
return;
|
||||||
} else return;
|
} else return;
|
||||||
if (event.getClickedBlock() == null) return;
|
if (event.getClickedBlock() == null) return;
|
||||||
Block clickedBlock = event.getClickedBlock();
|
Block clickedBlock = event.getClickedBlock();
|
||||||
Material blockType = clickedBlock.getType();
|
Material blockType = clickedBlock.getType();
|
||||||
if (!(blockType == Material.PISTON || blockType == Material.STICKY_PISTON)) return;
|
if (!(blockType == Material.PISTON || blockType == Material.STICKY_PISTON)) return;
|
||||||
if (System.currentTimeMillis() - DEBOUNCE.getOrDefault(event.getPlayer(), 0L) <= 200) return;
|
if (disablePistonCalculator.contains(event.getPlayer())) return;
|
||||||
DEBOUNCE.put(event.getPlayer(), System.currentTimeMillis());
|
if (System.currentTimeMillis() - debounce.getOrDefault(event.getPlayer(), 0L) <= 200) return;
|
||||||
|
debounce.put(event.getPlayer(), System.currentTimeMillis());
|
||||||
|
|
||||||
Location location = event.getClickedBlock().getLocation();
|
Location location = event.getClickedBlock().getLocation();
|
||||||
if (pistOrders.containsKey(location)) {
|
if (pistOrders.containsKey(location)) {
|
||||||
@@ -143,11 +145,14 @@ public class PistonCalculator implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
DEBOUNCE.remove(event.getPlayer());
|
debounce.remove(event.getPlayer());
|
||||||
|
disablePistonCalculator.remove(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear(Player player) {
|
||||||
Set<Location> toRemove = new HashSet<>();
|
Set<Location> toRemove = new HashSet<>();
|
||||||
pistOrders.forEach((location, pistOrder) -> {
|
pistOrders.forEach((location, pistOrder) -> {
|
||||||
pistOrder.server.removePlayer(event.getPlayer());
|
pistOrder.server.removePlayer(player);
|
||||||
if (pistOrder.server.getPlayers().isEmpty()) {
|
if (pistOrder.server.getPlayers().isEmpty()) {
|
||||||
toRemove.add(location);
|
toRemove.add(location);
|
||||||
pistOrder.server.close();
|
pistOrder.server.close();
|
||||||
|
|||||||
+29
-4
@@ -22,21 +22,46 @@ package de.steamwar.bausystem.features.util;
|
|||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.command.SWCommand;
|
import de.steamwar.command.SWCommand;
|
||||||
import de.steamwar.linkage.Linked;
|
import de.steamwar.linkage.Linked;
|
||||||
|
import de.steamwar.linkage.LinkedInstance;
|
||||||
import de.steamwar.linkage.MinVersion;
|
import de.steamwar.linkage.MinVersion;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Linked
|
@Linked
|
||||||
@MinVersion(20)
|
@MinVersion(20)
|
||||||
public class PistonCalculatorCommand extends SWCommand {
|
public class PistonCalculatorCommand extends SWCommand {
|
||||||
|
|
||||||
|
@LinkedInstance
|
||||||
|
public PistonCalculator pistonCalculator;
|
||||||
|
|
||||||
|
private final Set<UUID> helpMessageShowed = new HashSet<>();
|
||||||
|
|
||||||
public PistonCalculatorCommand() {
|
public PistonCalculatorCommand() {
|
||||||
super("piston", "pistoncalculator", "pistoncalc");
|
super("piston", "pistoncalculator", "pistoncalc");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register
|
@Register
|
||||||
public void help(@Validator Player player) {
|
public void genericCommand(@Validator Player player) {
|
||||||
BauSystem.MESSAGE.send("PISTON_HELP_1", player);
|
if (pistonCalculator.disablePistonCalculator.contains(player)) {
|
||||||
BauSystem.MESSAGE.send("PISTON_HELP_2", player);
|
pistonCalculator.disablePistonCalculator.remove(player);
|
||||||
BauSystem.MESSAGE.send("PISTON_HELP_3", 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("clear")
|
||||||
|
public void clearCommand(@Validator Player player) {
|
||||||
|
pistonCalculator.clear(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user