Clean up integration methods with other plugins a bit

This commit is contained in:
Brettflan 2012-02-22 11:43:53 -06:00
parent c8d6d06f90
commit 546ecd6a45
5 changed files with 77 additions and 99 deletions

View File

@ -2,7 +2,6 @@ package com.massivecraft.factions;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.logging.Level;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -13,7 +12,6 @@ import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.adapters.FFlagTypeAdapter; import com.massivecraft.factions.adapters.FFlagTypeAdapter;
import com.massivecraft.factions.adapters.FLocToStringSetTypeAdapter; 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.capi.CapiFeatures;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.integration.EssentialsFeatures; import com.massivecraft.factions.integration.EssentialsFeatures;
import com.massivecraft.factions.integration.EssentialsOldVersionFeatures;
import com.massivecraft.factions.integration.LWCFeatures; import com.massivecraft.factions.integration.LWCFeatures;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.factions.integration.Worldguard; 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.struct.Rel;
import com.massivecraft.factions.zcore.MPlugin; 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.GsonBuilder;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
@ -77,10 +72,6 @@ public class P extends MPlugin
} }
private static EssentialsChat essChat;
@Override @Override
public void onEnable() public void onEnable()
{ {
@ -97,13 +88,11 @@ public class P extends MPlugin
this.cmdAutoHelp = new CmdAutoHelp(); this.cmdAutoHelp = new CmdAutoHelp();
this.getBaseCommands().add(cmdBase); this.getBaseCommands().add(cmdBase);
//setupPermissions(); EssentialsFeatures.setup();
integrateEssentialsChat(); SpoutFeatures.setup();
setupSpout(this); Econ.setup();
Econ.doSetup();
Econ.oldMoneyDoTransfer();
CapiFeatures.setup(); CapiFeatures.setup();
setupLWC(); LWCFeatures.setup();
if(Conf.worldGuardChecking) if(Conf.worldGuardChecking)
{ {
@ -141,7 +130,7 @@ public class P extends MPlugin
{ {
Board.save(); Board.save();
Conf.save(); Conf.save();
unhookEssentialsChat(); EssentialsFeatures.unhookChat();
super.onDisable(); super.onDisable();
} }
@ -160,72 +149,7 @@ public class P extends MPlugin
return super.handleCommand(sender, commandString, testOnly); 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 // Functions for other plugins to hook into

View File

@ -23,17 +23,7 @@ public class Econ
{ {
private static Economy econ = null; private static Economy econ = null;
public static boolean shouldBeUsed() public static void setup()
{
return Conf.econEnabled && econ != null && econ.isEnabled();
}
public static boolean isSetup()
{
return econ != null;
}
public static void doSetup()
{ {
if (isSetup()) return; 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.log("NOTE: Economy is disabled. You can enable it with the command: f config econEnabled true");
P.p.cmdBase.cmdHelp.updateHelp(); P.p.cmdBase.cmdHelp.updateHelp();
oldMoneyDoTransfer();
}
public static boolean shouldBeUsed()
{
return Conf.econEnabled && econ != null && econ.isEnabled();
}
public static boolean isSetup()
{
return econ != null;
} }

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import com.massivecraft.factions.Conf; import com.massivecraft.factions.Conf;
import com.massivecraft.factions.P; 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" * 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 public class EssentialsFeatures
{ {
private static EssentialsChat essChat; 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) public static void integrateChat(EssentialsChat instance)
{ {
essChat = instance; essChat = instance;

View File

@ -6,6 +6,7 @@ import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
@ -20,13 +21,14 @@ import com.massivecraft.factions.P;
public class LWCFeatures public class LWCFeatures
{ {
private static LWC lwc; 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\").")); P.p.log("Successfully hooked into LWC!"+(Conf.lwcIntegration ? "" : " Integration is currently disabled, though (\"lwcIntegration\")."));
} }

View File

@ -11,6 +11,7 @@ import com.massivecraft.factions.P;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.plugin.Plugin;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.struct.Rel;
@ -26,6 +27,14 @@ public class SpoutFeatures
private transient static SpoutMainListener mainListener; private transient static SpoutMainListener mainListener;
private transient static boolean listenersHooked; 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 // set integration availability
public static void setAvailable(boolean enable, String pluginName) public static void setAvailable(boolean enable, String pluginName)
{ {