SteamWar/BauSystem2.0
Archiviert
12
0

Fix show and hide of TNTSimulator
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-09-09 16:15:53 +02:00
Ursprung 8a3cce0a3a
Commit 63e8b96ec9

Datei anzeigen

@ -45,12 +45,13 @@ import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;
@Linked
public class TNTSimulatorListener implements Listener {
private Map<Player, TNTSimulator> currentSimulator = new HashMap<>();
private Map<Player, Pair<TNTSimulator, Boolean>> currentSimulator = new HashMap<>();
private boolean permissionCheck(Player player) {
if (!Permission.hasPermission(player, Permission.WORLD)) {
@ -88,10 +89,10 @@ public class TNTSimulatorListener implements Listener {
{
BiFunction<Player, Object, Object> positionSetter = (player, o) -> {
if (player.getGameMode() == GameMode.SPECTATOR) return o;
TNTSimulator tntSimulator = currentSimulator.get(player);
Pair<TNTSimulator, Boolean> tntSimulator = currentSimulator.get(player);
if (tntSimulator == null) return o;
if (!tntSimulator.hasPreview(player)) return o;
if (!tntSimulator.getPreviewRecord().isAir(x.get(o), y.get(o), z.get(o))) return o;
if (!tntSimulator.getKey().hasPreview(player)) return o;
if (!tntSimulator.getKey().getPreviewRecord().isAir(x.get(o), y.get(o), z.get(o))) return o;
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
PlayerMovementWrapper.impl.setPosition(player, o);
}, 0L);
@ -103,15 +104,27 @@ public class TNTSimulatorListener implements Listener {
}
private void hideShow(Player player, Pair<TNTSimulator, Boolean> simulatorPair) {
Pair<TNTSimulator, Boolean> tntSimulatorPair = currentSimulator.get(player);
TNTSimulator tntSimulator = tntSimulatorPair == null ? null : tntSimulatorPair.getKey();
TNTSimulator simulator = simulatorPair.getKey();
TNTSimulator tntSimulator = currentSimulator.remove(player);
if (tntSimulator == simulator) return;
if (tntSimulator != null) tntSimulator.hide(player);
if (Objects.equals(simulatorPair, tntSimulatorPair)) {
if (simulatorPair.getKey() != null) {
SimulatorCursor.show(player, simulator, trace(player, player.getLocation(), simulator));
}
return;
}
if (tntSimulator != null) {
tntSimulator.hide(player);
currentSimulator.remove(player);
}
if (simulator == null) {
SimulatorCursor.hide(player);
return;
}
currentSimulator.put(player, simulator);
currentSimulator.put(player, simulatorPair);
simulator.show(player);
SimulatorCursor.show(player, simulator, trace(player, player.getLocation(), simulator));
if (simulatorPair.getValue()) {
@ -196,7 +209,7 @@ public class TNTSimulatorListener implements Listener {
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
currentSimulator.values().forEach(simulator -> {
simulator.calcPreview(false, event.getBlock().getLocation().toVector());
simulator.getKey().calcPreview(false, event.getBlock().getLocation().toVector());
});
}
@ -204,7 +217,7 @@ public class TNTSimulatorListener implements Listener {
public void onBlockBreak(BlockBreakEvent event) {
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
currentSimulator.values().forEach(simulator -> {
simulator.calcPreview(false, event.getBlock().getLocation().toVector());
simulator.getKey().calcPreview(false, event.getBlock().getLocation().toVector());
});
}, 0);
}