Skip to content
This repository was archived by the owner on Aug 2, 2026. It is now read-only.

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Regular-Event-System

How to use

creating events: CustomEvent.class

public final class CustomEvent extends Event {

  private Object object;

  public CustomEvent(Object object) {
    this.object = object;
  }

  public Object getObject() {
    return this.object;
  }

  public void setObject(Object object) {
    this.object = object;
  }
}

listening events:

public final class YourClass {

  public void start() {
    Start.EVENT_DISPATCHER.register(this::onEvent);
  }

  public void stop() {
    Start.EVENT_DISPATCHER.unregister(this::onEvent);
  }

  public void onEvent(EventHolder<CustomEvent> eventHolder) {
    System.out.println(eventHolder.getEvent().getObject());
  }
}

execute events:

public final class Start {

  public static final EventDispatcher EVENT_DISPATCHER = new EventDispatcher();

  public static void main(String[] args] {
    YourClass application = new YourClass();
    EVENT_DISPATCHER.execute(new EventHolder<>(new CustomEvent((Object) "KekW")));

    application.start();

    Runtime.getRuntime().addShutdownHook(new Thread(application::stop));
  }

}

You need to initialize your EventDispatcher. We do this mostly in the main or start class of your application.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages