ChestShop-3/com/Acrobot/ChestShop/Dependencies.java

162 lines
4.6 KiB
Java
Raw Normal View History

package com.Acrobot.ChestShop;
import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.ChestShop.Config.Config;
2012-04-19 15:53:08 +02:00
import com.Acrobot.ChestShop.Economy.Economy;
import com.Acrobot.ChestShop.Economy.NoProvider;
import com.Acrobot.ChestShop.Economy.Register;
import com.Acrobot.ChestShop.Economy.Vault;
import com.Acrobot.ChestShop.Plugins.*;
import com.nijikokun.register.payment.forChestShop.Method;
import com.nijikokun.register.payment.forChestShop.Methods;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import org.bukkit.Bukkit;
2012-06-25 17:16:24 +02:00
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginManager;
2012-06-25 17:16:24 +02:00
2012-11-04 21:09:38 +01:00
import static com.Acrobot.ChestShop.Config.Property.*;
/**
* @author Acrobot
*/
public class Dependencies {
public static void load() {
PluginManager pluginManager = Bukkit.getPluginManager();
2012-11-04 21:09:38 +01:00
for (String dependency : ChestShop.getDependencies()) {
2012-06-25 17:16:24 +02:00
Plugin plugin = pluginManager.getPlugin(dependency);
if (plugin != null) {
2012-06-25 17:16:24 +02:00
initializePlugin(dependency, plugin);
2012-04-19 15:53:08 +02:00
}
}
2012-06-25 17:16:24 +02:00
if (!Economy.isLoaded()) {
loadRegister();
}
}
private static void loadRegister() {
Method method = Methods.load();
2012-06-25 17:16:24 +02:00
2012-04-19 15:53:08 +02:00
if (method == null) {
2012-06-25 17:16:24 +02:00
Economy.setPlugin(new NoProvider());
2012-04-19 15:53:08 +02:00
return;
}
2012-06-25 17:16:24 +02:00
Economy.setPlugin(new Register(method));
ChestShop.getBukkitLogger().info(method.getName() + " version " + method.getVersion() + " loaded.");
}
private static void initializePlugin(String name, Plugin plugin) { //Really messy, right? But it's short and fast :)
2012-06-25 17:16:24 +02:00
Dependency dependency;
try {
dependency = Dependency.valueOf(name);
} catch (IllegalArgumentException exception) {
return;
}
Listener listener = null;
switch(dependency) {
//Protection plugins
case LWC:
listener = new LightweightChestProtection();
break;
case Lockette:
listener = new Lockette();
break;
case Deadbolt:
listener = new Deadbolt();
break;
case SimpleChestLock:
listener = SimpleChestLock.getSimpleChestLock(plugin);
break;
2012-08-24 10:45:54 +02:00
case Residence:
listener = new ResidenceChestProtection();
break;
2012-06-25 17:16:24 +02:00
//Terrain protection plugins
case Towny:
Towny towny = Towny.getTowny();
if (towny == null || !Config.getBoolean(TOWNY_INTEGRATION)) {
2012-06-25 17:16:24 +02:00
return;
}
listener = towny;
break;
case WorldGuard:
WorldGuardPlugin worldGuard = (WorldGuardPlugin) plugin;
boolean inUse = Config.getBoolean(WORLDGUARD_USE_PROTECTION) || Config.getBoolean(WORLDGUARD_INTEGRATION);
if (!inUse) {
return;
}
if (Config.getBoolean(WORLDGUARD_USE_PROTECTION)) {
ChestShop.registerListener(new WorldGuardProtection(worldGuard));
}
if (Config.getBoolean(WORLDGUARD_INTEGRATION)) {
listener = new WorldGuardBuilding(worldGuard);
}
break;
//Other plugins
case Vault:
Vault vault = Vault.getVault();
if (vault == null) {
return;
}
Economy.setPlugin(vault);
ChestShop.getBukkitLogger().info("Vault loaded - using " + Vault.getPluginName());
return;
2012-06-25 17:16:24 +02:00
case Heroes:
Heroes heroes = Heroes.getHeroes(plugin);
2012-04-19 15:53:08 +02:00
2012-06-25 17:16:24 +02:00
if (heroes == null) {
return;
}
2012-04-19 15:53:08 +02:00
2012-06-25 17:16:24 +02:00
listener = heroes;
break;
case OddItem:
MaterialUtil.Odd.initialize();
break;
}
2012-04-19 15:53:08 +02:00
2012-06-25 17:16:24 +02:00
if (listener != null) {
ChestShop.registerListener(listener);
}
PluginDescriptionFile description = plugin.getDescription();
ChestShop.getBukkitLogger().info(description.getName() + " version " + description.getVersion() + " loaded.");
}
2012-06-25 17:16:24 +02:00
private static enum Dependency {
LWC,
Lockette,
Deadbolt,
SimpleChestLock,
2012-08-24 10:45:54 +02:00
Residence,
2012-06-25 17:16:24 +02:00
OddItem,
Towny,
WorldGuard,
Vault,
Heroes
}
}