mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 09:54:59 +01:00
Implement packet send/receive events
This commit is contained in:
@@ -18,10 +18,9 @@ public abstract class Event {
|
||||
/**
|
||||
* Cancels the event if possible.
|
||||
*/
|
||||
public void cancel() throws IllegalAccessException {
|
||||
if(!(this instanceof Cancellable))
|
||||
throw new IllegalAccessException("Event is not cancellable.");
|
||||
this.cancelled = true;
|
||||
public void cancel() {
|
||||
if(this instanceof Cancellable)
|
||||
this.cancelled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package emu.grasscutter.server.event.game;
|
||||
|
||||
import emu.grasscutter.server.event.Cancellable;
|
||||
import emu.grasscutter.server.event.ServerEvent;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
|
||||
public final class ReceivePacketEvent extends ServerEvent implements Cancellable {
|
||||
private final GameSession gameSession;
|
||||
private final int packetId;
|
||||
private byte[] packetData;
|
||||
|
||||
public ReceivePacketEvent(GameSession gameSession, int packetId, byte[] packetData) {
|
||||
super(Type.GAME);
|
||||
|
||||
this.gameSession = gameSession;
|
||||
this.packetId = packetId;
|
||||
this.packetData = packetData;
|
||||
}
|
||||
|
||||
public GameSession getGameSession() {
|
||||
return this.gameSession;
|
||||
}
|
||||
|
||||
public int getPacketId() {
|
||||
return this.packetId;
|
||||
}
|
||||
|
||||
public void setPacketData(byte[] packetData) {
|
||||
this.packetData = packetData;
|
||||
}
|
||||
|
||||
public byte[] getPacketData() {
|
||||
return this.packetData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package emu.grasscutter.server.event.game;
|
||||
|
||||
import emu.grasscutter.net.packet.GenshinPacket;
|
||||
import emu.grasscutter.server.event.Cancellable;
|
||||
import emu.grasscutter.server.event.ServerEvent;
|
||||
import emu.grasscutter.server.game.GameSession;
|
||||
|
||||
public final class SendPacketEvent extends ServerEvent implements Cancellable {
|
||||
private final GameSession gameSession;
|
||||
private GenshinPacket packet;
|
||||
|
||||
public SendPacketEvent(GameSession gameSession, GenshinPacket packet) {
|
||||
super(Type.GAME);
|
||||
|
||||
this.gameSession = gameSession;
|
||||
this.packet = packet;
|
||||
}
|
||||
|
||||
public GameSession getGameSession() {
|
||||
return this.gameSession;
|
||||
}
|
||||
|
||||
public void setPacket(GenshinPacket packet) {
|
||||
this.packet = packet;
|
||||
}
|
||||
|
||||
public GenshinPacket getPacket() {
|
||||
return this.packet;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user