/
Event.java
69 lines (62 loc) · 2.33 KB
/
Event.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package net.ME1312.Galaxi.Library.Event;
import net.ME1312.Galaxi.Galaxi;
import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Plugin.PluginInfo;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;
/**
* SubEvent Layout Class
*/
public abstract class Event {
private PluginInfo plugin = null;
/**
* Get the Galaxi Engine API
*
* @return Get the Galaxi Engine API
*/
public Galaxi getEngine() {
return Galaxi.getInstance();
}
/**
* Gets your Plugin's Info
*
* @return Plugin Info
*/
public PluginInfo getPlugin() {
return plugin;
}
/**
* Get the handlers for this event
*
* @return Handler Map
*/
@SuppressWarnings({"deprecation", "unchecked"})
public Map<PluginInfo, List<Method>> getHandlers() throws IllegalAccessException {
try {
TreeMap<Short, HashMap<Class<? extends Event>, HashMap<PluginInfo, HashMap<Object, List<Method>>>>> listeners = Util.reflect(Class.forName("net.ME1312.Galaxi.Engine.PluginManager").getDeclaredField("listeners"), getEngine());
HashMap<PluginInfo, List<Method>> map = new LinkedHashMap<PluginInfo, List<Method>>();
for (Short order : listeners.keySet()) {
if (!listeners.get(order).keySet().contains(getClass())) continue;
for (PluginInfo plugin : listeners.get(order).get(getClass()).keySet()) {
for (Object listener : listeners.get(order).get(getClass()).get(plugin).keySet()) {
for (Method method : listeners.get(order).get(getClass()).get(plugin).get(listener)) {
List<Method> methods = (map.keySet().contains(plugin))?map.get(plugin):new LinkedList<Method>();
methods.add(method);
map.put(plugin, methods);
}
}
}
}
return map;
} catch (Exception e) {
getEngine().getAppInfo().getLogger().error.println(new InvocationTargetException(e, "Couldn't get handler list for event: " + toString()));
return null;
}
}
@Override
public String toString() {
return getClass().getTypeName();
}
}