I need to figure out the best way to get hold of BungeeCord’s channel, but if we were to create our own channel it’d look something like this:
// Create the channel
RawDataChannel channel = game.getChannelRegistrar().createRawChannel(this, "BungeeCord");
// A one-liner to send a player to a server
channel.sendTo(player, buf -> buf.writeString("Connect").writeString("someServer"));
// Another example
channel.sendTo(player, buf -> {
buf.writeString("PlayerCount");
buf.writeString("someServer");
});
// Add listeners for data
channel.addListener(Platform.Type.SERVER, (buf, con, side) -> {
String subChannel = buf.readString();
if (subChannel.equals("PlayerCount")) {
String server = buf.readString();
int playerCount = buf.readInteger();
System.out.println("Player count on server " + server + " is " + playerCount);
}
});
Using Message is the highly recommended way if you’re in control of the channel’s protocol spec. Because BungeeCord already defined their own spec, you have to use it. If BungeeCord were to create a new version, I’d suggest they use messages following the spec of IndexedMessageChannel