blob: a5a858b0f622d2f418d753e9c86e0e8ff00d959c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package me.Danker.handlers;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import me.Danker.events.PacketReadEvent;
import me.Danker.events.PacketWriteEvent;
import net.minecraft.network.Packet;
import net.minecraftforge.common.MinecraftForge;
public class PacketHandler extends ChannelDuplexHandler {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof Packet) {
if (MinecraftForge.EVENT_BUS.post(new PacketReadEvent((Packet) msg))) return;
}
super.channelRead(ctx, msg);
}
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof Packet) {
if (MinecraftForge.EVENT_BUS.post(new PacketWriteEvent((Packet) msg))) return;
}
super.write(ctx, msg, promise);
}
}
|