Skip to content

Bungee Data Sending and Receiving

Dawson edited this page Oct 21, 2019 · 3 revisions

Sending Data Across Servers

You can send data across servers using the BungeeManager#sendObjects method. You do not need the AtlasBungee addon for this functionality.

Method Information

Important Note: All arguments except "ALL_OVERRIDE" will not send to servers without players online.

Server Argument Requires AtlasBungee Plugin Channel(s) Used Functionality
ALL No Forward Sends objects to all Bungee slaves with Atlas.
ALL_OVERRIDE Yes atlasOut, atlasIn Sends objects to all Bungee slaves with Atlas even though no players are online.
ONLINE No Forward Sends objects to all online Bungee slaves with Atlas.
[Bungee Slave Name] No Forward Sends objects to one specific Bungee server.
[Bungee Slave Name]_OVERRIDE Yes Sends objects to one specific Bungee server even though no players are online.

Example

This is how I use this functionality in Kauri. Here, I am sending a player's UUID, the check name, the player's check violation count, and the specific information a check outputs.

public void flag(String information) {
        final String info = information
                .replace("%p", 
                     String.valueOf(data.lagInfo.ping))
                .replace("%t", 
                     String.valueOf(MathUtils.round(Kauri.INSTANCE.tps, 2)));
        if(Config.bungeeAlerts) {
            try {
                Atlas.getInstance().getBungeeManager()
                        .sendObjects("ALL", 
                                data.getPlayer().getUniqueId(),
                                checkName,
                                MathUtils.round(vl, 2), 
                                info);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
}

Receiving Data Sent

You can use the BungeeReceiveEvent AtlasEvent to receive the data sent.

Event Information

Field Return Type Information
BungeeReceiveEvent.type String Outputs the channel received.
BungeeReceiveEvent.objects[] Object[] The objects sent with the BungeeManager#sendObjects method.

Example

Here, you will receive the objects in an array formatted in exactly the same order called like in the example above.

@Init
public class BungeeListener implements AtlasListener, Listener {
    
    @Listen
    public void onBungee(BungeeReceiveEvent event) {
        if(!Config.bungeeAlerts || event.objects.length != 4) return;
        UUID uuid = (UUID)event.objects[0];
        String checkName = (String)event.objects[1];
        CheckEntry entry = new CheckEntry(uuid, checkName);
        float vl = (float)event.objects[2];
        String info = (String)event.objects[3];
        
    }
    
}
Clone this wiki locally