package nallar.patched.forge;

import nallar.collections.PartiallySynchronizedMap;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.Event;

public abstract class PatchEvent extends Event {
	private static final PartiallySynchronizedMap<Class, Boolean> annotationMap = new PartiallySynchronizedMap<Class, Boolean>();

	@Override
	protected boolean hasAnnotation(Class annotation) {
		Class cls = this.getClass();
		Boolean cachedResult = annotationMap.get(cls);
		if (cachedResult != null) {
			return cachedResult;
		}
		Class searchClass = cls;
		while (searchClass != Event.class) {
			if (searchClass.isAnnotationPresent(Cancelable.class)) // TODO: Forge bug, not fixed. Buggy behaviour may be required for some mods.
			{
				annotationMap.put(cls, true);
				return true;
			}
			searchClass = searchClass.getSuperclass();
		}
		annotationMap.put(cls, false);
		return false;
	}
}

@@ -83,53 +83,8 @@
 p;%0D%0A
-import net.minecraftforge.event.Cancelable;%0D%0A
 impo
@@ -216,32 +216,64 @@
 onizedMap%3CClass,
+ PartiallySynchronizedMap%3CClass,
  Boolean%3E annota
@@ -265,16 +265,17 @@
 Boolean%3E
+%3E
  annotat
@@ -310,32 +310,64 @@
 onizedMap%3CClass,
+ PartiallySynchronizedMap%3CClass,
  Boolean%3E();%0D%0A%0D%0A
@@ -359,16 +359,17 @@
 Boolean%3E
+%3E
 ();%0D%0A%0D%0A%09
@@ -471,31 +471,163 @@
 %0D%0A%09%09
-Boolean cachedResult = 
+PartiallySynchronizedMap%3CClass, Boolean%3E map = annotationMap.get(cls);%0D%0A%09%09if (map == null) %7B%0D%0A%09%09%09map = new PartiallySynchronizedMap%3CClass, Boolean%3E();%0D%0A%09%09%09
 anno
@@ -628,39 +628,96 @@
 %09%09annotationMap.
-ge
+pu
 t(cls
+, map);%0D%0A%09%09%7D%0D%0A%09%09Boolean cachedResult = map.get(annotation
 );%0D%0A%09%09if (cached
@@ -876,137 +876,46 @@
 ent(
-C
 an
-celable.class)) // TODO: Forge bug, not fixed. Buggy behaviour may be required for some mods.%0D%0A%09%09%09%7B%0D%0A%09%09%09%09annotationMap.put(cls
+notation)) %7B%0D%0A%09%09%09%09map.put(annotation
 , tr
@@ -998,16 +998,24 @@
 %0A%09%09%7D%0D%0A%09%09
+map.put(
 annotati
@@ -1016,27 +1016,16 @@
 notation
-Map.put(cls
 , false)

Update PatchEvent for Forge changes - no longer ignores the annotation parameter of hasAnnotation.