mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Try harder to find a mod container.
This commit is contained in:
1 parent
544320b8d2
commit
ab199c5811
5 files changed
+63
-2
No files matched your search
@@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
@@ -55,6 +56,7 @@ public class LoadController
|
||||
private List<ModContainer> activeModList = Lists.newArrayList();
|
||||
private ModContainer activeContainer;
|
||||
private BiMap<ModContainer, Object> modObjectList;
|
||||
private ListMultimap<String, ModContainer> packageOwners;
|
||||
|
||||
public LoadController(Loader loader)
|
||||
{
|
||||
@@ -63,7 +65,7 @@ public class LoadController
|
||||
this.masterChannel.register(this);
|
||||
|
||||
state = LoaderState.NOINIT;
|
||||
|
||||
packageOwners = ArrayListMultimap.create();
|
||||
|
||||
}
|
||||
|
||||
@@ -171,7 +173,7 @@ public class LoadController
|
||||
|
||||
public ModContainer activeContainer()
|
||||
{
|
||||
return activeContainer;
|
||||
return activeContainer != null ? activeContainer : findActiveContainerFromStack();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -229,6 +231,11 @@ public class LoadController
|
||||
if (!mc.isImmutable() && mc.getMod()!=null)
|
||||
{
|
||||
builder.put(mc, mc.getMod());
|
||||
List<String> packages = mc.getOwnedPackages();
|
||||
for (String pkg : packages)
|
||||
{
|
||||
packageOwners.put(pkg, mc);
|
||||
}
|
||||
}
|
||||
if (mc.getMod()==null && !mc.isImmutable() && state!=LoaderState.CONSTRUCTING)
|
||||
{
|
||||
@@ -309,4 +316,37 @@ public class LoadController
|
||||
{
|
||||
this.state = newState;
|
||||
}
|
||||
|
||||
private ModContainer findActiveContainerFromStack()
|
||||
{
|
||||
for (Class<?> c : getCallingStack())
|
||||
{
|
||||
int idx = c.getName().lastIndexOf('.');
|
||||
if (idx == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String pkg = c.getName().substring(0,idx);
|
||||
if (packageOwners.containsKey(pkg))
|
||||
{
|
||||
return packageOwners.get(pkg).get(0);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private FMLSecurityManager accessibleManager = new FMLSecurityManager();
|
||||
|
||||
class FMLSecurityManager extends SecurityManager
|
||||
{
|
||||
Class<?>[] getStackClasses()
|
||||
{
|
||||
return getClassContext();
|
||||
}
|
||||
}
|
||||
|
||||
Class<?>[] getCallingStack()
|
||||
{
|
||||
return accessibleManager.getStackClasses();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user