Archived
0

refactoring

This commit is contained in:
2021-06-15 23:56:53 +03:00
parent 475f1a28ca
commit e7b5120661
10 changed files with 138 additions and 65 deletions

View File

@@ -6,11 +6,11 @@ import mc.protocol.packets.ClientSidePacket;
import mc.protocol.utils.Table;
@SuppressWarnings({ "rawtypes", "unchecked" })
public class PacketProcessor {
public class ProtocolHandlersBus {
private final Table<State, Class<? extends ClientSidePacket>, Handler> table = new Table<>();
public <P extends ClientSidePacket> PacketProcessor addHandler(State state, Class<P> packetClass, Handler<P> handler) {
public <P extends ClientSidePacket> ProtocolHandlersBus addHandler(State state, Class<P> packetClass, Handler<P> handler) {
table.put(state, packetClass, handler);
return this;
}

View File

@@ -17,12 +17,12 @@ public class ProtocolInboundHandler extends SimpleChannelInboundHandler<ClientSi
private static final String CLIENT_FORCE_DISCONNECTED_IOEXCEPTION_MESSAGE_RU = "Программа на вашем хост-компьютере разорвала установленное подключение";
private final PacketProcessor packetProcessor;
private final ProtocolHandlersBus protocolHandlersBus;
@Override
protected void channelRead0(ChannelHandlerContext ctx, ClientSidePacket packet) {
State state = Objects.requireNonNull(ctx.channel().attr(ProtocolAttributes.STATE).get());
packetProcessor.process(state, ctx, packet);
protocolHandlersBus.process(state, ctx, packet);
}
@Override