2012-05-10 16:32:25 +02:00
|
|
|
package com.Acrobot.ChestShop;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
import com.Acrobot.Breeze.Utils.MaterialUtil;
|
2012-11-23 21:04:13 +01:00
|
|
|
import com.Acrobot.ChestShop.Configuration.Properties;
|
2012-11-25 23:34:21 +01:00
|
|
|
import com.Acrobot.ChestShop.Economy.EconomyManager;
|
2012-04-19 15:53:08 +02:00
|
|
|
import com.Acrobot.ChestShop.Economy.Economy;
|
2012-01-25 16:32:34 +01:00
|
|
|
import com.Acrobot.ChestShop.Economy.Register;
|
|
|
|
import com.Acrobot.ChestShop.Economy.Vault;
|
2012-05-10 16:32:25 +02:00
|
|
|
import com.Acrobot.ChestShop.Plugins.*;
|
2012-01-25 16:32:34 +01:00
|
|
|
import com.nijikokun.register.payment.forChestShop.Method;
|
2011-10-11 13:15:53 +02:00
|
|
|
import com.nijikokun.register.payment.forChestShop.Methods;
|
|
|
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2012-06-25 17:16:24 +02:00
|
|
|
import org.bukkit.event.Listener;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import org.bukkit.plugin.PluginDescriptionFile;
|
2012-06-08 15:28:36 +02:00
|
|
|
import org.bukkit.plugin.PluginManager;
|
2012-06-25 17:16:24 +02:00
|
|
|
|
2011-05-15 18:16:25 +02:00
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
2012-05-10 16:32:25 +02:00
|
|
|
public class Dependencies {
|
|
|
|
public static void load() {
|
2012-06-08 15:28:36 +02:00
|
|
|
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);
|
|
|
|
|
2012-06-08 15:28:36 +02:00
|
|
|
if (plugin != null) {
|
2012-06-25 17:16:24 +02:00
|
|
|
initializePlugin(dependency, plugin);
|
2012-04-19 15:53:08 +02:00
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2012-06-25 17:16:24 +02:00
|
|
|
if (!Economy.isLoaded()) {
|
|
|
|
loadRegister();
|
|
|
|
}
|
2012-05-10 16:32:25 +02:00
|
|
|
}
|
|
|
|
|
2012-03-17 15:00:25 +01:00
|
|
|
private static void loadRegister() {
|
2012-06-08 15:28:36 +02:00
|
|
|
Method method = Methods.load();
|
2012-06-25 17:16:24 +02:00
|
|
|
|
2012-04-19 15:53:08 +02:00
|
|
|
if (method == null) {
|
2012-11-25 23:34:21 +01:00
|
|
|
Economy.setPlugin(new EconomyManager());
|
2012-04-19 15:53:08 +02:00
|
|
|
return;
|
2012-01-25 16:32:34 +01:00
|
|
|
}
|
2012-06-25 17:16:24 +02:00
|
|
|
|
|
|
|
Economy.setPlugin(new Register(method));
|
|
|
|
|
2012-05-10 16:32:25 +02:00
|
|
|
ChestShop.getBukkitLogger().info(method.getName() + " version " + method.getVersion() + " loaded.");
|
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 :)
|
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();
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
if (towny == null || !Properties.TOWNY_INTEGRATION) {
|
2012-06-25 17:16:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
listener = towny;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case WorldGuard:
|
|
|
|
WorldGuardPlugin worldGuard = (WorldGuardPlugin) plugin;
|
2012-11-23 21:04:13 +01:00
|
|
|
boolean inUse = Properties.WORLDGUARD_USE_PROTECTION || Properties.WORLDGUARD_INTEGRATION;
|
2012-06-25 17:16:24 +02:00
|
|
|
|
|
|
|
if (!inUse) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
if (Properties.WORLDGUARD_USE_PROTECTION) {
|
2012-06-25 17:16:24 +02:00
|
|
|
ChestShop.registerListener(new WorldGuardProtection(worldGuard));
|
|
|
|
}
|
|
|
|
|
2012-11-23 21:04:13 +01:00
|
|
|
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());
|
2012-05-10 16:32:25 +02:00
|
|
|
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);
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
2012-03-17 15:00:25 +01:00
|
|
|
|
2011-09-06 19:01:57 +02:00
|
|
|
PluginDescriptionFile description = plugin.getDescription();
|
2012-05-10 16:32:25 +02:00
|
|
|
ChestShop.getBukkitLogger().info(description.getName() + " version " + description.getVersion() + " loaded.");
|
2011-09-25 16:17:44 +02:00
|
|
|
}
|
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
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|