Resource Netty Packet library

Discussion in 'Spigot Plugin Development' started by PierreSchwang, Jul 17, 2021.

  1. Hey,

    just a little library I wrote for myself for Netty Client <-> Server communication, which may be useful for someone:

    https://github.com/PierreSchwang/Netty-Packet

    It handles all stuff like encoding, decoding, Event-Handling. The PacketBuffer could also be used for PluginMessages.

    Example Packet structure:
    Code (Java):
    public class TestPacket extends Packet {

        private UUID uuid;

        // no-args-constructor is required for packet construction
        public TestPacket() {
        }

        @Override
        public void read(PacketBuffer packetBuffer) {
            uuid = packetBuffer.readUUID();
        }

        @Override
        public void write(PacketBuffer packetBuffer) {
            packetBuffer.writeUUID(uuid);
        }

        public UUID getUuid() {
            return uuid;
        }

        public TestPacket setUuid(UUID uuid) {
            this.uuid = uuid;
            return this;
        }
    }
    The Event-System is straight forward and annotation based:

    Code (Java):

    // Simple example, when TestPacket is received, dump the data and source.
    // ChannelHandlerContext is an optional parameter
    @PacketSubscriber
    public void onPacketReceive(TestPacket packet, ChannelHandlerContext ctx) {
       System.out.println("Received " + packet.getUuid().toString() + " from " + ctx.channel().remoteAddress().toString());
    }
    More examples can be acquired from the readme and the unit tests. Otherwise, it should be quite self explanatory.
     
    #1 PierreSchwang, Jul 17, 2021
    Last edited: Jul 18, 2021
    • Like Like x 1
  2. Lack of description resources.
     
  3. I disagree- look at his README.md. There's tons of documentation/example code to supplement what he described here. Although it may be beneficial to put some of that here.
     
    • Like Like x 1
  4. Why he didn't write it here, so I wrote it for lack of explanation.
     
  5. explanation is one click away, please
     
    • Like Like x 1
  6. I understand your concerns. I have added rough examples and explanations and referred to the repository for more stuff.