Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
8a3cce0a3a
Commit
63e8b96ec9
@ -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);
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren