dmulloy2 / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.
GNU General Public License v2.0
1.03k stars 259 forks source link

The constructor PacketType(PacketType.Protocol, PacketType.Sender, int, int) is undefined #2368

Closed FierraCodes closed 4 months ago

FierraCodes commented 1 year ago

Making a minecraft client with custom packets.

Describe the question The constructor PacketType(PacketType.Protocol, PacketType.Sender, int, int) is undefined, Should be PacketType(PacketType.Protocol, PacketType.Sender, String[], String[])

API method(s) used I forgot, abandoned this project and reworking it now

Expected behavior No errors with packetId being an integer

Code

private static void registerPacket(Class<? extends DEMCPacket> packetClass, int packetId, Sender sender) {
        PacketType packetType = new PacketType(Protocol.PLAY, sender, packetId, packetId);
        packetToType.put(packetClass, packetType);
        final EnumProtocol protocol = EnumProtocol.PLAY;
        final EnumProtocolDirection direction = packetType.isClient() ? EnumProtocolDirection.SERVERBOUND : EnumProtocolDirection.CLIENTBOUND;
        try {
            Map<EnumProtocolDirection, BiMap<Integer, Class<? extends Packet<?>>>> theMap = (Map<EnumProtocolDirection, BiMap<Integer, Class<? extends Packet<?>>>>) FieldUtils.readField(protocol, "j", true);
            BiMap<Integer, Class<? extends Packet<?>>> biMap = theMap.get(direction);
            biMap.put(packetId, (Class<? extends Packet<?>>) packetClass);
            theMap.put(direction, biMap);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        Map<Class<?>, EnumProtocol> map = (Map<Class<?>, EnumProtocol>) Accessors.getFieldAccessor(EnumProtocol.class, Map.class, true).get(protocol);
        map.put(packetClass, protocol);
    }
lukalt commented 1 year ago

I really have no clue what you are trying to do. However, the proper way to construct new PacketTypes would be to use PacketType.fromCurrent(Protocol protocol, Sender sender, int packetId, Class<?> packetClass)