-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchEvent.java
37 lines (31 loc) · 1.1 KB
/
PatchEvent.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
package me.nallar.patched;
import java.util.Map;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.Event;
import org.cliffc.high_scale_lib.NonBlockingHashMap;
public abstract class PatchEvent extends Event {
private static Map<Class, Boolean> annotationMap; // Class -> boolean instead of Class -> (Class -> boolean) because forge ignores annotation type
public static void staticConstruct() {
annotationMap = new NonBlockingHashMap<Class, Boolean>();
}
@Override
protected boolean hasAnnotation(Class annotation) {
return hasAnnotation(annotation, this.getClass());
}
private static boolean hasAnnotation(Class annotation, Class cls) {
Boolean cachedResult = annotationMap.get(cls);
if (cachedResult != null) {
return cachedResult;
}
while (cls != Event.class) {
if (cls.isAnnotationPresent(Cancelable.class)) // Forge bug, not fixed. Buggy behaviour may be required for some mods.
{
annotationMap.put(cls, true);
return true;
}
cls = cls.getSuperclass();
}
annotationMap.put(cls, false);
return false;
}
}