mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 12:20:11 +00:00
Fixed issue with Event.hasAnnotation ignoring it's parameter. And cached its values for potential performance gain. Closes #482
This commit is contained in:
1 parent
891527883e
commit
9bb558078b
1 file changed
+23
-2
@@ -5,6 +5,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
/**
|
||||
@@ -28,6 +30,8 @@ public class Event
|
||||
private Result result = Result.DEFAULT;
|
||||
private final boolean hasResult;
|
||||
private static ListenerList listeners = new ListenerList();
|
||||
|
||||
private static final Map<Class, Map<Class, Boolean>> annotationMap = new ConcurrentHashMap<Class, Map<Class, Boolean>>();
|
||||
|
||||
public Event()
|
||||
{
|
||||
@@ -38,15 +42,32 @@ public class Event
|
||||
|
||||
private boolean hasAnnotation(Class annotation)
|
||||
{
|
||||
Class cls = this.getClass();
|
||||
Class me = this.getClass();
|
||||
Map<Class, Boolean> list = annotationMap.get(me);
|
||||
if (list == null)
|
||||
{
|
||||
list = new ConcurrentHashMap<Class, Boolean>();
|
||||
annotationMap.put(me, list);
|
||||
}
|
||||
|
||||
Boolean cached = list.get(annotation);
|
||||
if (cached != null)
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
Class cls = me;
|
||||
while (cls != Event.class)
|
||||
{
|
||||
if (cls.isAnnotationPresent(Cancelable.class))
|
||||
if (cls.isAnnotationPresent(annotation))
|
||||
{
|
||||
list.put(annotation, true);
|
||||
return true;
|
||||
}
|
||||
cls = cls.getSuperclass();
|
||||
}
|
||||
|
||||
list.put(annotation, false);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user