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-05-10 16:32:25 +02:00
|
|
|
import com.Acrobot.ChestShop.Config.Config;
|
2012-04-19 15:53:08 +02:00
|
|
|
import com.Acrobot.ChestShop.Economy.Economy;
|
2012-02-16 19:09:37 +01:00
|
|
|
import com.Acrobot.ChestShop.Economy.NoProvider;
|
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
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2012-07-26 13:44:57 +02:00
|
|
|
import static com.Acrobot.ChestShop.Config.Property.TOWNY_INTEGRATION;
|
2012-06-25 17:16:24 +02:00
|
|
|
import static com.Acrobot.ChestShop.Config.Property.WORLDGUARD_INTEGRATION;
|
|
|
|
import static com.Acrobot.ChestShop.Config.Property.WORLDGUARD_USE_PROTECTION;
|
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-06-25 17:16:24 +02:00
|
|
|
for (String dependency : (List<String>) ChestShop.getDependencies()) {
|
|
|
|
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-06-25 17:16:24 +02:00
|
|
|
Economy.setPlugin(new NoProvider());
|
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-07-26 13:44:57 +02:00
|
|
|
case SecureChests:
|
|
|
|
listener = new SecureChests();
|
|
|
|
break;
|
2012-06-25 17:16:24 +02:00
|
|
|
|
|
|
|
//Terrain protection plugins
|
|
|
|
case Towny:
|
|
|
|
Towny towny = Towny.getTowny();
|
|
|
|
|
2012-07-26 13:44:57 +02:00
|
|
|
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());
|
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-07-26 13:44:57 +02:00
|
|
|
SecureChests,
|
2012-06-25 17:16:24 +02:00
|
|
|
|
|
|
|
OddItem,
|
|
|
|
|
|
|
|
Towny,
|
|
|
|
WorldGuard,
|
|
|
|
|
|
|
|
Vault,
|
|
|
|
Heroes
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|