mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-21 15:41:38 +01:00
Make PlayerPacketOutEvent cancellable
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
0c6599fee6
commit
1bf750a603
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user