SteamWar/BauSystem2.0
Archiviert
12
0

Fix AxisMovementLimiter
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-09-01 16:26:07 +02:00
Ursprung 02c68a8b0b
Commit 6409748d32
3 geänderte Dateien mit 58 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -81,7 +81,7 @@ public class AxisMovementLimiter {
}
break;
}
System.out.println(axis + " " + minX + " -> " + maxX + " " + minY + " -> " + maxY + " " + minZ + " -> " + maxZ);
// System.out.println(axis + " " + minX + " -> " + maxX + " " + minY + " -> " + maxY + " " + minZ + " -> " + maxZ);
}
private List<Pos> possibleCollisions() {
@ -160,14 +160,16 @@ public class AxisMovementLimiter {
if (collision == null) {
return movement;
} else {
System.out.println(axis + " " + movement + " " + collision);
switch (axis) {
case X:
return x - collision;
// System.out.println(axis + " " + movement + " " + x + " " + collision);
return collision - x;
case Y:
return y - collision;
// System.out.println(axis + " " + movement + " " + y + " " + collision);
return collision - y;
case Z:
return z - collision;
// System.out.println(axis + " " + movement + " " + z + " " + collision);
return collision - z;
default:
throw new IllegalStateException("Unexpected value: " + axis);
}

Datei anzeigen

@ -67,7 +67,7 @@ public class SimulatorCursor {
return;
}
if (SimulatorStorage.getSimulator(player.getInventory().getItemInOffHand()) != null && result.getHitPosition().distanceSquared(player.getLocation().toVector()) < 25) {
if (SimulatorStorage.getSimulator(player.getInventory().getItemInOffHand()) != null && result.getHitPosition().distanceSquared(player.getLocation().toVector()) < 16) {
return;
}

Datei anzeigen

@ -44,6 +44,9 @@ import java.util.function.Function;
@Linked
public class TNTSimulatorListener implements Listener {
private Map<Player, PreviewRecord> previewRecordMap = new HashMap<>();
private Map<Player, TNTSimulator> currentSimulator = new HashMap<>();
private boolean permissionCheck(Player player) {
if (!Permission.hasPermission(player, Permission.WORLD)) {
BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player);
@ -52,88 +55,82 @@ public class TNTSimulatorListener implements Listener {
return true;
}
private Pair<TNTSimulator, Boolean> getSimulator(Player player) {
if (ItemUtils.isItem(player.getInventory().getItemInOffHand(), "simulator")) {
return new Pair<>(SimulatorStorage.getSimulator(player.getInventory().getItemInOffHand()), true);
}
if (ItemUtils.isItem(player.getInventory().getItemInMainHand(), "simulator")) {
return new Pair<>(SimulatorStorage.getSimulator(player.getInventory().getItemInMainHand()), false);
}
return new Pair<>(null, false);
}
static RayTraceUtils.RRayTraceResult trace(Player player, Location to, TNTSimulator simulator) {
return RayTraceUtils.traceREntity(player, to, simulator.getEntities());
}
private void hideShow(Player player, TNTSimulator simulator) {
TNTSimulator tntSimulator = currentSimulator.remove(player);
if (tntSimulator == simulator) return;
if (tntSimulator != null) tntSimulator.hide(player);
if (simulator != null) {
simulator.show(player);
SimulatorCursor.show(player, simulator, trace(player, player.getLocation(), simulator));
}
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent e) {
if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) {
simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getTo());
} else {
SimulatorCursor.hide(e.getPlayer());
}
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
hideShow(e.getPlayer(), simulatorPair.getKey());
}
@EventHandler
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
simulatorShowHide(e.getPlayer(), i -> i.getItem(e.getPreviousSlot()), i -> i.getItem(e.getNewSlot()), e.getPlayer().getLocation());
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
hideShow(e.getPlayer(), simulatorPair.getKey());
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent e) {
simulatorShowHide(e.getPlayer(), i -> e.getItemDrop().getItemStack(), i -> null, e.getPlayer().getLocation());
}
private TNTSimulator simulatorShowHide(Player player, Function<PlayerInventory, ItemStack> oldItemFunction, Function<PlayerInventory, ItemStack> newItemFunction, Location location) {
TNTSimulator oldSimulator = SimulatorStorage.getSimulator(oldItemFunction.apply(player.getInventory()));
SimulatorCursor.hide(player, oldSimulator);
TNTSimulator simulator = SimulatorStorage.getSimulator(newItemFunction.apply(player.getInventory()));
if (simulator == null) return null;
SimulatorCursor.show(player, simulator, trace(player, location, simulator));
return simulator;
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
hideShow(e.getPlayer(), simulatorPair.getKey());
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent e) {
if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) {
simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getPlayer().getLocation());
}
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
hideShow(e.getPlayer(), simulatorPair.getKey());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
SimulatorCursor.hide(event.getPlayer(), null);
SimulatorStorage.getSimulatorNames().forEach(s -> {
SimulatorStorage.getSimulator(s)._hide(event.getPlayer());
});
PreviewRecord previewRecord = previewRecordMap.remove(event.getPlayer());
if (previewRecord != null) {
previewRecord.close(event.getPlayer());
public void onPlayerQuit(PlayerQuitEvent e) {
hideShow(e.getPlayer(), null);
}
}
private Map<Player, PreviewRecord> previewRecordMap = new HashMap<>();
@EventHandler
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
PreviewRecord current = previewRecordMap.remove(event.getPlayer());
if (current != null) {
current.close(event.getPlayer());
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent e) {
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
hideShow(e.getPlayer(), simulatorPair.getKey());
if (!simulatorPair.getValue()) return;
TNTSimulator simulator = SimulatorStorage.getSimulator(e.getOffHandItem());
if (preview(e.getPlayer(), simulator)) {
e.setCancelled(true);
}
}
if (!ItemUtils.isItem(event.getOffHandItem(), "simulator")) {
return;
}
if (ItemUtils.isItem(event.getMainHandItem(), "simulator")) {
return;
}
if (!permissionCheck(event.getPlayer())) {
return;
}
TNTSimulator simulator = SimulatorStorage.getSimulator(event.getOffHandItem());
if (simulator == null) return;
Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate = simulator.locations(event.getPlayer());
private boolean preview(Player player, TNTSimulator simulator) {
if (simulator == null) return false;
Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate = simulator.locations(player);
PreviewRecord previewRecord = Simulator.impl.run(toCalculate);
if (previewRecord == null) {
event.setCancelled(true);
return;
return true;
}
previewRecord.add(event.getPlayer());
previewRecordMap.put(event.getPlayer(), previewRecord);
previewRecord.add(player);
previewRecordMap.put(player, previewRecord);
return false;
}
@EventHandler