bungeecord plugin messaging check online players code example

Example: Send a custom plugin message to said server

// Sending
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Forward"); // So BungeeCord knows to forward it
out.writeUTF(recipientServerName);
out.writeUTF(channelName); // The channel name to check if this your data

ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
DataOutputStream msgout = new DataOutputStream(msgbytes);
try {
	msgout.writeUTF(dataToSend);
	msgout.writeShort(shortAlsoIntDataToSend);
} catch (IOException exception){ exception.printStackTrace(); }

out.writeShort(msgbytes.toByteArray().length);
out.write(msgbytes.toByteArray());

System.out.println("Sending message");
playerSender.sendPluginMessage(main, "BungeeCord", out.toByteArray());

	//Responce
String subChannel = in.readUTF();
short len = in.readShort();
byte[] msgbytes = new byte[len];
in.readFully(msgbytes);

DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
String somedata = msgin.readUTF(); // Read the data in the same way you wrote it
short somenumber = msgin.readShort();

Tags:

Java Example