-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSEvents.java
49 lines (40 loc) · 1.28 KB
/
JSEvents.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.roguecircuitry.repcraft;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.event.Event;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityAirChangeEvent;
import org.bukkit.plugin.RegisteredListener;
import org.graalvm.polyglot.Value;
public class JSEvents implements Listener {
RepCraft master;
public List<JSEventListener> listeners;
public JSEvents(RepCraft master) {
this.master = master;
this.listeners = new ArrayList<JSEventListener>();
this.master.jsBinding.putMember("Events", this);
RegisteredListener registeredListener = new RegisteredListener(
this,
(listener, event) -> onEvent(event),
EventPriority.NORMAL,
master,
false
);
for (HandlerList handler : HandlerList.getHandlerLists()) {
handler.register(registeredListener);
}
}
public void onEvent (Event e) {
if (e instanceof EntityAirChangeEvent) return;
for (JSEventListener l : this.listeners) {
if (l.type.equals(e.getClass().getSimpleName())) {
l.func.execute(e);
}
}
}
public void on (Class classType, Value f) {
this.listeners.add(new JSEventListener(classType.getSimpleName(), f));
}
}