Class Event

java.lang.Object
civitas.celestis.event.Event
All Implemented Interfaces:
Handleable, Unique<UUID>
Direct Known Subclasses:
ApplicationEvent, CancellableEvent, NotificationEvent

public class Event extends Object implements Handleable
The default implementation of Handleable. This class serves as the superclass for all events.

Serialization Standards

This section summarizes the standards subclasses of this class should meet in order to be properly serialized by Events.toString(Handleable). If these standards are to be ignored, toString() must be overridden to properly print a string representation of the specific event. The default serialization standards will be used if not overridden.

All fields will be serialized, along with their values separated by an equals sign. ("=") If the field is not public, the serializer will attempt to find its getter method. The getter method should be in the format of "get" followed by its field's name with its first letter capitalized. Getter methods must also have no parameters.

For example, the getter method for a variable content would be getContent(), which takes no parameters and returns the type of content.
protected final String content;
public String getContent() {
  return content;
}

For booleans, the getter convention is "is" followed by the field's name with its first letter capitalized. (e.g. cancelled will be isCancelled())

As long as these standards are met, the serializer will automatically serialize the event, eliminating the need to implement toString() for every event.

See Also:
  • Field Details

    • uniqueId

      @Nonnull protected final UUID uniqueId
      The unique identifier of this event.
    • cause

      @Nullable protected final Handleable cause
      The cause of this event.
  • Constructor Details

    • Event

      public Event()
      Creates a new event with a random unique identifier and no cause.
    • Event

      public Event(@Nonnull UUID uniqueId)
      Creates a new event with no cause.
      Parameters:
      uniqueId - The unique identifier of this event
    • Event

      public Event(@Nullable Handleable cause)
      Creates a new event with a random unique identifier.
      Parameters:
      cause - The cause of this event
    • Event

      public Event(@Nonnull UUID uniqueId, @Nullable Handleable cause)
      Creates a new event.
      Parameters:
      uniqueId - The unique identifier of this event
      cause - The cause of this event
  • Method Details

    • getUniqueId

      @Nonnull public UUID getUniqueId()
      Returns the unique identifier of this event.
      Specified by:
      getUniqueId in interface Handleable
      Specified by:
      getUniqueId in interface Unique<UUID>
      Returns:
      The unique identifier of this event
    • getCause

      @Nullable public Handleable getCause()
      Returns the cause of this event. If no cause was specified, this will return null.
      Specified by:
      getCause in interface Handleable
      Returns:
      The cause of this event if specified, null if not
    • toString

      @Nonnull public String toString()
      Serializes this event into a string for debugging purposes. This should be customized for events which add extra parameters.
      Overrides:
      toString in class Object
      Returns:
      The string representation of this event