mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-16 08:56:04 +01:00
Implement an event handler
This commit is contained in:
33
src/main/java/emu/grasscutter/server/event/Event.java
Normal file
33
src/main/java/emu/grasscutter/server/event/Event.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package emu.grasscutter.server.event;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
|
||||
/**
|
||||
* A generic server event.
|
||||
*/
|
||||
public abstract class Event {
|
||||
private boolean cancelled = false;
|
||||
|
||||
/**
|
||||
* Return the cancelled state of the event.
|
||||
*/
|
||||
public boolean isCanceled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the event if possible.
|
||||
*/
|
||||
public void cancel() throws IllegalAccessException {
|
||||
if(!(this instanceof Cancellable))
|
||||
throw new IllegalAccessException("Event is not cancellable.");
|
||||
this.cancelled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes this event to all listeners.
|
||||
*/
|
||||
public void call() {
|
||||
Grasscutter.getPluginManager().invokeEvent(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user