diff --git a/src/main/java/com/moulberry/axiom/event/AxiomManipulateEntityEvent.java b/src/main/java/com/moulberry/axiom/event/AxiomManipulateEntityEvent.java index 794a8ea..3bfe81f 100644 --- a/src/main/java/com/moulberry/axiom/event/AxiomManipulateEntityEvent.java +++ b/src/main/java/com/moulberry/axiom/event/AxiomManipulateEntityEvent.java @@ -19,13 +19,22 @@ public class AxiomManipulateEntityEvent extends Event implements Cancellable { private final Player player; private final UUID entityUUID; + private final Location fromLocation; private final Location toLocation; private boolean cancelled = false; - public AxiomManipulateEntityEvent(Player player, UUID entityUUID, Location toLocation) { + public AxiomManipulateEntityEvent(Player player, Entity entity, Location toLocation) { + this.player = player; + this.entityUUID = entity.getUniqueId(); + this.fromLocation = entity.getLocation(); + this.toLocation = toLocation; + } + + public AxiomManipulateEntityEvent(Player player, UUID entityUUID, Location fromLocation, Location toLocation) { this.player = player; this.entityUUID = entityUUID; + this.fromLocation = fromLocation; this.toLocation = toLocation; } @@ -33,6 +42,10 @@ public class AxiomManipulateEntityEvent extends Event implements Cancellable { return player; } + public Location getFromLocation() { + return fromLocation; + } + public Location getToLocation() { return toLocation; } diff --git a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java index b6c3ea8..34c6184 100644 --- a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java @@ -120,11 +120,16 @@ public class ManipulateEntityPacketListener implements PluginMessageListener { } if (entry.merge != null && !entry.merge.isEmpty()) { + final Location oldLocation = entity.getBukkitEntity().getLocation(); NbtSanitization.sanitizeEntity(entry.merge); CompoundTag compoundTag = entity.saveWithoutId(new CompoundTag()); compoundTag = merge(compoundTag, entry.merge); entity.load(compoundTag); + + Location newLocation = new Location(serverLevel.getWorld(), position.x, position.y, position.z, entity.getBukkitYaw(), entity.getXRot()); + AxiomManipulateEntityEvent manipulateEvent = new AxiomManipulateEntityEvent(player, entry.uuid, oldLocation, newLocation); + if (!manipulateEvent.callEvent()) continue; } entity.setPosRaw(position.x, position.y, position.z); @@ -138,7 +143,7 @@ public class ManipulateEntityPacketListener implements PluginMessageListener { float newPitch = entry.relativeMovementSet.contains(RelativeMovement.X_ROT) ? entity.getXRot() + entry.pitch : entry.pitch; Location newLocation = new Location(serverLevel.getWorld(), newX, newY, newZ, newYaw, newPitch); - AxiomManipulateEntityEvent manipulateEvent = new AxiomManipulateEntityEvent(player, entity.getUUID(), newLocation); + AxiomManipulateEntityEvent manipulateEvent = new AxiomManipulateEntityEvent(player, entity.getBukkitEntity(), newLocation); if (!manipulateEvent.callEvent()) continue; if (entity instanceof HangingEntity hangingEntity) {