mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 01:17:47 +01:00
Add PlayerPacketEvent
This commit is contained in:
parent
25f1183a1b
commit
3dfd4678d5
@ -0,0 +1,38 @@
|
|||||||
|
package net.minestom.server.event.player;
|
||||||
|
|
||||||
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.event.CancellableEvent;
|
||||||
|
import net.minestom.server.event.trait.PlayerEvent;
|
||||||
|
import net.minestom.server.network.packet.client.ClientPacket;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class PlayerPacketEvent implements PlayerEvent, CancellableEvent {
|
||||||
|
|
||||||
|
private final Player player;
|
||||||
|
private final ClientPacket packet;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
|
public PlayerPacketEvent(Player player, ClientPacket packet) {
|
||||||
|
this.player = player;
|
||||||
|
this.packet = packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull ClientPacket getPacket() {
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancelled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancelled = cancel;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,8 @@ package net.minestom.server.listener.manager;
|
|||||||
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
|
import net.minestom.server.event.EventDispatcher;
|
||||||
|
import net.minestom.server.event.player.PlayerPacketEvent;
|
||||||
import net.minestom.server.listener.*;
|
import net.minestom.server.listener.*;
|
||||||
import net.minestom.server.network.ConnectionManager;
|
import net.minestom.server.network.ConnectionManager;
|
||||||
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
import net.minestom.server.network.packet.client.ClientPlayPacket;
|
||||||
@ -74,6 +76,8 @@ public final class PacketListenerManager {
|
|||||||
LOGGER.warn("Packet " + clazz + " does not have any default listener! (The issue comes from Minestom)");
|
LOGGER.warn("Packet " + clazz + " does not have any default listener! (The issue comes from Minestom)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO remove legacy
|
||||||
|
{
|
||||||
final PacketController packetController = new PacketController();
|
final PacketController packetController = new PacketController();
|
||||||
for (ClientPacketConsumer clientPacketConsumer : CONNECTION_MANAGER.getReceivePacketConsumers()) {
|
for (ClientPacketConsumer clientPacketConsumer : CONNECTION_MANAGER.getReceivePacketConsumers()) {
|
||||||
clientPacketConsumer.accept(player, packetController, packet);
|
clientPacketConsumer.accept(player, packetController, packet);
|
||||||
@ -81,6 +85,14 @@ public final class PacketListenerManager {
|
|||||||
|
|
||||||
if (packetController.isCancel())
|
if (packetController.isCancel())
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Event
|
||||||
|
PlayerPacketEvent playerPacketEvent = new PlayerPacketEvent(player, packet);
|
||||||
|
EventDispatcher.call(playerPacketEvent);
|
||||||
|
if (playerPacketEvent.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Finally execute the listener
|
// Finally execute the listener
|
||||||
if (packetListenerConsumer != null) {
|
if (packetListenerConsumer != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user