Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
Ursprung
02c68a8b0b
Commit
6409748d32
@ -81,7 +81,7 @@ public class AxisMovementLimiter {
|
|||||||
}
|
}
|
||||||
break;
|
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() {
|
private List<Pos> possibleCollisions() {
|
||||||
@ -160,14 +160,16 @@ public class AxisMovementLimiter {
|
|||||||
if (collision == null) {
|
if (collision == null) {
|
||||||
return movement;
|
return movement;
|
||||||
} else {
|
} else {
|
||||||
System.out.println(axis + " " + movement + " " + collision);
|
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
case X:
|
case X:
|
||||||
return x - collision;
|
// System.out.println(axis + " " + movement + " " + x + " " + collision);
|
||||||
|
return collision - x;
|
||||||
case Y:
|
case Y:
|
||||||
return y - collision;
|
// System.out.println(axis + " " + movement + " " + y + " " + collision);
|
||||||
|
return collision - y;
|
||||||
case Z:
|
case Z:
|
||||||
return z - collision;
|
// System.out.println(axis + " " + movement + " " + z + " " + collision);
|
||||||
|
return collision - z;
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("Unexpected value: " + axis);
|
throw new IllegalStateException("Unexpected value: " + axis);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public class SimulatorCursor {
|
|||||||
return;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,9 @@ import java.util.function.Function;
|
|||||||
@Linked
|
@Linked
|
||||||
public class TNTSimulatorListener implements Listener {
|
public class TNTSimulatorListener implements Listener {
|
||||||
|
|
||||||
|
private Map<Player, PreviewRecord> previewRecordMap = new HashMap<>();
|
||||||
|
private Map<Player, TNTSimulator> currentSimulator = new HashMap<>();
|
||||||
|
|
||||||
private boolean permissionCheck(Player player) {
|
private boolean permissionCheck(Player player) {
|
||||||
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
if (!Permission.hasPermission(player, Permission.WORLD)) {
|
||||||
BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player);
|
BauSystem.MESSAGE.send("SIMULATOR_NO_PERMS", player);
|
||||||
@ -52,88 +55,82 @@ public class TNTSimulatorListener implements Listener {
|
|||||||
return true;
|
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) {
|
static RayTraceUtils.RRayTraceResult trace(Player player, Location to, TNTSimulator simulator) {
|
||||||
return RayTraceUtils.traceREntity(player, to, simulator.getEntities());
|
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
|
@EventHandler
|
||||||
public void onPlayerMove(PlayerMoveEvent e) {
|
public void onPlayerMove(PlayerMoveEvent e) {
|
||||||
if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) {
|
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||||
simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getTo());
|
hideShow(e.getPlayer(), simulatorPair.getKey());
|
||||||
} else {
|
|
||||||
SimulatorCursor.hide(e.getPlayer());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerItemHeld(PlayerItemHeldEvent e) {
|
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
|
@EventHandler
|
||||||
public void onPlayerDropItem(PlayerDropItemEvent e) {
|
public void onPlayerDropItem(PlayerDropItemEvent e) {
|
||||||
simulatorShowHide(e.getPlayer(), i -> e.getItemDrop().getItemStack(), i -> null, e.getPlayer().getLocation());
|
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||||
}
|
hideShow(e.getPlayer(), simulatorPair.getKey());
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
if (ItemUtils.isItem(e.getPlayer().getInventory().getItemInMainHand(), "simulator")) {
|
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||||
simulatorShowHide(e.getPlayer(), i -> null, PlayerInventory::getItemInMainHand, e.getPlayer().getLocation());
|
hideShow(e.getPlayer(), simulatorPair.getKey());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
SimulatorCursor.hide(event.getPlayer(), null);
|
hideShow(e.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());
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private Map<Player, PreviewRecord> previewRecordMap = new HashMap<>();
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent event) {
|
public void onPlayerSwapHandItems(PlayerSwapHandItemsEvent e) {
|
||||||
PreviewRecord current = previewRecordMap.remove(event.getPlayer());
|
Pair<TNTSimulator, Boolean> simulatorPair = getSimulator(e.getPlayer());
|
||||||
if (current != null) {
|
hideShow(e.getPlayer(), simulatorPair.getKey());
|
||||||
current.close(event.getPlayer());
|
|
||||||
|
if (!simulatorPair.getValue()) return;
|
||||||
|
|
||||||
|
TNTSimulator simulator = SimulatorStorage.getSimulator(e.getOffHandItem());
|
||||||
|
if (preview(e.getPlayer(), simulator)) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ItemUtils.isItem(event.getOffHandItem(), "simulator")) {
|
private boolean preview(Player player, TNTSimulator simulator) {
|
||||||
return;
|
if (simulator == null) return false;
|
||||||
}
|
Pair<Integer, Map<Integer, List<List<Pair<TNTData, Integer>>>>> toCalculate = simulator.locations(player);
|
||||||
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());
|
|
||||||
PreviewRecord previewRecord = Simulator.impl.run(toCalculate);
|
PreviewRecord previewRecord = Simulator.impl.run(toCalculate);
|
||||||
if (previewRecord == null) {
|
if (previewRecord == null) {
|
||||||
event.setCancelled(true);
|
return true;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
previewRecord.add(event.getPlayer());
|
previewRecord.add(player);
|
||||||
previewRecordMap.put(event.getPlayer(), previewRecord);
|
previewRecordMap.put(player, previewRecord);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren