diff --git a/src/main/java/me/ANONIMUS/proxy/protocol/connection/PlayerConnection.java b/src/main/java/me/ANONIMUS/proxy/protocol/connection/PlayerConnection.java index a208412..440260c 100644 --- a/src/main/java/me/ANONIMUS/proxy/protocol/connection/PlayerConnection.java +++ b/src/main/java/me/ANONIMUS/proxy/protocol/connection/PlayerConnection.java @@ -17,9 +17,7 @@ import me.ANONIMUS.proxy.protocol.objects.Player; import me.ANONIMUS.proxy.protocol.objects.Session; import me.ANONIMUS.proxy.protocol.packet.Packet; -import me.ANONIMUS.proxy.protocol.packet.PacketBuffer; import me.ANONIMUS.proxy.protocol.packet.PacketDirection; -import me.ANONIMUS.proxy.protocol.packet.Protocol; import me.ANONIMUS.proxy.protocol.packet.impl.CustomPacket; import me.ANONIMUS.proxy.protocol.packet.impl.client.HandshakePacket; import me.ANONIMUS.proxy.protocol.packet.impl.client.login.ClientLoginStartPacket; diff --git a/src/main/java/me/ANONIMUS/proxy/protocol/data/ConnectionState.java b/src/main/java/me/ANONIMUS/proxy/protocol/data/ConnectionState.java index 75bd476..d8d6d23 100644 --- a/src/main/java/me/ANONIMUS/proxy/protocol/data/ConnectionState.java +++ b/src/main/java/me/ANONIMUS/proxy/protocol/data/ConnectionState.java @@ -5,20 +5,21 @@ import me.ANONIMUS.proxy.protocol.packet.Protocol; import java.util.HashMap; +import java.util.List; import java.util.Map; public enum ConnectionState { HANDSHAKE, LOGIN, PLAY, STATUS; - private final Map clientPackets; - private final Map serverPackets; + private final Map> clientPackets; + private final Map> serverPackets; ConnectionState() { this.clientPackets = new HashMap<>(); this.serverPackets = new HashMap<>(); } - public Map getPacketsByDirection(PacketDirection direction) { + public Map> getPacketsByDirection(PacketDirection direction) { switch (direction) { case SERVERBOUND: return clientPackets; diff --git a/src/main/java/me/ANONIMUS/proxy/protocol/packet/PacketBuffer.java b/src/main/java/me/ANONIMUS/proxy/protocol/packet/PacketBuffer.java index 05e778f..be8aadb 100644 --- a/src/main/java/me/ANONIMUS/proxy/protocol/packet/PacketBuffer.java +++ b/src/main/java/me/ANONIMUS/proxy/protocol/packet/PacketBuffer.java @@ -24,7 +24,6 @@ import java.nio.channels.ScatteringByteChannel; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.UUID; import java.util.stream.IntStream; diff --git a/src/main/java/me/ANONIMUS/proxy/protocol/packet/PacketRegistry.java b/src/main/java/me/ANONIMUS/proxy/protocol/packet/PacketRegistry.java index 3aaa2ae..7664d79 100644 --- a/src/main/java/me/ANONIMUS/proxy/protocol/packet/PacketRegistry.java +++ b/src/main/java/me/ANONIMUS/proxy/protocol/packet/PacketRegistry.java @@ -7,14 +7,24 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; public class PacketRegistry { public void init() { Arrays.asList(PacketDirection.values()).forEach(direction -> Arrays.stream(ConnectionState.values()).filter(connectionState -> connectionState != ConnectionState.HANDSHAKE).forEach(state -> new Reflections("me.ANONIMUS.proxy.protocol.packet.impl." + direction.packetsPackageName.toLowerCase() + "." + state.name().toLowerCase()).getSubTypesOf(Packet.class).forEach(p -> { try { final Packet packet = p.newInstance(); - packet.getProtocolList().forEach(protocol -> state.getPacketsByDirection(direction).put(protocol, packet)); + packet.getProtocolList().forEach(protocol -> { + if(state.getPacketsByDirection(direction).get(packet) == null) { + List protocols = new ArrayList<>(); + protocols.add(protocol); + state.getPacketsByDirection(direction).put(packet, protocols); + } else { + state.getPacketsByDirection(direction).get(packet).add(protocol); + } + }); } catch (InstantiationException | IllegalAccessException e) { e.printStackTrace(); } @@ -45,6 +55,15 @@ private Packet getPacket(ConnectionState connectionState, PacketDirection direct if(connectionState == ConnectionState.HANDSHAKE) { return new HandshakePacket(); } - return connectionState.getPacketsByDirection(direction).get(protocol); + + for(Packet packet : connectionState.getPacketsByDirection(direction).keySet()) { + for(Protocol protocol1 : connectionState.getPacketsByDirection(direction).get(packet)) { + if(protocol1.equals(protocol)) { + return packet; + } + } + } + + return null; } } \ No newline at end of file