Network Channel - How to create a new channelbuf

I’m currently using raw channels to communicate between a bungeecord and sponge server. While reading works fine. I didn’t found a way to construct a new ChannelBuf for sending a new message from the sponge server to the BungeeCord server.

Do I have to have to create a new class implementing the interface on my own?

You don’t create an instance. You get given an instance when sending data.
Note that the signature of the methods in a raw channel take a Consumer of a ChannelBuf, e.g.

void sendTo(Player player, Consumer<ChannelBuf> payload);

This means you use it like this:

channel.sendTo(player, buf -> {
    buf.writeInt(1); // Or whatever here

I missed that it’s a consumer. Thank you very much.

Have you looked into SpongyCord?

1 Like