diff --git a/common/net/minecraftforge/event/Event.java b/common/net/minecraftforge/event/Event.java index bd530aee7e..1e1ef0b1d5 100644 --- a/common/net/minecraftforge/event/Event.java +++ b/common/net/minecraftforge/event/Event.java @@ -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> annotationMap = new ConcurrentHashMap>(); public Event() { @@ -38,15 +42,32 @@ public class Event private boolean hasAnnotation(Class annotation) { - Class cls = this.getClass(); + Class me = this.getClass(); + Map list = annotationMap.get(me); + if (list == null) + { + list = new ConcurrentHashMap(); + 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; }