From 546ecd6a45d5a0fb042b97ed292ced130dba820a Mon Sep 17 00:00:00 2001 From: Brettflan Date: Wed, 22 Feb 2012 11:43:53 -0600 Subject: [PATCH] Clean up integration methods with other plugins a bit --- src/com/massivecraft/factions/P.java | 90 ++----------------- .../factions/integration/Econ.java | 24 ++--- .../integration/EssentialsFeatures.java | 41 +++++++++ .../factions/integration/LWCFeatures.java | 12 +-- .../factions/integration/SpoutFeatures.java | 9 ++ 5 files changed, 77 insertions(+), 99 deletions(-) diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index 434ced79..e2c2f806 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -2,7 +2,6 @@ package com.massivecraft.factions; import java.lang.reflect.Modifier; import java.lang.reflect.Type; -import java.util.logging.Level; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -13,7 +12,6 @@ import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerChatEvent; -import org.bukkit.plugin.Plugin; import com.massivecraft.factions.adapters.FFlagTypeAdapter; import com.massivecraft.factions.adapters.FLocToStringSetTypeAdapter; @@ -24,7 +22,6 @@ import com.massivecraft.factions.cmd.*; import com.massivecraft.factions.integration.capi.CapiFeatures; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.EssentialsFeatures; -import com.massivecraft.factions.integration.EssentialsOldVersionFeatures; import com.massivecraft.factions.integration.LWCFeatures; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.Worldguard; @@ -39,8 +36,6 @@ import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.zcore.MPlugin; -import com.griefcraft.lwc.LWCPlugin; -import com.earth2me.essentials.chat.EssentialsChat; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; @@ -75,12 +70,8 @@ public class P extends MPlugin this.blockListener = new FactionsBlockListener(this); this.serverListener = new FactionsServerListener(this); } - - - private static EssentialsChat essChat; - - + @Override public void onEnable() { @@ -96,14 +87,12 @@ public class P extends MPlugin this.cmdBase = new FCmdRoot(); this.cmdAutoHelp = new CmdAutoHelp(); this.getBaseCommands().add(cmdBase); - - //setupPermissions(); - integrateEssentialsChat(); - setupSpout(this); - Econ.doSetup(); - Econ.oldMoneyDoTransfer(); + + EssentialsFeatures.setup(); + SpoutFeatures.setup(); + Econ.setup(); CapiFeatures.setup(); - setupLWC(); + LWCFeatures.setup(); if(Conf.worldGuardChecking) { @@ -141,7 +130,7 @@ public class P extends MPlugin { Board.save(); Conf.save(); - unhookEssentialsChat(); + EssentialsFeatures.unhookChat(); super.onDisable(); } @@ -160,72 +149,7 @@ public class P extends MPlugin return super.handleCommand(sender, commandString, testOnly); } - // -------------------------------------------- // - // Integration with other plugins - // -------------------------------------------- // - private void setupSpout(P factions) - { - Plugin test = factions.getServer().getPluginManager().getPlugin("Spout"); - - if (test != null && test.isEnabled()) - { - SpoutFeatures.setAvailable(true, test.getDescription().getFullName()); - } - } - - private void integrateEssentialsChat() - { - if (essChat != null) return; - - Plugin test = this.getServer().getPluginManager().getPlugin("EssentialsChat"); - - if (test != null && test.isEnabled()) - { - essChat = (EssentialsChat)test; - - // try newer Essentials 3.x integration method - try - { - Class.forName("com.earth2me.essentials.chat.EssentialsLocalChatEvent"); - EssentialsFeatures.integrateChat(essChat); - } - catch (ClassNotFoundException ex) - { - // no? try older Essentials 2.x integration method - try - { - EssentialsOldVersionFeatures.integrateChat(essChat); - } - catch (NoClassDefFoundError ex2) - { - // no known method for hooking into Essentials chat stuff - } - } - } - } - - private void unhookEssentialsChat() - { - if (essChat != null) - { - try - { - EssentialsOldVersionFeatures.unhookChat(); - } - catch (NoClassDefFoundError ex) - { - } - } - } - - private void setupLWC() - { - Plugin test = this.getServer().getPluginManager().getPlugin("LWC"); - - if(test != null && test.isEnabled()) - LWCFeatures.integrateLWC((LWCPlugin)test); - } // -------------------------------------------- // // Functions for other plugins to hook into diff --git a/src/com/massivecraft/factions/integration/Econ.java b/src/com/massivecraft/factions/integration/Econ.java index 00e68eae..f3911c13 100644 --- a/src/com/massivecraft/factions/integration/Econ.java +++ b/src/com/massivecraft/factions/integration/Econ.java @@ -22,18 +22,8 @@ import net.milkbowl.vault.economy.Economy; public class Econ { private static Economy econ = null; - - public static boolean shouldBeUsed() - { - return Conf.econEnabled && econ != null && econ.isEnabled(); - } - - public static boolean isSetup() - { - return econ != null; - } - public static void doSetup() + public static void setup() { if (isSetup()) return; @@ -59,6 +49,18 @@ public class Econ P.p.log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true"); P.p.cmdBase.cmdHelp.updateHelp(); + + oldMoneyDoTransfer(); + } + + public static boolean shouldBeUsed() + { + return Conf.econEnabled && econ != null && econ.isEnabled(); + } + + public static boolean isSetup() + { + return econ != null; } diff --git a/src/com/massivecraft/factions/integration/EssentialsFeatures.java b/src/com/massivecraft/factions/integration/EssentialsFeatures.java index d8f63406..a2ea246b 100644 --- a/src/com/massivecraft/factions/integration/EssentialsFeatures.java +++ b/src/com/massivecraft/factions/integration/EssentialsFeatures.java @@ -5,6 +5,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import com.massivecraft.factions.Conf; import com.massivecraft.factions.P; @@ -15,12 +16,52 @@ import com.earth2me.essentials.chat.EssentialsLocalChatEvent; /* * This Essentials integration handler is for newer 3.x.x versions of Essentials which don't have "IEssentialsChatListener" + * If an older version is detected in the setup() method below, handling is passed off to EssentialsOldVersionFeatures */ public class EssentialsFeatures { private static EssentialsChat essChat; + public static void setup() + { + if (essChat != null) return; + + Plugin test = Bukkit.getServer().getPluginManager().getPlugin("EssentialsChat"); + if (test == null || !test.isEnabled()) return; + + essChat = (EssentialsChat)test; + + // try newer Essentials 3.x integration method + try + { + Class.forName("com.earth2me.essentials.chat.EssentialsLocalChatEvent"); + integrateChat(essChat); + } + catch (ClassNotFoundException ex) + { + // no? try older Essentials 2.x integration method + try + { + EssentialsOldVersionFeatures.integrateChat(essChat); + } + catch (NoClassDefFoundError ex2) { /* no known integration method, then */ } + } + } + + public static void unhookChat() + { + if (essChat == null) return; + + try + { + EssentialsOldVersionFeatures.unhookChat(); + } + catch (NoClassDefFoundError ex) {} + } + + + public static void integrateChat(EssentialsChat instance) { essChat = instance; diff --git a/src/com/massivecraft/factions/integration/LWCFeatures.java b/src/com/massivecraft/factions/integration/LWCFeatures.java index 2f62b7bc..b7e904be 100644 --- a/src/com/massivecraft/factions/integration/LWCFeatures.java +++ b/src/com/massivecraft/factions/integration/LWCFeatures.java @@ -6,6 +6,7 @@ import java.util.List; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.plugin.Plugin; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockState; @@ -20,13 +21,14 @@ import com.massivecraft.factions.P; public class LWCFeatures { - private static LWC lwc; - - public static void integrateLWC(LWCPlugin test) + + public static void setup() { - lwc = test.getLWC(); - + Plugin test = Bukkit.getServer().getPluginManager().getPlugin("LWC"); + if(test == null || !test.isEnabled()) return; + + lwc = ((LWCPlugin)test).getLWC(); P.p.log("Successfully hooked into LWC!"+(Conf.lwcIntegration ? "" : " Integration is currently disabled, though (\"lwcIntegration\").")); } diff --git a/src/com/massivecraft/factions/integration/SpoutFeatures.java b/src/com/massivecraft/factions/integration/SpoutFeatures.java index 340205b2..a1714473 100644 --- a/src/com/massivecraft/factions/integration/SpoutFeatures.java +++ b/src/com/massivecraft/factions/integration/SpoutFeatures.java @@ -11,6 +11,7 @@ import com.massivecraft.factions.P; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.plugin.Plugin; import org.bukkit.entity.Player; import com.massivecraft.factions.struct.Rel; @@ -26,6 +27,14 @@ public class SpoutFeatures private transient static SpoutMainListener mainListener; private transient static boolean listenersHooked; + public static void setup() + { + Plugin test = Bukkit.getServer().getPluginManager().getPlugin("Spout"); + if (test == null || !test.isEnabled()) return; + + setAvailable(true, test.getDescription().getFullName()); + } + // set integration availability public static void setAvailable(boolean enable, String pluginName) {