Controller Messages

Talk to other controllers without reflection

Controllers can send packs of data between each other cross controller cross plugin without the classpath of the plugin with that controller. You just need to know the name

Sending a Controller Message

This creates a message and sends the message getting a response in return. This response will either contain more data, changed data, or the same data cluster if the controller diddnt return anything extra.

//Create a message (it's a data cluster)
ControllerMessage msg = new ControllerMessage(this);
msg.set("is", "loaded"); //Key Val string to ask if the other controller is loading

//Send the message
ControllerMessage response = sendMessage("TheController", msg);

if(response.contains("result", ClusterDataType.BOOLEAN))
{
    boolean loaded = response.getBoolean("result");
}

Listening for Controller Messages

Here we can listen for controller messages. Never Return null. If you dont want to return data, simply return the message.

//We override this in a controller
@Override
public ControllerMessage onControllerMessageRecieved(ControllerMessage message)
{
    //We do a safe check
    if(message.contains("is", ClusterDataType.STRING))
    {
        //And check if the is is equal to loaded
        if(message.getString("is").equalsIgnoreCase("loaded"))
        {
            //We will just respond true every time
            message.set("result", true);
        }
    }

    //Always return the message
    return message;
}

results matching ""

    No results matching ""