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

129 lines
3.6 KiB
Java
Raw Normal View History

package com.Acrobot.ChestShop;
import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.ChestShop.Configuration.Properties;
2013-07-13 23:12:20 +02:00
import com.Acrobot.ChestShop.Listeners.Economy.Plugins.VaultListener;
import com.Acrobot.ChestShop.Plugins.*;
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 loadPlugins() {
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
}
}
loadEconomy();
}
private static void loadEconomy() {
String plugin = "Vault";
Listener economy = VaultListener.initializeVault();
2012-06-25 17:16:24 +02:00
if (economy == null) {
return;
}
2012-06-25 17:16:24 +02:00
ChestShop.registerListener(economy);
2013-07-13 23:12:20 +02:00
ChestShop.getBukkitLogger().info(plugin + " loaded! Found an economy plugin!");
}
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 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 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,
WorldGuard,
Heroes
}
}