From 9c5ecab8598760ae3a399e8f0c6e9cde5e55924b Mon Sep 17 00:00:00 2001 From: Moulberry Date: Thu, 27 Jun 2024 01:23:55 +0800 Subject: [PATCH] Recreate Boy0000/entity-manip-event --- .../event/AxiomManipulateEntityEvent.java | 50 +++++++++++++++++++ .../ManipulateEntityPacketListener.java | 6 +++ 2 files changed, 56 insertions(+) create mode 100644 src/main/java/com/moulberry/axiom/event/AxiomManipulateEntityEvent.java diff --git a/src/main/java/com/moulberry/axiom/event/AxiomManipulateEntityEvent.java b/src/main/java/com/moulberry/axiom/event/AxiomManipulateEntityEvent.java new file mode 100644 index 0000000..5e418e1 --- /dev/null +++ b/src/main/java/com/moulberry/axiom/event/AxiomManipulateEntityEvent.java @@ -0,0 +1,50 @@ +package com.moulberry.axiom.event; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public class AxiomManipulateEntityEvent extends Event implements Cancellable { + + private static final HandlerList HANDLERS = new HandlerList(); + + private final Player player; + private final Entity entity; + + private boolean cancelled = false; + + public AxiomManipulateEntityEvent(Player player, @NotNull Entity entity) { + this.player = player; + this.entity = entity; + } + + public Player getPlayer() { + return player; + } + + public Entity getEntity() { + return entity; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java index b1d3a2c..7cab623 100644 --- a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java @@ -2,6 +2,7 @@ package com.moulberry.axiom.packet; import com.moulberry.axiom.AxiomPaper; import com.moulberry.axiom.NbtSanitization; +import com.moulberry.axiom.event.AxiomManipulateEntityEvent; import com.moulberry.axiom.integration.Integration; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.moulberry.axiom.viaversion.UnknownVersionHelper; @@ -124,6 +125,11 @@ public class ManipulateEntityPacketListener implements PluginMessageListener { continue; } + AxiomManipulateEntityEvent manipulateEvent = new AxiomManipulateEntityEvent(player, entity.getBukkitEntity()); + if (!manipulateEvent.callEvent()) { + continue; + } + if (entry.merge != null && !entry.merge.isEmpty()) { NbtSanitization.sanitizeEntity(entry.merge);