Sending messages to clients

The Server API allows you to send JSON messages to the client that it can handle. Every message has got a key that makes it possible to easily identify it. Use the method LabyModPlugin#sendServerMessage( Player player, String messageKey, JsonElement messageContents ) to send those messages. You can see here how the following example message could be handled.

Example:

1
2
3
4
5
6
7
8
public void updatePoints( Player player, int points ) {
    // Constructing the JsonObject we want to send to the client
    JsonObject pointsObject = new JsonObject();
    pointsObject.addProperty( "points", points );

    // Sending the server message
    LabyModPlugin.getInstance().sendServerMessage( player, "EXAMPLE-Points", pointsObject );
}