Clean up integration methods with other plugins a bit

This commit is contained in:
Brettflan 2012-02-22 11:43:56 -06:00
parent 11a4162981
commit 5452a7cf91
5 changed files with 78 additions and 103 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,13 +12,11 @@ import org.bukkit.block.Block;
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.cmd.CmdAutoHelp; import com.massivecraft.factions.cmd.CmdAutoHelp;
import com.massivecraft.factions.cmd.FCmdRoot; import com.massivecraft.factions.cmd.FCmdRoot;
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;
@ -34,10 +31,8 @@ import com.massivecraft.factions.util.MapFLocToStringSetTypeAdapter;
import com.massivecraft.factions.util.MyLocationTypeAdapter; import com.massivecraft.factions.util.MyLocationTypeAdapter;
import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.MPlugin;
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;
import com.griefcraft.lwc.LWCPlugin;
public class P extends MPlugin public class P extends MPlugin
@ -70,12 +65,8 @@ public class P extends MPlugin
this.blockListener = new FactionsBlockListener(this); this.blockListener = new FactionsBlockListener(this);
this.serverListener = new FactionsServerListener(this); this.serverListener = new FactionsServerListener(this);
} }
private static EssentialsChat essChat;
@Override @Override
public void onEnable() public void onEnable()
{ {
@ -91,15 +82,13 @@ public class P extends MPlugin
this.cmdBase = new FCmdRoot(); this.cmdBase = new FCmdRoot();
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)
{ {
Worldguard.init(this); Worldguard.init(this);
@ -133,7 +122,7 @@ public class P extends MPlugin
{ {
Board.save(); Board.save();
Conf.save(); Conf.save();
unhookEssentialsChat(); EssentialsFeatures.unhookChat();
super.onDisable(); super.onDisable();
} }
@ -152,76 +141,8 @@ 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,18 +23,8 @@ import net.milkbowl.vault.economy.Economy;
public class Econ public class Econ
{ {
private static Economy econ = null; 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; if (isSetup()) return;
@ -60,6 +50,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.Relation; import com.massivecraft.factions.struct.Relation;
@ -27,6 +28,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)
{ {