Handling client messages

You can handle a client message by listening to the Bukkit/Bungeecord event we provide which is called MessageReceiveEvent.
This example refers to this example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
@EventHandler
public void onMessageReceive( MessageReceiveEvent event ) {
    Player player = event.getPlayer();
    JsonElement jsonElement = event.getJsonElement();

    // Checking whether we received the options
    if( event.getMessageKey().equals( "EXAMPLE-Options" ) || !jsonElement.isJsonObject() )
        return;

    JsonObject optionsObject = jsonElement.getAsJsonObject();
    JsonPrimitive randomOption = optionsObject.has( "randomOption" ) && optionsObject.get( "randomOption" ).isJsonPrimitive() ? 
        optionsObject.get("randomOption").getAsJsonPrimitive() : null;

    // Checking whether "randomOption" is present and a boolean
    if( randomOption != null && randomOption.isJsonBoolean() ) {
        // Setting the value in our backend
        TestPlugin.getInstance().setRandomOption( player, randomOption.getAsBoolean() );
    }
}