Merge pull request #426 from thatsIch/IntegrationRegistry

Changed the integration registry into a real singleton independent about its instantiation by other classes
This commit is contained in:
thatsIch
2014-11-13 15:22:40 +01:00
4 changed files with 174 additions and 99 deletions
+41 -20
View File
@@ -1,9 +1,44 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core; package appeng.core;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import com.google.common.base.Stopwatch;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import appeng.api.config.TunnelType; import appeng.api.config.TunnelType;
import appeng.core.api.IIMCHandler; import appeng.core.api.IIMCHandler;
import appeng.core.api.imc.IMCBlackListSpatial; import appeng.core.api.imc.IMCBlackListSpatial;
@@ -23,21 +58,6 @@ import appeng.server.AECommand;
import appeng.services.VersionChecker; import appeng.services.VersionChecker;
import appeng.util.Platform; import appeng.util.Platform;
import com.google.common.base.Stopwatch;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
@Mod( modid = AppEng.modid, acceptedMinecraftVersions = "[1.7.10]", name = AppEng.name, version = AEConfig.VERSION, dependencies = AppEng.dependencies, guiFactory = "appeng.client.gui.config.AEConfigGuiFactory" ) @Mod( modid = AppEng.modid, acceptedMinecraftVersions = "[1.7.10]", name = AppEng.name, version = AEConfig.VERSION, dependencies = AppEng.dependencies, guiFactory = "appeng.client.gui.config.AEConfigGuiFactory" )
public class AppEng public class AppEng
@@ -70,7 +90,8 @@ public class AppEng
+ net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion + net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion
+ net.minecraftforge.common.ForgeVersion.buildVersion + ",)"; // buildVersion + net.minecraftforge.common.ForgeVersion.buildVersion + ",)"; // buildVersion
public AppEng() { public AppEng()
{
instance = this; instance = this;
IMCHandlers.put( "blacklist-block-spatial", new IMCBlackListSpatial() ); IMCHandlers.put( "blacklist-block-spatial", new IMCBlackListSpatial() );
@@ -88,12 +109,12 @@ public class AppEng
public boolean isIntegrationEnabled( IntegrationType Name ) public boolean isIntegrationEnabled( IntegrationType Name )
{ {
return IntegrationRegistry.instance.isEnabled( Name ); return IntegrationRegistry.INSTANCE.isEnabled( Name );
} }
public Object getIntegration( IntegrationType Name ) public Object getIntegration( IntegrationType Name )
{ {
return IntegrationRegistry.instance.getInstance( Name ); return IntegrationRegistry.INSTANCE.getInstance( Name );
} }
private void startService( String serviceName, Thread thread ) private void startService( String serviceName, Thread thread )
@@ -144,7 +165,7 @@ public class AppEng
AELog.info( "Init" ); AELog.info( "Init" );
Registration.instance.Init( event ); Registration.instance.Init( event );
IntegrationRegistry.instance.init(); IntegrationRegistry.INSTANCE.init();
AELog.info( "Init ( end " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" ); AELog.info( "Init ( end " + star.elapsed( TimeUnit.MILLISECONDS ) + "ms )" );
} }
@@ -156,7 +177,7 @@ public class AppEng
AELog.info( "PostInit" ); AELog.info( "PostInit" );
Registration.instance.PostInit( event ); Registration.instance.PostInit( event );
IntegrationRegistry.instance.postInit(); IntegrationRegistry.INSTANCE.postInit();
FMLCommonHandler.instance().registerCrashCallable( new CrashEnhancement( CrashInfo.INTEGRATION ) ); FMLCommonHandler.instance().registerCrashCallable( new CrashEnhancement( CrashInfo.INTEGRATION ) );
CommonHelper.proxy.postInit(); CommonHelper.proxy.postInit();
@@ -1,8 +1,29 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core.crash; package appeng.core.crash;
import cpw.mods.fml.common.ICrashCallable;
import appeng.core.AEConfig; import appeng.core.AEConfig;
import appeng.integration.IntegrationRegistry; import appeng.integration.IntegrationRegistry;
import cpw.mods.fml.common.ICrashCallable;
public class CrashEnhancement implements ICrashCallable public class CrashEnhancement implements ICrashCallable
{ {
@@ -16,7 +37,8 @@ public class CrashEnhancement implements ICrashCallable
+ net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion + net.minecraftforge.common.ForgeVersion.revisionVersion + "." // revisionVersion
+ net.minecraftforge.common.ForgeVersion.buildVersion; + net.minecraftforge.common.ForgeVersion.buildVersion;
public CrashEnhancement(CrashInfo Output) { public CrashEnhancement( CrashInfo Output )
{
if ( Output == CrashInfo.MOD_VERSION ) if ( Output == CrashInfo.MOD_VERSION )
{ {
@@ -26,10 +48,7 @@ public class CrashEnhancement implements ICrashCallable
else if ( Output == CrashInfo.INTEGRATION ) else if ( Output == CrashInfo.INTEGRATION )
{ {
name = "AE2 Integration"; name = "AE2 Integration";
if ( IntegrationRegistry.instance != null ) value = IntegrationRegistry.INSTANCE.getStatus();
value = IntegrationRegistry.instance.getStatus();
else
value = "N/A";
} }
else else
{ {
@@ -1,14 +1,34 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.integration; package appeng.integration;
import java.util.LinkedList; import java.util.LinkedList;
import cpw.mods.fml.relauncher.FMLLaunchHandler; import cpw.mods.fml.relauncher.FMLLaunchHandler;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
public class IntegrationRegistry
{
public static IntegrationRegistry instance = null; public enum IntegrationRegistry
{
INSTANCE;
private final LinkedList<IntegrationNode> modules = new LinkedList<IntegrationNode>(); private final LinkedList<IntegrationNode> modules = new LinkedList<IntegrationNode>();
public void add( IntegrationType type ) public void add( IntegrationType type )
@@ -22,10 +42,6 @@ public class IntegrationRegistry
modules.add( new IntegrationNode( type.dspName, type.modID, type, "appeng.integration.modules." + type.name() ) ); modules.add( new IntegrationNode( type.dspName, type.modID, type, "appeng.integration.modules." + type.name() ) );
} }
public IntegrationRegistry() {
instance = this;
}
public void init() public void init()
{ {
for ( IntegrationNode node : modules ) for ( IntegrationNode node : modules )
@@ -1,10 +1,27 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.transformer.asm; package appeng.transformer.asm;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import net.minecraft.launchwrapper.IClassTransformer;
import org.apache.logging.log4j.Level; import org.apache.logging.log4j.Level;
import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
@@ -13,17 +30,19 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.MethodNode;
import net.minecraft.launchwrapper.IClassTransformer;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
import appeng.integration.IntegrationRegistry; import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType; import appeng.integration.IntegrationType;
import appeng.transformer.annotations.integration; import appeng.transformer.annotations.integration;
import cpw.mods.fml.relauncher.FMLRelaunchLog;
public class ASMIntegration implements IClassTransformer public class ASMIntegration implements IClassTransformer
{ {
public ASMIntegration()
private final IntegrationRegistry integrationModules = new IntegrationRegistry(); {
public ASMIntegration() {
/** /**
* Side, Display Name, ModID ClassPostFix * Side, Display Name, ModID ClassPostFix
@@ -31,7 +50,7 @@ public class ASMIntegration implements IClassTransformer
for ( IntegrationType type : IntegrationType.values() ) for ( IntegrationType type : IntegrationType.values() )
{ {
integrationModules.add( type ); IntegrationRegistry.INSTANCE.add( type );
} }
// integrationModules.add( IntegrationSide.BOTH, "Thermal Expansion", "ThermalExpansion", IntegrationType.TE ); // integrationModules.add( IntegrationSide.BOTH, "Thermal Expansion", "ThermalExpansion", IntegrationType.TE );
@@ -145,7 +164,7 @@ public class ASMIntegration implements IClassTransformer
if ( iName != null ) if ( iName != null )
{ {
IntegrationType type = IntegrationType.valueOf( iName ); IntegrationType type = IntegrationType.valueOf( iName );
if ( !IntegrationRegistry.instance.isEnabled( type ) ) if ( !IntegrationRegistry.INSTANCE.isEnabled( type ) )
{ {
log( "Removing Method " + mn.name + " from " + classNode.name + " because " + iName + " integration is disabled." ); log( "Removing Method " + mn.name + " from " + classNode.name + " because " + iName + " integration is disabled." );
i.remove(); i.remove();
@@ -182,7 +201,7 @@ public class ASMIntegration implements IClassTransformer
if ( iName != null && iFace != null ) if ( iName != null && iFace != null )
{ {
if ( !IntegrationRegistry.instance.isEnabled( type ) ) if ( !IntegrationRegistry.INSTANCE.isEnabled( type ) )
{ {
log( "Removing Interface " + iFace + " from " + classNode.name + " because " + iName + " integration is disabled." ); log( "Removing Interface " + iFace + " from " + classNode.name + " because " + iName + " integration is disabled." );
classNode.interfaces.remove( iFace.replace( '.', '/' ) ); classNode.interfaces.remove( iFace.replace( '.', '/' ) );