summaryrefslogtreecommitdiffstats
path: root/EssentialsChat/src
diff options
context:
space:
mode:
authorBrettflan <dsr@fenrisoft.com>2011-07-02 17:34:49 -0500
committerBrettflan <dsr@fenrisoft.com>2011-07-02 17:34:49 -0500
commit16b101b958551bac656364fa6ed4399799d72b0c (patch)
tree0550470c7ddd28e5229b21576d4ab8ce2512bc72 /EssentialsChat/src
parent6616d9a62f4b2763c50623519c2d4a6df44395a2 (diff)
downloadEssentials-16b101b958551bac656364fa6ed4399799d72b0c.tar
Essentials-16b101b958551bac656364fa6ed4399799d72b0c.tar.gz
Essentials-16b101b958551bac656364fa6ed4399799d72b0c.tar.lz
Essentials-16b101b958551bac656364fa6ed4399799d72b0c.tar.xz
Essentials-16b101b958551bac656364fa6ed4399799d72b0c.zip
Implemented Factions hooks for proper chat integration with it (master/dev branch)
Diffstat (limited to 'EssentialsChat/src')
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java3
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java42
2 files changed, 44 insertions, 1 deletions
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
index 428413661..5fb8e9842 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
@@ -17,6 +17,9 @@ public class EssentialsChat extends JavaPlugin
public void onEnable()
{
final PluginManager pluginManager = getServer().getPluginManager();
+
+ EssentialsChatPlayerListener.checkFactions(pluginManager);
+
final EssentialsChatPlayerListener playerListener = new EssentialsChatPlayerListener(getServer());
pluginManager.registerEvent(Type.PLAYER_JOIN, playerListener, Priority.Lowest, this);
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListener, Priority.Highest, this);
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
index 211733818..57c41de72 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListener.java
@@ -13,6 +13,10 @@ import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginManager;
+
+import org.mcteam.factions.Factions;
public class EssentialsChatPlayerListener extends PlayerListener
@@ -20,6 +24,7 @@ public class EssentialsChatPlayerListener extends PlayerListener
private static final Logger LOGGER = Logger.getLogger("Minecraft");
private final transient IEssentials ess = Essentials.getStatic();
private final transient Server server;
+ private static Factions factions = null;
public EssentialsChatPlayerListener(final Server server)
{
@@ -48,6 +53,10 @@ public class EssentialsChatPlayerListener extends PlayerListener
{
return;
}
+
+ if (factions != null && (factions.shouldLetFactionsHandleThisChat(event)))
+ return;
+
final User user = ess.getUser(event.getPlayer());
updateDisplayName(user);
@@ -118,8 +127,39 @@ public class EssentialsChatPlayerListener extends PlayerListener
continue;
}
}
+ String message = String.format(event.getFormat(), user.getDisplayName(), event.getMessage());
+
+ if (factions != null)
+ message = message.replace("{FACTION}", factions.getPlayerFactionTagRelation(event.getPlayer(), p)).replace("{FACTION_TITLE}", factions.getPlayerTitle(event.getPlayer()));
- u.sendMessage(String.format(event.getFormat(), user.getDisplayName(), event.getMessage()));
+ u.sendMessage(message);
}
}
+
+ protected static void checkFactions(PluginManager pm)
+ {
+ if (factions != null)
+ return;
+
+ Plugin factionsPlugin = pm.getPlugin("Factions");
+ if (factionsPlugin == null)
+ return;
+
+ factions = (Factions)factionsPlugin;
+ try
+ { // make sure Factions is sufficiently up-to-date
+ if (factions.hookSupportVersion() < 1)
+ factions = null;
+ }
+ catch (NoSuchMethodError ex)
+ { // if not, we can't work with it, so don't bother
+ factions = null;
+ }
+
+ if (factions == null)
+ return;
+
+ // normally a good thing, but we'll skip it to let Factions handle faction tags for global messages
+ //factions.handleFactionTagExternally(true);
+ }
}