From 7a63e67e9d493bf4fcd6365981ce98b7d622d5fd Mon Sep 17 00:00:00 2001 From: LexManos Date: Sun, 9 Oct 2016 12:36:21 -0700 Subject: [PATCH] Revert commits related to filtering proxy and Automatic Subscriber annotations. Broke some existing setups, will require a annotation definition change in 1.11. --- .../fml/common/AutomaticEventSubscriber.java | 18 ------ .../fml/common/ProxyInjector.java | 61 ++----------------- 2 files changed, 5 insertions(+), 74 deletions(-) diff --git a/src/main/java/net/minecraftforge/fml/common/AutomaticEventSubscriber.java b/src/main/java/net/minecraftforge/fml/common/AutomaticEventSubscriber.java index 230abe471b..d1fe342581 100644 --- a/src/main/java/net/minecraftforge/fml/common/AutomaticEventSubscriber.java +++ b/src/main/java/net/minecraftforge/fml/common/AutomaticEventSubscriber.java @@ -51,24 +51,6 @@ public class AutomaticEventSubscriber { try { - //Filter out handlers for things that arnt this mod. - //Perhaps find a way to make this more generic for multiple mods - //from the same source.... - boolean register = true; - for (ASMData a : data.getAll(Mod.class.getName())) - { - if (a.getClassName().equals(targ.getClassName())) - { - if (!mod.getModId().equals(a.getAnnotationInfo().get("modid"))) - { - register = false; - break; - } - } - } - if (!register) - continue; - //noinspection unchecked List sidesEnum = (List)targ.getAnnotationInfo().get("value"); EnumSet sides = DEFAULT; diff --git a/src/main/java/net/minecraftforge/fml/common/ProxyInjector.java b/src/main/java/net/minecraftforge/fml/common/ProxyInjector.java index d159168d08..9c6669467f 100644 --- a/src/main/java/net/minecraftforge/fml/common/ProxyInjector.java +++ b/src/main/java/net/minecraftforge/fml/common/ProxyInjector.java @@ -47,30 +47,6 @@ public class ProxyInjector { try { - //Pull this from the ASM data so we do not prematurely initialize mods with the below Class.forName - String modid = (String)targ.getAnnotationInfo().get("modId"); - if (modid == null) - { - for (ASMData a : data.getAll(Mod.class.getName())) - { - if (isProxyFromMod(a.getClassName(), targ.getClassName())) - { - modid = (String)a.getAnnotationInfo().get("modid"); - break; - } - } - } - - if (modid == null) - { - FMLLog.warning("Unable to determine the associated mod for proxy injection for %s.%s, assuming it's from %s", targ.getClassName(), targ.getObjectName(), mod.getModId()); - } - else if (!modid.equals(mod.getModId())) - { - FMLLog.fine("Skipping proxy injection for %s.%s since it is not for mod %s, it should belong to %s", targ.getClassName(), targ.getObjectName(), mod.getModId(), modid); - continue; - } - Class proxyTarget = Class.forName(targ.getClassName(), true, mcl); Field target = proxyTarget.getDeclaredField(targ.getObjectName()); if (target == null) @@ -82,6 +58,11 @@ public class ProxyInjector target.setAccessible(true); SidedProxy annotation = target.getAnnotation(SidedProxy.class); + if (!Strings.isNullOrEmpty(annotation.modId()) && !annotation.modId().equals(mod.getModId())) + { + FMLLog.fine("Skipping proxy injection for %s.%s since it is not for mod %s", targ.getClassName(), targ.getObjectName(), mod.getModId()); + continue; + } String targetType = side.isClient() ? annotation.clientSide() : annotation.serverSide(); if(targetType.equals("")) { @@ -111,36 +92,4 @@ public class ProxyInjector // Allow language specific proxy injection. languageAdapter.setInternalProxies(mod, side, mcl); } - - /** - * Checks if a proxy is part of a mod. - * - * Checks that the proxy is somewhere in the same package that holds the mod. - * For example, the @Mod is 'com.modname.Mod', the Proxy is 'com.modname.proxies.ProxyClient' - * The package of the mod is 'com.modname', and Proxy is in that package, so it is from the mod. - * - * Compares each path section in a for loop instead of simply using {@link String#startsWith(String)} - * because a mod like 'com.modname.Mod' with package 'com.modname' - * does not own a proxy from 'com.modnametools.proxies.ProxyClient' even though they start the same. - */ - private static boolean isProxyFromMod(String modClassName, String proxyClassName) - { - if (modClassName.equals(proxyClassName)) - return true; - - String[] modPath = modClassName.split("\\."); - String[] proxyPath = proxyClassName.split("\\."); - if (proxyPath.length < modPath.length) - return false; - - for (int i = 0; i < modPath.length - 1; i++) - { - if (!modPath[i].equals(proxyPath[i])) - { - return false; - } - } - - return true; - } }