2013-12-27 23:59:59 +01:00
package appeng.integration ;
import java.lang.reflect.Field ;
import appeng.api.exceptions.ModNotInstalled ;
2014-02-09 06:08:27 +01:00
import appeng.core.AEConfig ;
2014-02-09 19:35:35 +01:00
import appeng.core.AELog ;
2013-12-27 23:59:59 +01:00
import cpw.mods.fml.common.Loader ;
public class IntegrationNode
{
IntegrationStage state = IntegrationStage . PREINIT ;
IntegrationStage failedStage = IntegrationStage . PREINIT ;
Throwable exception = null ;
String displayName ;
String modID ;
2014-07-24 00:26:23 +02:00
IntegrationType shortName ;
2013-12-27 23:59:59 +01:00
String name = null ;
Class classValue = null ;
Object instance ;
IIntegrationModule mod = null ;
2014-07-24 00:26:23 +02:00
public IntegrationNode ( String dspname , String _modID , IntegrationType sName , String n ) {
2013-12-27 23:59:59 +01:00
displayName = dspname ;
shortName = sName ;
modID = _modID ;
name = n ;
}
void Call ( IntegrationStage stage )
{
2014-04-06 08:55:24 +02:00
if ( state ! = IntegrationStage . FAILED )
2013-12-27 23:59:59 +01:00
{
2014-04-06 08:55:24 +02:00
if ( state . ordinal ( ) > stage . ordinal ( ) )
return ;
2013-12-27 23:59:59 +01:00
try
{
switch ( stage )
{
case PREINIT :
boolean enabled = modID = = null | | Loader . isModLoaded ( modID ) ;
2014-02-09 06:08:27 +01:00
AEConfig . instance
2013-12-27 23:59:59 +01:00
. addCustomCategoryComment (
" ModIntegration " ,
" Valid Values are 'AUTO', 'ON', or 'OFF' - defaults to 'AUTO' ; Suggested that you leave this alone unless your experiencing an issue, or wish to disable the integration for a reason. " ) ;
2014-02-09 06:08:27 +01:00
String Mode = AEConfig . instance . get ( " ModIntegration " , displayName . replace ( " " , " " ) , " AUTO " ) . getString ( ) ;
2013-12-27 23:59:59 +01:00
if ( Mode . toUpperCase ( ) . equals ( " ON " ) )
enabled = true ;
if ( Mode . toUpperCase ( ) . equals ( " OFF " ) )
enabled = false ;
if ( enabled )
{
classValue = getClass ( ) . getClassLoader ( ) . loadClass ( name ) ;
mod = ( IIntegrationModule ) classValue . getConstructor ( ) . newInstance ( ) ;
Field f = classValue . getField ( " instance " ) ;
f . set ( classValue , instance = mod ) ;
}
else
throw new ModNotInstalled ( modID ) ;
break ;
case INIT :
mod . Init ( ) ;
break ;
case POSTINIT :
mod . PostInit ( ) ;
break ;
case FAILED :
default :
break ;
}
}
catch ( Throwable t )
{
failedStage = stage ;
exception = t ;
state = IntegrationStage . FAILED ;
}
}
if ( stage = = IntegrationStage . POSTINIT )
{
if ( state = = IntegrationStage . FAILED )
{
AELog . info ( displayName + " - Integration Disabled " ) ;
if ( ! ( exception instanceof ModNotInstalled ) )
2014-02-09 19:35:35 +01:00
AELog . integration ( exception ) ;
2013-12-27 23:59:59 +01:00
}
else
{
AELog . info ( displayName + " - Integration Enable " ) ;
}
}
}
public boolean isActive ( )
{
2014-04-06 08:55:24 +02:00
if ( state = = IntegrationStage . PREINIT )
Call ( IntegrationStage . PREINIT ) ;
2013-12-27 23:59:59 +01:00
return state ! = IntegrationStage . FAILED ;
}
}