The field Protocol.TO_CLIENT is not visible

Discussion in 'BungeeCord Plugin Development' started by goop51, Mar 17, 2020.

  1. I've wrote this method to register a packet:
    Code (Java):
    public static void registerPacket(Direction data, int protocolVersion, int packetID, Class<? extends PingPacket> packetClass) {
            try {
                Class<?> protocolMap = Class.forName("net.md_5.bungee.protocol.Protocol$ProtocolMapping");
                Method register = Direction.class.getDeclaredMethod("registerPacket", Class.class, Array.newInstance(protocolMap, 0).getClass());
                Method map = Protocol.class.getDeclaredMethod("map", int.class, int.class);
                Object packetMap = Array.newInstance(protocolMap, 1);
                Array.set(packetMap, 0, map.invoke(null, protocolVersion, packetID));
                register.invoke(data, packetClass, packetMap);
            } catch (Exception e) {
    and I'm calling this method using this code:
    Code (Java):
    for ( int i = 0; i < packets.length; i++ )
                this.registerPacket(Protocol.GAME.TO_CLIENT, 340, 0x0D, packets[i]);
    But It's ends up with the following error:
    I have no idea what I'm doing wrong. Can somebody help me? Thanks!
  2. You need to access the field using reflection and then cast it. Also you should be asking for DirectionData and not Direction.
  3. Thanks. Can you give me a code example? I've spent 10 hours to figure it out with no success.

    P.S: I'm developing a plugin, not editing a BungeeCord source.
    #3 goop51, Mar 17, 2020
    Last edited: Mar 17, 2020
  4. "Can I get spoon feed?" NO
    And I clearly know that you are doing bungee plugin