Utility that simplifies the exchange of data between BungeeCord and Bukkit
- Download the latest version of the plugin here
- Stop your BungeeCord server
- Drag and drop it into the folder "plugins" in the root of your BungeeCord server
- Start your BungeeCord server
This is a very simple tool that allows Bukkit plugins to get informations about other servers/players that are connected to the same BungeeCord network. It also allows Bukkit plugins to give certain instructions to the BungeeCord server that would otherwise require you to connect your plugins to a SQL server. See the documentation below for further instructions.
Note: This assumes that you have already followed the instructions in the installation part of this file. First, we have to tell our Bukkit plugins that we want to use the BukkitPluginMessenger. We accomplish that by inserting the following line into the onEnable method of the plugin:
public void onEnable(){
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeePluginMsg");
}
We can now start sending instructions to the BungeeCord server.
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("kickPlayer")
out.writeUTF("PLAYERNAME");
out.writeUTF("MESSAGE");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("kickPlayerUUID")
out.writeUTF("UUID");
out.writeUTF("MESSAGE");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("sendMessage");
out.writeUTF("PLAYERNAME");
out.writeUTF("MESSAGE");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("broadcast");
out.writeUTF("PERMISSION");
out.writeUTF("MESSAGE");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("broadcastMessage");
out.writeUTF("MESSAGE");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
To query data from the BungeeCord server, you will additionally need a listener that listens to the responses from the BungeeCord server. This listener must also be registered in the onEnable method. See the example below.
public class foo extends JavaPlugin implements PluginMessageListener {
public void onEnable(){
getServer().getMessenger().registerIncomingPluginChannel(this, "BungeePluginMsg", this /* Or an instance of a different class that implements the interface PluginMessageListener */);
}
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] data) {
if(s.equalsIgnoreCase("BungeePluginMsg")){
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
if(in.readUTF().equalsIgnoreCase("SUBCHANNEL")){
String response = in.readUTF();
}
}
}
}
Now we are ready to query data from our BungeeCord server.
Query
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("getServers");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
Example Response (JSON Array)
[
{
"name":"Server1",
"online":true,
"count":10
},
{
"name":"Server2",
"online":false,
"count":-1
}
]
Query
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("getPlayers");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
Example Response (JSON Array)
[
{
"name":"Player1",
"uuid":"UUID1",
"server":"Server1"
},
{
"name":"Player2",
"uuid":"UUID2",
"server":"Server2"
}
]
Query
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("getPlayerCount");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
Example Response (Plain text)
10
Query
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("getPlayer");
out.writeUTF("PLAYERNAME");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
Example Response (JSON Object)
{
"name":"Player1",
"online":true,
"server":"Server1",
"uuid":"UUID1",
"ping":10,
"ip":"127.0.0.1"
}
{
"name":"Player2",
"online":false
}
Query
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("getServer");
out.writeUTF("SERVERNAME");
Bukkit.getServer().sendPluginMessage(this /* (Instance of your main class) */, "BungeePluginMsg", out.toByteArray());
Example Response (JSON Object)
{
"name":"Server1",
"online":true,
"motd":"Motd1",
"players":"Player1, Player2, Player3",
"count":3
}
{
"name":"Server2",
"online":false
}
If the server does not exist
{}