Backstory: I wrote this whilst working on a private project for a client. We had to do a lot of Bukkit -> BungeeCord communication and this became a real pain. Plugin Messages are long to write and you can often end up with issues using them. So I wrote this little API to ease the use of plugin messages. Before I begin explaining how it works, lets from now on, refer to plugin messages as Packets How Does It Work?: In short a Packet class is used to load and send data. You would have this api installed on whichever software you use it (Bukkit/BungeeCord etc). This api handles the sending and receiving of the packets. You use a Bukkit-like listener to receive these packets and a simple API to send it. Usage: The usage of this API is very similar on Bukkit as it is to BungeeCord or any other implementations I include in the future but I'll show an example of each anyway. Bukkit: Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Initializing Example: Code:java public PacketManager packetManager; public void onEnable(){packetManager = new BukkitPacketManager(this, "MyChannelName");packetManager.registerPacket(PacketPlayerUpdatePoints.class);packetManager.registerListener(new IncomingPacketHandler());} Sending Example: Code:java packetManager.sendPacket(new PacketPlayer(Bukkit.getPlayer("iKeirNez"), new PacketPlayerUpdatePoints(50))); Listener Example: Code:java public class IncomingPacketHandler implements PacketListener {@PacketHandlerpublic void onPointsUpdate(PacketPlayerUpdatePoints packet){Player player = packet.getSender().getBukkitPlayer();int points = packet.points; // do something to update points}} BungeeCord: Spoiler (Move your mouse to the spoiler area to reveal the content) Show Spoiler Hide Spoiler Initializing Example: Code:java public PacketManager packetManager;public void onEnable(){packetManager = new BungeeCordPacketManager(this, "MyChannelName");packetManager.registerPacket(PacketPlayerUpdatePoints.class);packetManager.registerListener(new IncomingPacketHandler());} Sending Example: Code:java packetManager.sendPacket(new PacketPlayer(ProxyServer.getInstance().getPlayer("iKeirNez"), new PacketPlayerUpdatePoints(50))); Listener Example: Code:java public class IncomingPacketHandler implements PacketListener {@PacketHandlerpublic void onPointsUpdate(PacketPlayerUpdatePoints packet){ProxiedPlayer player = packet.getSender().getBungeePlayer();int points = packet.points; // do something to update points}} The Packet Class: This is probably the most important part of using this API, creating you're own Packet classes. For the above example I would use a Packet class that looks like this. Code:java public class PacketPlayerUpdatePoints extends StandardPacket { public int points; public PacketPlayerUpdatePoints(){} public PacketPlayerUpdatePoints(int point){this.change = change;} public void handle(DataInputStream dataInputStream) throws IOException {this.point = dataInputStream.readInt();} public PacketWriter write() throws IOException {PacketWriter packetWriter = new PacketWriter(this);packetWriter.writeInt(points);return packetWriter;}} Remember this packet class MUST be included in any module in which you send or receive otherwise this will not be able to function. A good way to do this would be with Maven by creating a Common module and then included that module in each other module jar. GitHub: https://github.com/iKeirNez/PluginMessageAPI-Plus Let me know if you use this API in any of you're Projects/Servers and I'll keep a list somewhere of projects/servers that use this. If you need any help or clarification on how to use this then feel free to post a reply or pm me.
DrJava But this resource is for Bukkit OR Bungee iKeirNez Really useful resource! Thank you for that.
Yes, it uses BungeeCord's built in forward channel so you don't need to install a BungeeCord plugin. You can simply use Code:java packetManager.sendForwardPacket(new PacketPlayer(player), packet, "theServerYouWishToSendThisTo"); I'll add support for the ForwardAll channel soon.
That is really nice, but what is the "theServerYouWishToSendThisTo" argument? The server ip/adress or the name which is defined in bungee?
iKeirNez Would this work with modified versions of bungeecord and will it be able to send plugin messages to different server versions? Or is it compatible with only one specific version of bungeecord?
This should be compatible with most versions of BungeeCord (as it only uses the API, not any internals) and yes it can be sent to different versions of BungeeCord as long as the same version of PluginMessageAPI+ is installed (even different versions of PluginMessageAPI+ may work, but I can't guarantee it.).