Added copyrights
Reformated code Rearrnaged code Changed the integration registry into a real singleton independent about its instantiation by other classes
This commit is contained in:
@@ -1,17 +1,37 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
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>();
|
||||
|
||||
public void add( IntegrationType type)
|
||||
public void add( IntegrationType type )
|
||||
{
|
||||
if ( type.side == IntegrationSide.CLIENT && FMLLaunchHandler.side() == Side.SERVER )
|
||||
return;
|
||||
@@ -22,22 +42,18 @@ public class IntegrationRegistry
|
||||
modules.add( new IntegrationNode( type.dspName, type.modID, type, "appeng.integration.modules." + type.name() ) );
|
||||
}
|
||||
|
||||
public IntegrationRegistry() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
for (IntegrationNode node : modules)
|
||||
for ( IntegrationNode node : modules )
|
||||
node.Call( IntegrationStage.PRE_INIT );
|
||||
|
||||
for (IntegrationNode node : modules)
|
||||
for ( IntegrationNode node : modules )
|
||||
node.Call( IntegrationStage.INIT );
|
||||
}
|
||||
|
||||
public void postInit()
|
||||
{
|
||||
for (IntegrationNode node : modules)
|
||||
for ( IntegrationNode node : modules )
|
||||
node.Call( IntegrationStage.POST_INIT );
|
||||
}
|
||||
|
||||
@@ -45,9 +61,9 @@ public class IntegrationRegistry
|
||||
{
|
||||
String out = null;
|
||||
|
||||
for (IntegrationNode node : modules)
|
||||
for ( IntegrationNode node : modules )
|
||||
{
|
||||
String str = node.shortName + ":" + (node.state == IntegrationStage.FAILED ? "OFF" : "ON");
|
||||
String str = node.shortName + ":" + ( node.state == IntegrationStage.FAILED ? "OFF" : "ON" );
|
||||
|
||||
if ( out == null )
|
||||
out = str;
|
||||
@@ -58,9 +74,9 @@ public class IntegrationRegistry
|
||||
return out;
|
||||
}
|
||||
|
||||
public boolean isEnabled(IntegrationType name)
|
||||
public boolean isEnabled( IntegrationType name )
|
||||
{
|
||||
for (IntegrationNode node : modules)
|
||||
for ( IntegrationNode node : modules )
|
||||
{
|
||||
if ( node.shortName == name )
|
||||
return node.isActive();
|
||||
@@ -68,16 +84,16 @@ public class IntegrationRegistry
|
||||
return false;
|
||||
}
|
||||
|
||||
public Object getInstance(IntegrationType name)
|
||||
public Object getInstance( IntegrationType name )
|
||||
{
|
||||
for (IntegrationNode node : modules)
|
||||
for ( IntegrationNode node : modules )
|
||||
{
|
||||
if ( node.shortName.equals( name ) && node.isActive() )
|
||||
{
|
||||
return node.instance;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException( "integration with "+name.name()+" is disabled." );
|
||||
throw new RuntimeException( "integration with " + name.name() + " is disabled." );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user