package me.nallar.patched.forge;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.Event;

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 ConcurrentHashMap<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;
		}
		Class searchClass = cls;
		while (searchClass != Event.class) {
			if (searchClass.isAnnotationPresent(Cancelable.class)) // 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;
	}
}

@@ -33,31 +33,8 @@
 %0D%0A%0D%0A
-import java.util.Map;%0D%0A
 impo
@@ -77,16 +77,16 @@
 shMap;%0D%0A
+
 %0D%0Aimport
@@ -232,16 +232,30 @@
  static 
+ConcurrentHash
 Map%3CClas
@@ -560,134 +560,36 @@
 %0D%0A%09%09
-return hasAnnotation(annotation, this.getClass());%0D%0A%09%7D%0D%0A%0D%0A%09private static boolean hasAnnotation(Class annotation, Class cls) %7B
+Class cls = this.getClass();
 %0D%0A%09%09

Simplify PatchEvent