diff --git a/src/main/java/net/minestom/server/event/player/PlayerPacketOutEvent.java b/src/main/java/net/minestom/server/event/player/PlayerPacketOutEvent.java index 71fb43760..6dc726ba1 100644 --- a/src/main/java/net/minestom/server/event/player/PlayerPacketOutEvent.java +++ b/src/main/java/net/minestom/server/event/player/PlayerPacketOutEvent.java @@ -1,6 +1,7 @@ package net.minestom.server.event.player; import net.minestom.server.entity.Player; +import net.minestom.server.event.trait.CancellableEvent; import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.network.packet.server.ServerPacket; import org.jetbrains.annotations.ApiStatus; @@ -12,10 +13,10 @@ import org.jetbrains.annotations.NotNull; * Currently, do not support viewable packets. */ @ApiStatus.Experimental -public class PlayerPacketOutEvent implements PlayerEvent { - +public class PlayerPacketOutEvent implements PlayerEvent, CancellableEvent { private final Player player; private final ServerPacket packet; + private boolean cancelled; public PlayerPacketOutEvent(Player player, ServerPacket packet) { this.player = player; @@ -30,4 +31,14 @@ public class PlayerPacketOutEvent implements PlayerEvent { public @NotNull ServerPacket getPacket() { return packet; } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancel) { + this.cancelled = cancel; + } } diff --git a/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java b/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java index f412bd0aa..b68327924 100644 --- a/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java +++ b/src/main/java/net/minestom/server/network/player/PlayerSocketConnection.java @@ -349,7 +349,9 @@ public class PlayerSocketConnection extends PlayerConnection { // Outgoing event if (player != null && outgoing.hasListener()) { final ServerPacket serverPacket = SendablePacket.extractServerPacket(packet); - outgoing.call(new PlayerPacketOutEvent(player, serverPacket)); + PlayerPacketOutEvent event = new PlayerPacketOutEvent(player, serverPacket); + outgoing.call(event); + if (event.isCancelled()) return; } // Write packet if (packet instanceof ServerPacket serverPacket) {