Resource BungeeCord Server Bridge Utility

Discussion in 'Spigot Plugin Development' started by tcmal, Jan 6, 2020.

  1. This is a small utility for sending classes over the Bungee plugin messaging channel.

    Say you have an event with whatever fields:

    Code (Java):
    public class StartMatchmakingEvent extends RemoteEvent {
        public UUID player;
        public boolean isWithParty;
        public String queueName;
        public int priority;
        // ...
    which you'd like to send to some other server on your bungee instance, 'pvp'. First, initialise the bridge and register your class:

    Code (Java):
    this.bridge = new ServerBridge(this);

    // The 1st argument is an arbitrary string, as long as its the same for the receiver.
    this.bridge.registerSubChannel("StartMatchmaking", StartMatchmakingEvent.class);
    Now you can send your event through the bungee channel:

    Code (Java):
    StartMatchmakingEvent e = new StartMatchmakingEvent(UUID.randomUUID(), true, "pvp", 999);

    // Send it to the PVP server
    bridge.forwardEvent(e, "pvp");

    // Broadcast to all servers

    // You can also specify which player to send the packet through, but it shouldn't matter
    bridge.forwardEvent(e, "ALL", player)
    This comes with a couple drawbacks:
    • Both the sending and receiving servers must have at least one online player
    • The message must be less than 32766 bytes (unlikely to be an issue)
    • All types used in the RemoteEvent class must implement Serializable.

    Hopefully this is useful to some. Feel free to look inside the code, it's not complicated.

    • Like Like x 3
  2. This is awesome, I don't know how its not more recognized.
  3. The Bukkit.getPluginManager (). CallEvent (event); doesn't work when the onPluginMessageReceived method is called