From 0dc1270aedb932d19d5c1c2e313c4f2fb099bbc0 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Thu, 22 Mar 2012 22:07:13 +0000 Subject: Split colour permissions into 3: color/magic/format --- .../essentials/chat/EssentialsChatPlayerListenerLowest.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index 5a8cde62d..2c0906cbf 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -37,14 +37,7 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer /** * This listener should apply the general chat formatting only...then return control back the event handler */ - if (user.isAuthorized("essentials.chat.color")) - { - event.setMessage(Util.replaceColor(event.getMessage())); - } - else - { - event.setMessage(Util.stripColor(event.getMessage())); - } + event.setMessage(Util.formatString(user, "essentials.chat", event.getMessage())); String group = user.getGroup(); String world = user.getWorld().getName(); event.setFormat(ess.getSettings().getChatFormat(group).format(new Object[] {group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)})); -- cgit v1.2.3 From d20519ef8bf4141cb99ffc7dd2f43783e2c23253 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Thu, 22 Mar 2012 22:15:18 +0000 Subject: New Permission: essentials.chat.url Without this perm, URLs will be modified not to be links. --- .../essentials/chat/EssentialsChatPlayerListenerLowest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index 2c0906cbf..599c39dda 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -37,9 +37,12 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer /** * This listener should apply the general chat formatting only...then return control back the event handler */ - event.setMessage(Util.formatString(user, "essentials.chat", event.getMessage())); + event.setMessage(Util.formatMessage(user, "essentials.chat", event.getMessage())); String group = user.getGroup(); String world = user.getWorld().getName(); - event.setFormat(ess.getSettings().getChatFormat(group).format(new Object[] {group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)})); + event.setFormat(ess.getSettings().getChatFormat(group).format(new Object[] + { + group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH) + })); } } -- cgit v1.2.3 From 6504c88bf7cb406acce0dda2c45623bc8be15734 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Fri, 6 Apr 2012 02:36:27 +0100 Subject: Chat spy, should show otherworld chat. --- .../earth2me/essentials/chat/EssentialsChatPlayer.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java index ddf928725..6bdab0919 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -126,20 +126,19 @@ public abstract class EssentialsChatPlayer implements Listener } if (!onlineUser.equals(sender)) { - final Location playerLoc = onlineUser.getLocation(); - if (playerLoc.getWorld() != world) + if (onlineUser.isAuthorized("essentials.chat.spy")) { - continue; + type = type.concat(_("chatTypeSpy")); } - final double delta = playerLoc.distanceSquared(loc); - - if (delta > chatStore.getRadius()) + else { - if (onlineUser.isAuthorized("essentials.chat.spy")) + final Location playerLoc = onlineUser.getLocation(); + if (playerLoc.getWorld() != world) { - type = type.concat(_("chatTypeSpy")); + continue; } - else + final double delta = playerLoc.distanceSquared(loc); + if (delta > chatStore.getRadius()) { continue; } -- cgit v1.2.3 From a8af0a92593a6a9f5b23e782c147e237521738a1 Mon Sep 17 00:00:00 2001 From: ementalo Date: Tue, 29 May 2012 22:06:04 +0100 Subject: 2.9 to 3.0 merge --- .../src/com/earth2me/essentials/chat/EssentialsChatPlayer.java | 1 + 1 file changed, 1 insertion(+) (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java index 6a86de1f1..acf08a5dd 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -9,6 +9,7 @@ import com.earth2me.essentials.api.IRanks; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; import com.earth2me.essentials.permissions.Permissions; +import com.earth2me.essentials.storage.Location; import java.util.Locale; import java.util.Map; import java.util.logging.Logger; -- cgit v1.2.3 From ff5a82a14cbffbbd65e9baefb09d2c95305124c1 Mon Sep 17 00:00:00 2001 From: ementalo Date: Wed, 6 Jun 2012 01:53:34 +0100 Subject: 2.9 -> 3.0 merge --- .../essentials/chat/EssentialsChatPlayer.java | 21 +----------------- .../chat/EssentialsLocalChatEventListener.java | 25 +++++++++++----------- 2 files changed, 14 insertions(+), 32 deletions(-) (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java index acf08a5dd..7618a66ab 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -112,6 +112,7 @@ public abstract class EssentialsChatPlayer implements Listener protected void handleLocalChat(final PlayerChatEvent event, final ChatStore chatStore) { + long radius = 0; ISettings settings = ess.getSettings(); settings.acquireReadLock(); @@ -143,26 +144,6 @@ public abstract class EssentialsChatPlayer implements Listener event.setFormat(_(format.toString(), event.getFormat())); return; } - if (!onlineUser.equals(sender)) - { - if (onlineUser.isAuthorized("essentials.chat.spy")) - { - type = type.concat(_("chatTypeSpy")); - } - else - { - final Location playerLoc = onlineUser.getLocation(); - if (playerLoc.getWorld() != world) - { - continue; - } - final double delta = playerLoc.distanceSquared(loc); - if (delta > chatStore.getRadius()) - { - continue; - } - } - } final StringBuilder errorMsg = new StringBuilder(); errorMsg.append("notAllowedTo").append(chatStore.getType().substring(0, 1).toUpperCase(Locale.ENGLISH)).append(chatStore.getType().substring(1)); diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java index 401fa1142..8788d755d 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java @@ -44,28 +44,29 @@ public class EssentialsLocalChatEventListener implements Listener } if (!user.equals(sender)) { - final Location playerLoc = user.getLocation(); - if (playerLoc.getWorld() != world) + if (Permissions.CHAT_SPY.isAuthorized(user)) { - continue; + type = type.concat(_("chatTypeSpy")); } - final double delta = playerLoc.distanceSquared(loc); - - if (delta > event.getRadius()) + else { - if (Permissions.CHAT_SPY.isAuthorized(user)) + final Location playerLoc = user.getLocation(); + if (playerLoc.getWorld() != world) { - type = type.concat(_("chatTypeSpy")); + continue; } - else + final double delta = playerLoc.distanceSquared(loc); + + if (delta > event.getRadius()) { continue; } } - } - final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage())); - user.sendMessage(message); + final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage())); + user.sendMessage(message); + } } + } } \ No newline at end of file -- cgit v1.2.3 From 89eca7d99158e59e9a6807492bdf219dc25c31a6 Mon Sep 17 00:00:00 2001 From: ementalo Date: Mon, 18 Jun 2012 13:55:25 +0100 Subject: 2.9 Merges Make /vanish follow the same rules as /fly, /god and /gamemode Add espawn to plugin.yml Allow your hat to be removed with /hat remove void silent command failures on /hat (ie typing /hat fish will no longer silently return as if broken) Fix /exp so it can be used in the console Using /exp, show can't find player message, if no matching player is found Replace op ignore exempt with ignore exempt chat permission: essentials.chat.ignoreexempt This permission won't prevent a player from ignoring the player, but the player will see the chat messages anyway. Fix chat showing [spy] prefix when social spy was not required to see the message Players should not be able to ignore Console Also implement chat exempt permission in other commands. Prevent joinbots from triggering join code, unless they are actually connected to the server and online. --- .../chat/EssentialsLocalChatEventListener.java | 35 +++++++++++----------- 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java index 8788d755d..04c49b698 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java @@ -37,36 +37,35 @@ public class EssentialsLocalChatEventListener implements Listener { String type = _("chatTypeLocal"); final IUser user = ess.getUser(onlinePlayer); - //TODO: remove reference to op - if (user.isIgnoringPlayer(sender.getName()) && !sender.isOp()) + if (user.isIgnoringPlayer(ess.getUser(sender))) { continue; } if (!user.equals(sender)) { - if (Permissions.CHAT_SPY.isAuthorized(user)) + boolean abort = false; + final Location playerLoc = user.getLocation(); + if (playerLoc.getWorld() != world) { - type = type.concat(_("chatTypeSpy")); + abort = true; } - else + final double delta = playerLoc.distanceSquared(loc); + + if (delta > event.getRadius()) { - final Location playerLoc = user.getLocation(); - if (playerLoc.getWorld() != world) - { - continue; - } - final double delta = playerLoc.distanceSquared(loc); + abort = true; + } - if (delta > event.getRadius()) + if (abort) + { + if (ChatPermissions.getPermission("spy").isAuthorized(user)) { - continue; + type = type.concat(_("chatTypeSpy")); } } - - final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage())); - user.sendMessage(message); } + final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage())); + user.sendMessage(message); } - } -} \ No newline at end of file +} -- cgit v1.2.3 From bfbec1c46c3ab2454ebda9b1a0adda4fbb8269d2 Mon Sep 17 00:00:00 2001 From: ementalo Date: Mon, 18 Jun 2012 15:51:48 +0100 Subject: Remove fake explosion. Missing bits of commandr --- .../src/com/earth2me/essentials/chat/EssentialsChatPlayer.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java index 7618a66ab..d0ae47d31 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -1,15 +1,14 @@ package com.earth2me.essentials.chat; -import com.earth2me.essentials.api.ChargeException; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.economy.Trade; -import com.earth2me.essentials.utils.Util; +import com.earth2me.essentials.api.ChargeException; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IRanks; import com.earth2me.essentials.api.ISettings; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.economy.Trade; import com.earth2me.essentials.permissions.Permissions; -import com.earth2me.essentials.storage.Location; +import com.earth2me.essentials.utils.Util; import java.util.Locale; import java.util.Map; import java.util.logging.Logger; -- cgit v1.2.3 From 06f54fdbac1874c549b5181d92b4a9474da55dcc Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 27 Jun 2012 20:27:27 +1000 Subject: That just leaves the big ol' core. Largely ignore Compat as it is very temporary. --- .../src/com/earth2me/essentials/chat/ChatPermissions.java | 6 ++++-- EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java | 2 +- EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java | 5 ----- .../src/com/earth2me/essentials/chat/EssentialsChatPlayer.java | 2 +- .../src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java | 3 ++- .../earth2me/essentials/chat/EssentialsLocalChatEventListener.java | 3 --- 6 files changed, 8 insertions(+), 13 deletions(-) (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java b/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java index 9a8bd9e88..43142915f 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java @@ -6,7 +6,9 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; -public class ChatPermissions { + +public class ChatPermissions +{ private static Map permissions = new HashMap(); public static IPermission getPermission(final String groupName) @@ -14,7 +16,7 @@ public class ChatPermissions { IPermission perm = permissions.get(groupName); if (perm == null) { - perm = new BasePermission("essentials.chat.",groupName.toLowerCase(Locale.ENGLISH)); + perm = new BasePermission("essentials.chat.", groupName.toLowerCase(Locale.ENGLISH)); permissions.put(groupName, perm); } return perm; diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java b/EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java index 887ac8337..f01ada07b 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java @@ -1,8 +1,8 @@ package com.earth2me.essentials.chat; -import com.earth2me.essentials.economy.Trade; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IUser; +import com.earth2me.essentials.economy.Trade; public class ChatStore diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java index a4d4283a7..1ff0d6f41 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java @@ -45,9 +45,4 @@ public class EssentialsChat extends JavaPlugin final EssentialsLocalChatEventListener localChatListener = new EssentialsLocalChatEventListener(getServer(), ess); pluginManager.registerEvents(localChatListener, this); } - - @Override - public void onDisable() - { - } } diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java index d0ae47d31..fcd9d7e01 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -111,7 +111,7 @@ public abstract class EssentialsChatPlayer implements Listener protected void handleLocalChat(final PlayerChatEvent event, final ChatStore chatStore) { - + long radius = 0; ISettings settings = ess.getSettings(); settings.acquireReadLock(); diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java index 2eae385a9..4ca1a4496 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java @@ -98,6 +98,7 @@ public class EssentialsLocalChatEvent extends Event implements Cancellable return parentEvent; } + @Override public HandlerList getHandlers() { return handlers; @@ -107,4 +108,4 @@ public class EssentialsLocalChatEvent extends Event implements Cancellable { return handlers; } -} \ No newline at end of file +} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java index 04c49b698..db596b15f 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java @@ -3,8 +3,6 @@ package com.earth2me.essentials.chat; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IUser; -import com.earth2me.essentials.permissions.Permissions; -import java.util.logging.Logger; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.World; @@ -18,7 +16,6 @@ public class EssentialsLocalChatEventListener implements Listener { protected transient IEssentials ess; protected final transient Server server; - private static final Logger LOGGER = Logger.getLogger("Minecraft"); public EssentialsLocalChatEventListener(final Server server, final IEssentials ess) { -- cgit v1.2.3 From 6123f17ef45136089837ba891c34be2ace5fd012 Mon Sep 17 00:00:00 2001 From: snowleo Date: Wed, 27 Jun 2012 13:54:13 +0200 Subject: Renamed plugin from Essentials3 to Essentials-3 --- EssentialsChat/src/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/plugin.yml b/EssentialsChat/src/plugin.yml index 488ef7b50..0d54428e3 100644 --- a/EssentialsChat/src/plugin.yml +++ b/EssentialsChat/src/plugin.yml @@ -6,5 +6,5 @@ version: ${build.number} website: http://tiny.cc/EssentialsWiki description: Provides chat control features for Essentials. Requires Permissions. authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits, md_5, Okamosy] -depend: [Essentials3] +depend: [Essentials-3] #softdepend: [Factions] \ No newline at end of file -- cgit v1.2.3 From 16d0b5c228dd8d981a0d79944c70248ea813d63b Mon Sep 17 00:00:00 2001 From: ementalo Date: Wed, 27 Jun 2012 13:35:39 +0100 Subject: package name change to net.ess3 --- .../earth2me/essentials/chat/ChatPermissions.java | 24 ---- .../com/earth2me/essentials/chat/ChatStore.java | 40 ------ .../earth2me/essentials/chat/EssentialsChat.java | 48 ------- .../essentials/chat/EssentialsChatPlayer.java | 159 --------------------- .../essentials/chat/EssentialsLocalChatEvent.java | 111 -------------- .../chat/EssentialsLocalChatEventListener.java | 68 --------- .../EssentialsChatPlayerListenerHighest.java | 33 ----- .../EssentialsChatPlayerListenerLowest.java | 36 ----- .../EssentialsChatPlayerListenerNormal.java | 33 ----- .../src/net/ess3/chat/ChatPermissions.java | 24 ++++ EssentialsChat/src/net/ess3/chat/ChatStore.java | 40 ++++++ .../src/net/ess3/chat/EssentialsChat.java | 48 +++++++ .../src/net/ess3/chat/EssentialsChatPlayer.java | 159 +++++++++++++++++++++ .../net/ess3/chat/EssentialsLocalChatEvent.java | 111 ++++++++++++++ .../chat/EssentialsLocalChatEventListener.java | 68 +++++++++ .../EssentialsChatPlayerListenerHighest.java | 34 +++++ .../EssentialsChatPlayerListenerLowest.java | 38 +++++ .../EssentialsChatPlayerListenerNormal.java | 33 +++++ EssentialsChat/src/plugin.yml | 2 +- 19 files changed, 556 insertions(+), 553 deletions(-) delete mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java delete mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java delete mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java delete mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java delete mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java delete mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java delete mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java delete mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java delete mode 100644 EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerNormal.java create mode 100644 EssentialsChat/src/net/ess3/chat/ChatPermissions.java create mode 100644 EssentialsChat/src/net/ess3/chat/ChatStore.java create mode 100644 EssentialsChat/src/net/ess3/chat/EssentialsChat.java create mode 100644 EssentialsChat/src/net/ess3/chat/EssentialsChatPlayer.java create mode 100644 EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEvent.java create mode 100644 EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEventListener.java create mode 100644 EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java create mode 100644 EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java create mode 100644 EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerNormal.java (limited to 'EssentialsChat') diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java b/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java deleted file mode 100644 index 43142915f..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.earth2me.essentials.chat; - -import com.earth2me.essentials.api.IPermission; -import com.earth2me.essentials.permissions.BasePermission; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - - -public class ChatPermissions -{ - private static Map permissions = new HashMap(); - - public static IPermission getPermission(final String groupName) - { - IPermission perm = permissions.get(groupName); - if (perm == null) - { - perm = new BasePermission("essentials.chat.", groupName.toLowerCase(Locale.ENGLISH)); - permissions.put(groupName, perm); - } - return perm; - } -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java b/EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java deleted file mode 100644 index f01ada07b..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.earth2me.essentials.chat; - -import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.api.IUser; -import com.earth2me.essentials.economy.Trade; - - -public class ChatStore -{ - private final transient IUser user; - private final transient String type; - private final transient Trade charge; - - public ChatStore(final IEssentials ess, final IUser user, final String type) - { - this.user = user; - this.type = type; - this.charge = new Trade(getLongType(), ess); - } - - public IUser getUser() - { - return user; - } - - public Trade getCharge() - { - return charge; - } - - public String getType() - { - return type; - } - - public final String getLongType() - { - return type.length() == 0 ? "chat" : "chat-" + type; - } -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java deleted file mode 100644 index 1ff0d6f41..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.earth2me.essentials.chat; - -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.chat.listenerlevel.EssentialsChatPlayerListenerHighest; -import com.earth2me.essentials.chat.listenerlevel.EssentialsChatPlayerListenerLowest; -import com.earth2me.essentials.chat.listenerlevel.EssentialsChatPlayerListenerNormal; -import java.util.HashMap; -import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.bukkit.event.player.PlayerChatEvent; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; - - -public class EssentialsChat extends JavaPlugin -{ - private static final Logger LOGGER = Logger.getLogger("Minecraft"); - - @Override - public void onEnable() - { - final PluginManager pluginManager = getServer().getPluginManager(); - final IEssentials ess = (IEssentials)pluginManager.getPlugin("Essentials3"); - if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) - { - LOGGER.log(Level.WARNING, _("versionMismatchAll")); - } - if (!ess.isEnabled()) - { - this.setEnabled(false); - return; - } - - final Map chatStore = new HashMap(); - - final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatStore); - final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatStore); - final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatStore); - pluginManager.registerEvents(playerListenerLowest, this); - pluginManager.registerEvents(playerListenerNormal, this); - pluginManager.registerEvents(playerListenerHighest, this); - - final EssentialsLocalChatEventListener localChatListener = new EssentialsLocalChatEventListener(getServer(), ess); - pluginManager.registerEvents(localChatListener, this); - } -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java deleted file mode 100644 index fcd9d7e01..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ /dev/null @@ -1,159 +0,0 @@ -package com.earth2me.essentials.chat; - -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.api.ChargeException; -import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.api.IRanks; -import com.earth2me.essentials.api.ISettings; -import com.earth2me.essentials.api.IUser; -import com.earth2me.essentials.economy.Trade; -import com.earth2me.essentials.permissions.Permissions; -import com.earth2me.essentials.utils.Util; -import java.util.Locale; -import java.util.Map; -import java.util.logging.Logger; -import org.bukkit.Server; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerChatEvent; - -//TODO: Translate the local/spy tags -public abstract class EssentialsChatPlayer implements Listener -{ - protected transient IEssentials ess; - protected final static Logger LOGGER = Logger.getLogger("Minecraft"); - protected final transient Server server; - protected final transient Map chatStorage; - - public EssentialsChatPlayer(final Server server, - final IEssentials ess, - final Map chatStorage) - { - this.ess = ess; - this.server = server; - this.chatStorage = chatStorage; - } - - public void onPlayerChat(final PlayerChatEvent event) - { - } - - public ChatStore getChatStore(final PlayerChatEvent event) - { - return chatStorage.get(event); - } - - public void setChatStore(final PlayerChatEvent event, final ChatStore chatStore) - { - chatStorage.put(event, chatStore); - } - - public ChatStore delChatStore(final PlayerChatEvent event) - { - return chatStorage.remove(event); - } - - protected void chargeChat(final PlayerChatEvent event, final ChatStore chatStore) - { - try - { - charge(chatStore.getUser(), chatStore.getCharge()); - } - catch (ChargeException e) - { - ess.getCommandHandler().showCommandError(chatStore.getUser(), chatStore.getLongType(), e); - event.setCancelled(true); - } - } - - protected void charge(final CommandSender sender, final Trade charge) throws ChargeException - { - if (sender instanceof Player) - { - charge.charge(ess.getUser((Player)sender)); - } - } - - protected void formatChat(final PlayerChatEvent event, final ChatStore chatStore) - { - final IUser user = chatStore.getUser(); - if (Permissions.CHAT_COLOR.isAuthorized(user)) - { - event.setMessage(Util.stripColor(event.getMessage())); - } - String group = ess.getRanks().getMainGroup(user); - String world = user.getWorld().getName(); - - IRanks groupSettings = ess.getRanks(); - event.setFormat(groupSettings.getChatFormat(user).format(new Object[] - { - group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH) - })); - - } - - //TODO: Flesh this out - '?' trigger is too easily accidentally triggered - protected String getChatType(final String message) - { - switch (message.charAt(0)) - { - case '!': - return "shout"; - //case '?': - //return "question"; - //case '@': - // return "admin"; - default: - return ""; - } - } - - protected void handleLocalChat(final PlayerChatEvent event, final ChatStore chatStore) - { - - long radius = 0; - ISettings settings = ess.getSettings(); - settings.acquireReadLock(); - try - { - radius = settings.getData().getChat().getLocalRadius(); - } - finally - { - settings.unlock(); - } - - if (radius < 1) - { - return; - } - - radius *= radius; - - final IUser user = chatStore.getUser(); - - if (event.getMessage().length() > 1 && chatStore.getType().length() > 0) - { - if (ChatPermissions.getPermission(chatStore.getType()).isAuthorized(user)) - { - final StringBuilder format = new StringBuilder(); - format.append(chatStore.getType()).append("Format"); - event.setMessage(event.getMessage().substring(1)); - event.setFormat(_(format.toString(), event.getFormat())); - return; - } - - final StringBuilder errorMsg = new StringBuilder(); - errorMsg.append("notAllowedTo").append(chatStore.getType().substring(0, 1).toUpperCase(Locale.ENGLISH)).append(chatStore.getType().substring(1)); - - user.sendMessage(_(errorMsg.toString())); - event.setCancelled(true); - return; - } - - event.setCancelled(true); - final EssentialsLocalChatEvent localChat = new EssentialsLocalChatEvent(event, radius); - ess.getServer().getPluginManager().callEvent(localChat); - } -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java deleted file mode 100644 index 4ca1a4496..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.earth2me.essentials.chat; - -import org.bukkit.entity.Player; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; -import org.bukkit.event.player.PlayerChatEvent; - - -public class EssentialsLocalChatEvent extends Event implements Cancellable -{ - private Player player; - private String message; - private String format = "<%1$s> %2$s"; - private long radius; - private boolean cancelled = false; - private PlayerChatEvent parentEvent = null; - private static final HandlerList handlers = new HandlerList(); - - public EssentialsLocalChatEvent(final Player player, final String message, final String format, final long radius) - { - this.player = player; - this.message = message; - this.format = format; - this.radius = radius; - } - - public EssentialsLocalChatEvent(final PlayerChatEvent event, final long radius) - { - this(event.getPlayer(), event.getMessage(), event.getFormat(), radius); - this.parentEvent = event; - } - - @Override - public boolean isCancelled() - { - return cancelled; - } - - @Override - public void setCancelled(final boolean cancel) - { - this.cancelled = cancel; - } - - public String getMessage() - { - return message; - } - - public void setMessage(final String message) - { - this.message = message; - } - - public void setPlayer(final Player player) - { - this.player = player; - } - - public Player getPlayer() - { - return player; - } - - public String getFormat() - { - return format; - } - - public void setFormat(final String format) - { - // Oh for a better way to do this! - try - { - String.format(format, player, message); - } - catch (RuntimeException ex) - { - ex.fillInStackTrace(); - throw ex; - } - this.format = format; - } - - public long getRadius() - { - return radius; - } - - public void setRadius(final long radius) - { - this.radius = radius; - } - - public PlayerChatEvent getParentEvent() - { - return parentEvent; - } - - @Override - public HandlerList getHandlers() - { - return handlers; - } - - public static HandlerList getHandlerList() - { - return handlers; - } -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java deleted file mode 100644 index db596b15f..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.earth2me.essentials.chat; - -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.api.IUser; -import org.bukkit.Location; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; - - -public class EssentialsLocalChatEventListener implements Listener -{ - protected transient IEssentials ess; - protected final transient Server server; - - public EssentialsLocalChatEventListener(final Server server, final IEssentials ess) - { - this.ess = ess; - this.server = server; - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onLocalChat(final EssentialsLocalChatEvent event) - { - final Player sender = event.getPlayer(); - final Location loc = sender.getLocation(); - final World world = loc.getWorld(); - - for (Player onlinePlayer : server.getOnlinePlayers()) - { - String type = _("chatTypeLocal"); - final IUser user = ess.getUser(onlinePlayer); - if (user.isIgnoringPlayer(ess.getUser(sender))) - { - continue; - } - if (!user.equals(sender)) - { - boolean abort = false; - final Location playerLoc = user.getLocation(); - if (playerLoc.getWorld() != world) - { - abort = true; - } - final double delta = playerLoc.distanceSquared(loc); - - if (delta > event.getRadius()) - { - abort = true; - } - - if (abort) - { - if (ChatPermissions.getPermission("spy").isAuthorized(user)) - { - type = type.concat(_("chatTypeSpy")); - } - } - } - final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage())); - user.sendMessage(message); - } - } -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java b/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java deleted file mode 100644 index 576c93e6f..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.earth2me.essentials.chat.listenerlevel; - -import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.chat.ChatStore; -import com.earth2me.essentials.chat.EssentialsChatPlayer; -import java.util.Map; -import org.bukkit.Server; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerChatEvent; - - -public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer -{ - public EssentialsChatPlayerListenerHighest(final Server server, - final IEssentials ess, - final Map chatStorage) - { - super(server, ess, chatStorage); - } - - @EventHandler(priority = EventPriority.HIGHEST) - @Override - public void onPlayerChat(final PlayerChatEvent event) - { - final ChatStore chatStore = delChatStore(event); - if (event.isCancelled()) - { - return; - } - chargeChat(event, chatStore); - } -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java deleted file mode 100644 index 3fcff995c..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.earth2me.essentials.chat.listenerlevel; - -import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.api.IUser; -import com.earth2me.essentials.chat.ChatStore; -import com.earth2me.essentials.chat.EssentialsChatPlayer; -import java.util.Map; -import org.bukkit.Server; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerChatEvent; - - -public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer -{ - public EssentialsChatPlayerListenerLowest(final Server server, - final IEssentials ess, - final Map chatStorage) - { - super(server, ess, chatStorage); - } - - @EventHandler(priority = EventPriority.LOWEST) - @Override - public void onPlayerChat(final PlayerChatEvent event) - { - if (event.isCancelled()) - { - return; - } - final IUser user = ess.getUser(event.getPlayer()); - final ChatStore chatStore = new ChatStore(ess, user, getChatType(event.getMessage())); - setChatStore(event, chatStore); - formatChat(event, chatStore); - } -} \ No newline at end of file diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerNormal.java b/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerNormal.java deleted file mode 100644 index c456b700d..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerNormal.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.earth2me.essentials.chat.listenerlevel; - -import com.earth2me.essentials.api.IEssentials; -import com.earth2me.essentials.chat.ChatStore; -import com.earth2me.essentials.chat.EssentialsChatPlayer; -import java.util.Map; -import org.bukkit.Server; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerChatEvent; - - -public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer -{ - public EssentialsChatPlayerListenerNormal(final Server server, - final IEssentials ess, - final Map chatStorage) - { - super(server, ess, chatStorage); - } - - @EventHandler(priority = EventPriority.NORMAL) - @Override - public void onPlayerChat(final PlayerChatEvent event) - { - if (event.isCancelled()) - { - return; - } - final ChatStore chatStore = getChatStore(event); - handleLocalChat(event, chatStore); - } -} diff --git a/EssentialsChat/src/net/ess3/chat/ChatPermissions.java b/EssentialsChat/src/net/ess3/chat/ChatPermissions.java new file mode 100644 index 000000000..888b85f9d --- /dev/null +++ b/EssentialsChat/src/net/ess3/chat/ChatPermissions.java @@ -0,0 +1,24 @@ +package net.ess3.chat; + +import net.ess3.api.IPermission; +import net.ess3.permissions.BasePermission; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + + +public class ChatPermissions +{ + private static Map permissions = new HashMap(); + + public static IPermission getPermission(final String groupName) + { + IPermission perm = permissions.get(groupName); + if (perm == null) + { + perm = new BasePermission("essentials.chat.", groupName.toLowerCase(Locale.ENGLISH)); + permissions.put(groupName, perm); + } + return perm; + } +} diff --git a/EssentialsChat/src/net/ess3/chat/ChatStore.java b/EssentialsChat/src/net/ess3/chat/ChatStore.java new file mode 100644 index 000000000..4d696fb36 --- /dev/null +++ b/EssentialsChat/src/net/ess3/chat/ChatStore.java @@ -0,0 +1,40 @@ +package net.ess3.chat; + +import net.ess3.api.IEssentials; +import net.ess3.api.IUser; +import net.ess3.economy.Trade; + + +public class ChatStore +{ + private final transient IUser user; + private final transient String type; + private final transient Trade charge; + + public ChatStore(final IEssentials ess, final IUser user, final String type) + { + this.user = user; + this.type = type; + this.charge = new Trade(getLongType(), ess); + } + + public IUser getUser() + { + return user; + } + + public Trade getCharge() + { + return charge; + } + + public String getType() + { + return type; + } + + public final String getLongType() + { + return type.length() == 0 ? "chat" : "chat-" + type; + } +} diff --git a/EssentialsChat/src/net/ess3/chat/EssentialsChat.java b/EssentialsChat/src/net/ess3/chat/EssentialsChat.java new file mode 100644 index 000000000..4c922c45f --- /dev/null +++ b/EssentialsChat/src/net/ess3/chat/EssentialsChat.java @@ -0,0 +1,48 @@ +package net.ess3.chat; + +import static net.ess3.I18n._; +import net.ess3.api.IEssentials; +import net.ess3.chat.listenerlevel.EssentialsChatPlayerListenerHighest; +import net.ess3.chat.listenerlevel.EssentialsChatPlayerListenerLowest; +import net.ess3.chat.listenerlevel.EssentialsChatPlayerListenerNormal; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.bukkit.event.player.PlayerChatEvent; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + + +public class EssentialsChat extends JavaPlugin +{ + private static final Logger LOGGER = Logger.getLogger("Minecraft"); + + @Override + public void onEnable() + { + final PluginManager pluginManager = getServer().getPluginManager(); + final IEssentials ess = (IEssentials)pluginManager.getPlugin("Essentials-3"); + if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) + { + LOGGER.log(Level.WARNING, _("versionMismatchAll")); + } + if (!ess.isEnabled()) + { + this.setEnabled(false); + return; + } + + final Map chatStore = new HashMap(); + + final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatStore); + final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatStore); + final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatStore); + pluginManager.registerEvents(playerListenerLowest, this); + pluginManager.registerEvents(playerListenerNormal, this); + pluginManager.registerEvents(playerListenerHighest, this); + + final EssentialsLocalChatEventListener localChatListener = new EssentialsLocalChatEventListener(getServer(), ess); + pluginManager.registerEvents(localChatListener, this); + } +} diff --git a/EssentialsChat/src/net/ess3/chat/EssentialsChatPlayer.java b/EssentialsChat/src/net/ess3/chat/EssentialsChatPlayer.java new file mode 100644 index 000000000..ae8fce4a1 --- /dev/null +++ b/EssentialsChat/src/net/ess3/chat/EssentialsChatPlayer.java @@ -0,0 +1,159 @@ +package net.ess3.chat; + +import static net.ess3.I18n._; +import net.ess3.api.ChargeException; +import net.ess3.api.IEssentials; +import net.ess3.api.IRanks; +import net.ess3.api.ISettings; +import net.ess3.api.IUser; +import net.ess3.economy.Trade; +import net.ess3.permissions.Permissions; +import net.ess3.utils.Util; +import java.util.Locale; +import java.util.Map; +import java.util.logging.Logger; +import org.bukkit.Server; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerChatEvent; + +//TODO: Translate the local/spy tags +public abstract class EssentialsChatPlayer implements Listener +{ + protected transient IEssentials ess; + protected final static Logger LOGGER = Logger.getLogger("Minecraft"); + protected final transient Server server; + protected final transient Map chatStorage; + + public EssentialsChatPlayer(final Server server, + final IEssentials ess, + final Map chatStorage) + { + this.ess = ess; + this.server = server; + this.chatStorage = chatStorage; + } + + public void onPlayerChat(final PlayerChatEvent event) + { + } + + public ChatStore getChatStore(final PlayerChatEvent event) + { + return chatStorage.get(event); + } + + public void setChatStore(final PlayerChatEvent event, final ChatStore chatStore) + { + chatStorage.put(event, chatStore); + } + + public ChatStore delChatStore(final PlayerChatEvent event) + { + return chatStorage.remove(event); + } + + protected void chargeChat(final PlayerChatEvent event, final ChatStore chatStore) + { + try + { + charge(chatStore.getUser(), chatStore.getCharge()); + } + catch (ChargeException e) + { + ess.getCommandHandler().showCommandError(chatStore.getUser(), chatStore.getLongType(), e); + event.setCancelled(true); + } + } + + protected void charge(final CommandSender sender, final Trade charge) throws ChargeException + { + if (sender instanceof Player) + { + charge.charge(ess.getUser((Player)sender)); + } + } + + protected void formatChat(final PlayerChatEvent event, final ChatStore chatStore) + { + final IUser user = chatStore.getUser(); + if (Permissions.CHAT_COLOR.isAuthorized(user)) + { + event.setMessage(Util.stripColor(event.getMessage())); + } + String group = ess.getRanks().getMainGroup(user); + String world = user.getWorld().getName(); + + IRanks groupSettings = ess.getRanks(); + event.setFormat(groupSettings.getChatFormat(user).format(new Object[] + { + group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH) + })); + + } + + //TODO: Flesh this out - '?' trigger is too easily accidentally triggered + protected String getChatType(final String message) + { + switch (message.charAt(0)) + { + case '!': + return "shout"; + //case '?': + //return "question"; + //case '@': + // return "admin"; + default: + return ""; + } + } + + protected void handleLocalChat(final PlayerChatEvent event, final ChatStore chatStore) + { + + long radius = 0; + ISettings settings = ess.getSettings(); + settings.acquireReadLock(); + try + { + radius = settings.getData().getChat().getLocalRadius(); + } + finally + { + settings.unlock(); + } + + if (radius < 1) + { + return; + } + + radius *= radius; + + final IUser user = chatStore.getUser(); + + if (event.getMessage().length() > 1 && chatStore.getType().length() > 0) + { + if (ChatPermissions.getPermission(chatStore.getType()).isAuthorized(user)) + { + final StringBuilder format = new StringBuilder(); + format.append(chatStore.getType()).append("Format"); + event.setMessage(event.getMessage().substring(1)); + event.setFormat(_(format.toString(), event.getFormat())); + return; + } + + final StringBuilder errorMsg = new StringBuilder(); + errorMsg.append("notAllowedTo").append(chatStore.getType().substring(0, 1).toUpperCase(Locale.ENGLISH)).append(chatStore.getType().substring(1)); + + user.sendMessage(_(errorMsg.toString())); + event.setCancelled(true); + return; + } + + event.setCancelled(true); + final EssentialsLocalChatEvent localChat = new EssentialsLocalChatEvent(event, radius); + ess.getServer().getPluginManager().callEvent(localChat); + } +} diff --git a/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEvent.java b/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEvent.java new file mode 100644 index 000000000..e0ce6602d --- /dev/null +++ b/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEvent.java @@ -0,0 +1,111 @@ +package net.ess3.chat; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerChatEvent; + + +public class EssentialsLocalChatEvent extends Event implements Cancellable +{ + private Player player; + private String message; + private String format = "<%1$s> %2$s"; + private long radius; + private boolean cancelled = false; + private PlayerChatEvent parentEvent = null; + private static final HandlerList handlers = new HandlerList(); + + public EssentialsLocalChatEvent(final Player player, final String message, final String format, final long radius) + { + this.player = player; + this.message = message; + this.format = format; + this.radius = radius; + } + + public EssentialsLocalChatEvent(final PlayerChatEvent event, final long radius) + { + this(event.getPlayer(), event.getMessage(), event.getFormat(), radius); + this.parentEvent = event; + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(final boolean cancel) + { + this.cancelled = cancel; + } + + public String getMessage() + { + return message; + } + + public void setMessage(final String message) + { + this.message = message; + } + + public void setPlayer(final Player player) + { + this.player = player; + } + + public Player getPlayer() + { + return player; + } + + public String getFormat() + { + return format; + } + + public void setFormat(final String format) + { + // Oh for a better way to do this! + try + { + String.format(format, player, message); + } + catch (RuntimeException ex) + { + ex.fillInStackTrace(); + throw ex; + } + this.format = format; + } + + public long getRadius() + { + return radius; + } + + public void setRadius(final long radius) + { + this.radius = radius; + } + + public PlayerChatEvent getParentEvent() + { + return parentEvent; + } + + @Override + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} diff --git a/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEventListener.java b/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEventListener.java new file mode 100644 index 000000000..29bd7e8e8 --- /dev/null +++ b/EssentialsChat/src/net/ess3/chat/EssentialsLocalChatEventListener.java @@ -0,0 +1,68 @@ +package net.ess3.chat; + +import static net.ess3.I18n._; +import net.ess3.api.IEssentials; +import net.ess3.api.IUser; +import org.bukkit.Location; +import org.bukkit.Server; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + + +public class EssentialsLocalChatEventListener implements Listener +{ + protected transient IEssentials ess; + protected final transient Server server; + + public EssentialsLocalChatEventListener(final Server server, final IEssentials ess) + { + this.ess = ess; + this.server = server; + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onLocalChat(final EssentialsLocalChatEvent event) + { + final Player sender = event.getPlayer(); + final Location loc = sender.getLocation(); + final World world = loc.getWorld(); + + for (Player onlinePlayer : server.getOnlinePlayers()) + { + String type = _("chatTypeLocal"); + final IUser user = ess.getUser(onlinePlayer); + if (user.isIgnoringPlayer(ess.getUser(sender))) + { + continue; + } + if (!user.equals(sender)) + { + boolean abort = false; + final Location playerLoc = user.getLocation(); + if (playerLoc.getWorld() != world) + { + abort = true; + } + final double delta = playerLoc.distanceSquared(loc); + + if (delta > event.getRadius()) + { + abort = true; + } + + if (abort) + { + if (ChatPermissions.getPermission("spy").isAuthorized(user)) + { + type = type.concat(_("chatTypeSpy")); + } + } + } + final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage())); + user.sendMessage(message); + } + } +} diff --git a/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java new file mode 100644 index 000000000..21f3a188e --- /dev/null +++ b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java @@ -0,0 +1,34 @@ +package net.ess3.chat.listenerlevel; + +import net.ess3.api.IEssentials; +import net.ess3.chat.ChatStore; +import net.ess3.chat.ChatStore; +import net.ess3.chat.EssentialsChatPlayer; +import java.util.Map; +import org.bukkit.Server; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChatEvent; + + +public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer +{ + public EssentialsChatPlayerListenerHighest(final Server server, + final IEssentials ess, + final Map chatStorage) + { + super(server, ess, chatStorage); + } + + @EventHandler(priority = EventPriority.HIGHEST) + @Override + public void onPlayerChat(final PlayerChatEvent event) + { + final ChatStore chatStore = delChatStore(event); + if (event.isCancelled()) + { + return; + } + chargeChat(event, chatStore); + } +} diff --git a/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java new file mode 100644 index 000000000..eb75e3680 --- /dev/null +++ b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java @@ -0,0 +1,38 @@ +package net.ess3.chat.listenerlevel; + +import net.ess3.api.IEssentials; +import net.ess3.api.IUser; +import net.ess3.chat.ChatStore; +import net.ess3.chat.EssentialsChatPlayer; +import java.util.Map; + +import net.ess3.chat.EssentialsChatPlayer; +import org.bukkit.Server; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChatEvent; + + +public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer +{ + public EssentialsChatPlayerListenerLowest(final Server server, + final IEssentials ess, + final Map chatStorage) + { + super(server, ess, chatStorage); + } + + @EventHandler(priority = EventPriority.LOWEST) + @Override + public void onPlayerChat(final PlayerChatEvent event) + { + if (event.isCancelled()) + { + return; + } + final IUser user = ess.getUser(event.getPlayer()); + final ChatStore chatStore = new ChatStore(ess, user, getChatType(event.getMessage())); + setChatStore(event, chatStore); + formatChat(event, chatStore); + } +} \ No newline at end of file diff --git a/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerNormal.java b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerNormal.java new file mode 100644 index 000000000..2e3b44549 --- /dev/null +++ b/EssentialsChat/src/net/ess3/chat/listenerlevel/EssentialsChatPlayerListenerNormal.java @@ -0,0 +1,33 @@ +package net.ess3.chat.listenerlevel; + +import net.ess3.api.IEssentials; +import net.ess3.chat.ChatStore; +import net.ess3.chat.EssentialsChatPlayer; +import java.util.Map; +import org.bukkit.Server; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChatEvent; + + +public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer +{ + public EssentialsChatPlayerListenerNormal(final Server server, + final IEssentials ess, + final Map chatStorage) + { + super(server, ess, chatStorage); + } + + @EventHandler(priority = EventPriority.NORMAL) + @Override + public void onPlayerChat(final PlayerChatEvent event) + { + if (event.isCancelled()) + { + return; + } + final ChatStore chatStore = getChatStore(event); + handleLocalChat(event, chatStore); + } +} diff --git a/EssentialsChat/src/plugin.yml b/EssentialsChat/src/plugin.yml index 0d54428e3..6e314cbbb 100644 --- a/EssentialsChat/src/plugin.yml +++ b/EssentialsChat/src/plugin.yml @@ -1,6 +1,6 @@ # This determines the command prefix when there are conflicts (/name:home, /name:help, etc.) name: EssentialsChat -main: com.earth2me.essentials.chat.EssentialsChat +main: net.ess3.chat.EssentialsChat # Note to developers: This next line cannot change, or the automatic versioning system will break. version: ${build.number} website: http://tiny.cc/EssentialsWiki -- cgit v1.2.3