> For the complete documentation index, see [llms.txt](https://smuddgge.gitbook.io/kerb/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://smuddgge.gitbook.io/kerb/developer-api/events.md).

# 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!

{% code title="Example" overflow="wrap" %}

```java
/**
 * 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;
    }
}
```

{% endcode %}

## Listening to Events

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

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

You can also listen to all events.

```java
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.

{% code title="" overflow="wrap" %}

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


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

{% endcode %}
