Answers for "Send a custom plugin message to said server"

0

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();
Posted by: Guest on July-17-2020

Code answers related to "Send a custom plugin message to said server"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language