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

160 lines
4.5 KiB
Java
Raw Normal View History

package com.Acrobot.ChestShop;
import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
2012-04-19 15:53:08 +02:00
import com.Acrobot.ChestShop.Economy.Economy;
2012-11-29 20:28:16 +01:00
import com.Acrobot.ChestShop.Economy.EconomyManager;
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
/**
* @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) {
Economy.setPlugin(new EconomyManager());
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;
2012-11-29 20:28:16 +01:00
switch (dependency) {
2012-06-25 17:16:24 +02:00
//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 || !Properties.TOWNY_INTEGRATION) {
2012-06-25 17:16:24 +02:00
return;
}
listener = towny;
break;
case WorldGuard:
WorldGuardPlugin worldGuard = (WorldGuardPlugin) plugin;
boolean inUse = Properties.WORLDGUARD_USE_PROTECTION || Properties.WORLDGUARD_INTEGRATION;
2012-06-25 17:16:24 +02:00
if (!inUse) {
return;
}
if (Properties.WORLDGUARD_USE_PROTECTION) {
2012-06-25 17:16:24 +02:00
ChestShop.registerListener(new WorldGuardProtection(worldGuard));
}
if (Properties.WORLDGUARD_INTEGRATION) {
2012-06-25 17:16:24 +02:00
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
}
}