Events

Creating Events

To create an event, you create a new class and implement Event. You can then add as man variables and methods to interact with the event as you like!

Example
/**
 * Represents a simple ping event.
 * This is used as an example.
 */
public class PingEvent extends Event {

    private @NotNull String serverName;

    /**
     * Used to create a ping event.
     *
     * @param serverName The server that the ping was sent from.
     */
    public PingEvent(@NotNull String serverName) {
        this.serverName = serverName;
    }

    /**
     * Used to get the name of the server
     * the event was sent from.
     *
     * @return The name of the server.
     */
    public @NotNull String getServerName() {
        return this.serverName;
    }
}

Listening to Events

When a client calls a PingEvent it will be sent here.

client.registerListener((EventListener<PingEvent>) event -> {
    String serverName = event.getServerName();
    System.out.println(serverName);
    return event;
});

You can also listen to all events.

client.registerListener((EventListener<Event>) event -> {
    System.out.println(event.getIdentifier());
    return event;
});

You can also make categories of events with inheritance and listen to the inherited event class!

Calling Events

This event will be sent to all clients. You can then wait for the results the clients have returned.

CompletableResultSet<PingEvent> resultCollection = client
        .callEvent(new PingEvent("Computer Name"));


// Wait for the final result.
List<PingEvent> result = resultCollection.waitForFinalResult();

Last updated