2011-05-15 19:33:03 +02:00
package com.Acrobot.ChestShop.Listeners ;
2011-05-15 18:16:25 +02:00
2011-05-16 17:35:12 +02:00
import com.Acrobot.ChestShop.ChestShop ;
2011-05-15 19:33:03 +02:00
import com.Acrobot.ChestShop.Economy ;
import com.Acrobot.ChestShop.Items.Odd ;
import com.Acrobot.ChestShop.Permission ;
2011-09-06 19:01:57 +02:00
import com.Acrobot.ChestShop.Protection.Plugins.DeadboltPlugin ;
2011-09-01 18:59:15 +02:00
import com.Acrobot.ChestShop.Protection.Plugins.LWCplugin ;
import com.Acrobot.ChestShop.Protection.Plugins.LockettePlugin ;
2011-05-15 19:33:03 +02:00
import com.Acrobot.ChestShop.Protection.Security ;
2011-09-22 15:56:06 +02:00
import com.Acrobot.ChestShop.Utils.uNumber ;
2011-09-23 14:07:20 +02:00
import com.Acrobot.ChestShop.Utils.uSign ;
2011-09-06 19:01:57 +02:00
import com.daemitus.deadbolt.Deadbolt ;
2011-05-15 18:16:25 +02:00
import com.griefcraft.lwc.LWCPlugin ;
import com.nijikokun.bukkit.Permissions.Permissions ;
2011-09-22 15:56:06 +02:00
import com.nijikokun.register.payment.forChestShop.Methods ;
import com.palmergames.bukkit.towny.Towny ;
2011-05-15 18:16:25 +02:00
import org.bukkit.event.server.PluginEnableEvent ;
import org.bukkit.event.server.ServerListener ;
import org.bukkit.plugin.Plugin ;
import org.bukkit.plugin.PluginDescriptionFile ;
import org.yi.acru.bukkit.Lockette.Lockette ;
/ * *
* @author Acrobot
* /
2011-05-29 13:25:25 +02:00
public class pluginEnable extends ServerListener {
2011-05-15 18:16:25 +02:00
2011-05-29 13:25:25 +02:00
public void onPluginEnable ( PluginEnableEvent event ) {
2011-09-06 19:01:57 +02:00
if ( ! Methods . hasMethod ( ) & & Methods . setMethod ( ChestShop . pm ) ) {
Economy . economy = Methods . getMethod ( ) ;
System . out . println ( ChestShop . chatPrefix + Economy . economy . getName ( ) + ' ' + Economy . economy . getVersion ( ) + " loaded. " ) ;
2011-05-15 18:16:25 +02:00
}
2011-09-06 19:01:57 +02:00
}
2011-05-15 18:16:25 +02:00
2011-09-06 19:01:57 +02:00
public static void initializePlugins ( ) {
for ( Object plugin : ChestShop . getDependencies ( ) ) {
Plugin pl = ChestShop . pm . getPlugin ( ( String ) plugin ) ;
if ( pl ! = null ) initializePlugin ( ( String ) plugin , pl ) ;
2011-05-15 18:16:25 +02:00
}
2011-08-13 12:08:34 +02:00
}
2011-05-15 18:16:25 +02:00
2011-08-13 12:08:34 +02:00
private static void initializePlugin ( String name , Plugin plugin ) { //Really messy, right? But it's short and fast :)
if ( name . equals ( " Permissions " ) ) {
if ( Permission . permissions ! = null ) return ;
Permission . permissions = ( ( Permissions ) plugin ) . getHandler ( ) ;
} else if ( name . equals ( " LWC " ) ) {
if ( LWCplugin . lwc ! = null ) return ;
2011-08-31 20:57:10 +02:00
LWCplugin . setLWC ( ( ( LWCPlugin ) plugin ) . getLWC ( ) ) ;
2011-08-13 12:08:34 +02:00
Security . protection = new LWCplugin ( ) ;
} else if ( name . equals ( " Lockette " ) ) {
2011-09-06 19:01:57 +02:00
if ( LockettePlugin . lockette ! = null ) return ;
LockettePlugin . lockette = ( Lockette ) plugin ;
Security . protection = new LockettePlugin ( ) ;
} else if ( name . equals ( " Deadbolt " ) ) {
if ( DeadboltPlugin . deadbolt ! = null ) return ;
DeadboltPlugin . deadbolt = ( Deadbolt ) plugin ;
Security . protection = new DeadboltPlugin ( ) ;
2011-08-13 12:08:34 +02:00
} else if ( name . equals ( " OddItem " ) ) {
2011-09-25 16:17:44 +02:00
if ( Odd . isInitialized ( ) ) return ;
if ( plugin . getDescription ( ) . getVersion ( ) . startsWith ( " 0.7 " ) ) { System . out . println ( generateOutdatedVersion ( name , plugin . getDescription ( ) . getVersion ( ) , " 0.8 " ) ) ; return ; }
Odd . isInitialized = true ;
2011-09-22 15:56:06 +02:00
} else if ( name . equals ( " Towny " ) ) {
2011-09-23 14:07:20 +02:00
if ( uSign . towny ! = null ) return ;
2011-09-22 15:56:06 +02:00
int versionNumber = 0 ;
String [ ] split = plugin . getDescription ( ) . getVersion ( ) . split ( " \\ . " ) ;
2011-09-25 16:17:44 +02:00
for ( int i = 0 ; i < 4 ; i + + ) if ( split . length > = i + 1 & & uNumber . isInteger ( split [ i ] ) ) versionNumber + = ( Math . pow ( 10 , ( 3 - i ) < < 1 ) * Integer . parseInt ( split [ i ] ) ) ; //EPIC CODE RIGHT HERE
if ( versionNumber < 760047 ) { System . out . println ( generateOutdatedVersion ( name , plugin . getDescription ( ) . getVersion ( ) , " 0.76.0.47 " ) ) ; return ; }
2011-09-23 14:07:20 +02:00
uSign . towny = ( Towny ) plugin ;
2011-05-15 18:16:25 +02:00
}
2011-09-06 19:01:57 +02:00
PluginDescriptionFile description = plugin . getDescription ( ) ;
2011-09-01 18:59:15 +02:00
System . out . println ( ChestShop . chatPrefix + description . getName ( ) + " version " + description . getVersion ( ) + " loaded. " ) ;
2011-05-15 18:16:25 +02:00
}
2011-09-25 16:17:44 +02:00
private static String generateOutdatedVersion ( String pluginName , String curVersion , String neededVersion ) {
return ( new StringBuilder ( 7 ) . append ( ChestShop . chatPrefix ) . append ( " Your " ) . append ( pluginName ) . append ( " is outdated! Need version AT LEAST " ) . append ( neededVersion ) . append ( " - Your version is " ) . append ( curVersion ) . toString ( ) ) ;
}
2011-05-15 18:16:25 +02:00
}