From 9e4357e8e3e8645e14d48f3384c7e45ccffbf0f0 Mon Sep 17 00:00:00 2001 From: ElgarL Date: Wed, 21 Dec 2011 19:26:29 +0000 Subject: [PATCH] v0.7: - Added support for Essentials mute and ignore features. Players on ignore will still be seen in town and nation chat. --- .classpath | 1 + src/changelog.txt | 4 +- .../event/TownyPlayerHighestListener.java | 60 ++++++++++++++++++- src/plugin.yml | 2 +- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/.classpath b/.classpath index 757c1f5..df19c10 100644 --- a/.classpath +++ b/.classpath @@ -5,5 +5,6 @@ + diff --git a/src/changelog.txt b/src/changelog.txt index 8fb34a4..ddeeb90 100644 --- a/src/changelog.txt +++ b/src/changelog.txt @@ -19,4 +19,6 @@ v0.5: - Added {worldname} as an accepted entry. - Fixed '/g' mode to add formatting. v0.6: - - Changed global chat to pass through bukkits chat process instead of our own (allows other plugins to see it again). \ No newline at end of file + - Changed global chat to pass through bukkits chat process instead of our own (allows other plugins to see it again). +v0.7: + - Added support for Essentials mute and ignore features. Players on ignore will still be seen in town and nation chat. \ No newline at end of file diff --git a/src/com/palmergames/bukkit/TownyChat/event/TownyPlayerHighestListener.java b/src/com/palmergames/bukkit/TownyChat/event/TownyPlayerHighestListener.java index 00d4234..c1b4261 100644 --- a/src/com/palmergames/bukkit/TownyChat/event/TownyPlayerHighestListener.java +++ b/src/com/palmergames/bukkit/TownyChat/event/TownyPlayerHighestListener.java @@ -6,8 +6,10 @@ import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerListener; +import com.earth2me.essentials.User; import com.palmergames.bukkit.towny.NotRegisteredException; import com.palmergames.bukkit.towny.Towny; +import com.palmergames.bukkit.towny.TownyException; import com.palmergames.bukkit.towny.TownyMessaging; import com.palmergames.bukkit.towny.TownySettings; import com.palmergames.bukkit.TownyChat.event.TownyChatEvent; @@ -47,6 +49,19 @@ public class TownyPlayerHighestListener extends PlayerListener { event.setMessage(message); if (!plugin.isPermissions() || (plugin.isPermissions() && TownyUniverse.getPermissionSource().hasPermission(player, TownySettings.getChatChannelPermission(command)))) { + + // Check if essentials has this player muted. + if (plugin.isEssentials()) { + try { + if (plugin.getEssentials().getUser(player).isMuted()) { + TownyMessaging.sendErrorMsg(player, "Unable to talk...You are currently muted!"); + return; + } + } catch (TownyException e) { + // Get essentials failed + } + } + // Deal with special cases if (command.equalsIgnoreCase("/tc")) { @@ -101,6 +116,19 @@ public class TownyPlayerHighestListener extends PlayerListener { Player player = event.getPlayer(); Resident resident; + + // Check if essentials has this player muted. + if (plugin.isEssentials()) { + try { + if (plugin.getEssentials().getUser(player).isMuted()) { + TownyMessaging.sendErrorMsg(player, "Unable to talk...You are currently muted!"); + return; + } + } catch (TownyException e) { + // Get essentials failed + } + } + try { resident = plugin.getTownyUniverse().getResident(player.getName()); } catch (NotRegisteredException e) { @@ -184,7 +212,8 @@ public class TownyPlayerHighestListener extends PlayerListener { private void parseDefaultChannelChatCommand(PlayerChatEvent event, String command, Player player) { try { Resident resident = plugin.getTownyUniverse().getResident(player.getName()); - + Boolean bEssentials = plugin.isEssentials(); + event.setFormat(TownySettings.getChatDefaultChannelFormat().replace("{channelTag}", TownySettings.getChatChannelName(command)).replace("{msgcolour}", TownySettings.getChatChannelColour(command))); TownyChatEvent chatEvent = new TownyChatEvent(event, resident); @@ -192,8 +221,20 @@ public class TownyPlayerHighestListener extends PlayerListener { TownyUniverse.plugin.log(chatEvent.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage())); for (Player test : plugin.getTownyUniverse().getOnlinePlayers()) { - if (!plugin.isPermissions() || (plugin.isPermissions() && TownyUniverse.getPermissionSource().hasPermission(test, TownySettings.getChatChannelPermission(command)))) + if (!plugin.isPermissions() || (plugin.isPermissions() && TownyUniverse.getPermissionSource().hasPermission(test, TownySettings.getChatChannelPermission(command)))) { + + if (bEssentials) { + try { + User targetUser = plugin.getEssentials().getUser(test); + // Don't send this message if the user is ignored + if (targetUser.isIgnoredPlayer(player.getName())) + continue; + } catch (TownyException e) { + // Failed to fetch user so ignore. + } + } TownyMessaging.sendMessage(test, chatEvent.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage())); + } } } catch (NotRegisteredException x) { @@ -204,6 +245,7 @@ public class TownyPlayerHighestListener extends PlayerListener { private void parseGlobalChannelChatCommand(PlayerChatEvent event, String command, Player player) { try { Resident resident = plugin.getTownyUniverse().getResident(player.getName()); + Boolean bEssentials = plugin.isEssentials(); if (TownySettings.isUsingModifyChat()) { event.setFormat(TownySettings.getModifyChatFormat()); @@ -214,8 +256,20 @@ public class TownyPlayerHighestListener extends PlayerListener { TownyUniverse.plugin.log(chatEvent.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage())); for (Player test : plugin.getTownyUniverse().getOnlinePlayers()) { - if (!plugin.isPermissions() || (plugin.isPermissions() && TownyUniverse.getPermissionSource().hasPermission(test, TownySettings.getChatChannelPermission(command)))) + if (!plugin.isPermissions() || (plugin.isPermissions() && TownyUniverse.getPermissionSource().hasPermission(test, TownySettings.getChatChannelPermission(command)))) { + + if (bEssentials) { + try { + User targetUser = plugin.getEssentials().getUser(test); + // Don't send this message if the user is ignored + if (targetUser.isIgnoredPlayer(player.getName())) + continue; + } catch (TownyException e) { + // Failed to fetch user so ignore. + } + } TownyMessaging.sendMessage(test, chatEvent.getFormat().replace("%1$s", event.getPlayer().getDisplayName()).replace("%2$s", event.getMessage())); + } } // TownyMessaging.sendNationMessage(nation, chatEvent.getFormat()); diff --git a/src/plugin.yml b/src/plugin.yml index f471f6d..2b382a1 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ name: TownyChat main: com.palmergames.bukkit.TownyChat.Chat -version: 0.6 +version: 0.7 author: ElgarL website: http://code.google.com/a/eclipselabs.org/p/towny/ description: >