Skip to content

Basic Events

cyklon73 edited this page Apr 11, 2024 · 1 revision

You can create a custom event by extending the Event class

public class MyEvent extends Event {

}

you can define a name for your event using the super constructor

public MyEvent() {
	super("MyEventName");
}

if you do not want to specify a name, the class name is automatically used

public MyEvent() [
	super();
}

to make your event more meaningful, you can define variables with associated getters and setters, which can then be edited when the event is called up. These variables are initialized via the constructor when the event is created

private String name;

public MyEvent(String name) {
	super("MyEventName");
	this.name = name;
}

public String getName() {
	return name;
}

public void setName(String name) {
	this.name = name;
}

you can also add final variable with associated getter to make data retrievable in the event but which cannot be edited

private final UUID id;

public MyEvent(UUID id) {
	this.id = id;
}

public UUID getId() {
	return id;
}

Example

public class MyEvent extends Event {
	private final UUID id;
	private String name;

	public MyEvent(UUID id, String name) {
		super("MyEventName");
		this.id = id;
		this.name = name;
	}

	public UUID getId() {
		return id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
Clone this wiki locally