summaryrefslogtreecommitdiffstats
path: root/EssentialsChat/src
diff options
context:
space:
mode:
authorsnowleo <schneeleo@gmail.com>2011-12-09 02:48:39 +0100
committersnowleo <schneeleo@gmail.com>2011-12-09 02:48:57 +0100
commitde12c5c6d17147714c9452f76f8337dd996eb220 (patch)
treeb25eecd8db4e77b65e8734eeabb9e6b69322c380 /EssentialsChat/src
parent95d5217f588f11f3477e57420c3c678d4f7e4293 (diff)
downloadEssentials-de12c5c6d17147714c9452f76f8337dd996eb220.tar
Essentials-de12c5c6d17147714c9452f76f8337dd996eb220.tar.gz
Essentials-de12c5c6d17147714c9452f76f8337dd996eb220.tar.lz
Essentials-de12c5c6d17147714c9452f76f8337dd996eb220.tar.xz
Essentials-de12c5c6d17147714c9452f76f8337dd996eb220.zip
Fix broken charge for shout and question
Diffstat (limited to 'EssentialsChat/src')
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java15
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java25
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java4
-rw-r--r--EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java60
4 files changed, 59 insertions, 45 deletions
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
index 6600ff91d..25ce85cc8 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java
@@ -4,10 +4,12 @@ import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IEssentials;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentSkipListMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
+import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@@ -15,8 +17,10 @@ import org.bukkit.plugin.java.JavaPlugin;
public class EssentialsChat extends JavaPlugin
{
private static final Logger LOGGER = Logger.getLogger("Minecraft");
- private Map<String, IEssentialsChatListener> chatListener;
+ private transient Map<String, IEssentialsChatListener> chatListener;
+
+ @Override
public void onEnable()
{
final PluginManager pluginManager = getServer().getPluginManager();
@@ -31,11 +35,13 @@ public class EssentialsChat extends JavaPlugin
return;
}
- chatListener = new HashMap<String, IEssentialsChatListener>();
+ chatListener = new ConcurrentSkipListMap<String, IEssentialsChatListener>();
+ final Map<PlayerChatEvent, String> charges = new HashMap<PlayerChatEvent, String>();
+
final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatListener);
- final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatListener);
- final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatListener);
+ final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatListener, charges);
+ final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatListener, charges);
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerLowest, Priority.Lowest, this);
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerNormal, Priority.Normal, this);
pluginManager.registerEvent(Type.PLAYER_CHAT, playerListenerHighest, Priority.Highest, this);
@@ -43,6 +49,7 @@ public class EssentialsChat extends JavaPlugin
LOGGER.info(_("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), "essentials team"));
}
+ @Override
public void onDisable()
{
if (chatListener != null)
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java
index 17a219acd..22989d4f9 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java
@@ -10,14 +10,25 @@ import org.bukkit.event.player.PlayerChatEvent;
public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer
{
- public EssentialsChatPlayerListenerHighest(Server server, IEssentials ess, Map<String, IEssentialsChatListener> listeners)
+ private final transient Map<PlayerChatEvent, String> charges;
+
+ public EssentialsChatPlayerListenerHighest(final Server server,
+ final IEssentials ess,
+ final Map<String, IEssentialsChatListener> listeners,
+ final Map<PlayerChatEvent, String> charges)
{
super(server, ess, listeners);
+ this.charges = charges;
}
@Override
public void onPlayerChat(final PlayerChatEvent event)
{
+ String charge = charges.remove(event);
+ if (charge == null)
+ {
+ charge = "chat";
+ }
if (isAborted(event))
{
return;
@@ -27,22 +38,14 @@ public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer
* This file should handle charging the user for the action before returning control back
*/
final User user = ess.getUser(event.getPlayer());
- final String chatType = getChatType(event.getMessage());
- final StringBuilder command = new StringBuilder();
- command.append("chat");
-
- if (chatType.length() > 0)
- {
- command.append("-").append(chatType);
- }
try
{
- charge(user, command.toString());
+ charge(user, charge);
}
catch (ChargeException e)
{
- ess.showError(user, e, command.toString());
+ ess.showError(user, e, charge);
event.setCancelled(true);
return;
}
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java
index 0a599e88b..de5757951 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java
@@ -10,7 +10,9 @@ import org.bukkit.event.player.PlayerChatEvent;
public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer
{
- public EssentialsChatPlayerListenerLowest(Server server, IEssentials ess, Map<String, IEssentialsChatListener> listeners)
+ public EssentialsChatPlayerListenerLowest(final Server server,
+ final IEssentials ess,
+ final Map<String, IEssentialsChatListener> listeners)
{
super(server, ess, listeners);
}
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java
index 7789009e1..4e3cbefc0 100644
--- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java
+++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java
@@ -1,6 +1,5 @@
package com.earth2me.essentials.chat;
-import com.earth2me.essentials.ChargeException;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
@@ -12,9 +11,15 @@ import org.bukkit.event.player.PlayerChatEvent;
public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer
{
- public EssentialsChatPlayerListenerNormal(Server server, IEssentials ess, Map<String, IEssentialsChatListener> listeners)
+ private final transient Map<PlayerChatEvent, String> charges;
+
+ public EssentialsChatPlayerListenerNormal(final Server server,
+ final IEssentials ess,
+ final Map<String, IEssentialsChatListener> listeners,
+ final Map<PlayerChatEvent, String> charges)
{
super(server, ess, listeners);
+ this.charges = charges;
}
@Override
@@ -29,49 +34,46 @@ public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer
* This file should handle detection of the local chat features... if local chat is enabled, we need to handle
* it here
*/
- final User user = ess.getUser(event.getPlayer());
final String chatType = getChatType(event.getMessage());
+ final StringBuilder command = new StringBuilder();
+ command.append("chat");
+
+ if (chatType.length() > 0)
+ {
+ command.append("-").append(chatType);
+ }
long radius = ess.getSettings().getChatRadius();
if (radius < 1)
{
return;
}
radius *= radius;
- try
- {
- if (event.getMessage().length() > 0 && chatType.length() > 0)
- {
- StringBuilder permission = new StringBuilder();
- permission.append("essentials.chat.").append(chatType);
-
- StringBuilder command = new StringBuilder();
- command.append("chat-").append(chatType);
+ final User user = ess.getUser(event.getPlayer());
- StringBuilder format = new StringBuilder();
- format.append(chatType).append("Format");
+ if (event.getMessage().length() > 0 && chatType.length() > 0)
+ {
+ final StringBuilder permission = new StringBuilder();
+ permission.append("essentials.chat.").append(chatType);
- StringBuilder errorMsg = new StringBuilder();
- errorMsg.append("notAllowedTo").append(chatType.substring(0, 1).toUpperCase(Locale.ENGLISH)).append(chatType.substring(1));
+ final StringBuilder format = new StringBuilder();
+ format.append(chatType).append("Format");
- if (user.isAuthorized(permission.toString()))
- {
- charge(user, command.toString());
- event.setMessage(event.getMessage().substring(1));
- event.setFormat(_(format.toString(), event.getFormat()));
- return;
- }
+ final StringBuilder errorMsg = new StringBuilder();
+ errorMsg.append("notAllowedTo").append(chatType.substring(0, 1).toUpperCase(Locale.ENGLISH)).append(chatType.substring(1));
- user.sendMessage(_(errorMsg.toString()));
- event.setCancelled(true);
+ if (user.isAuthorized(permission.toString()))
+ {
+ event.setMessage(event.getMessage().substring(1));
+ event.setFormat(_(format.toString(), event.getFormat()));
+ charges.put(event, command.toString());
return;
}
- }
- catch (ChargeException ex)
- {
- ess.showError(user, ex, "Shout");
+
+ user.sendMessage(_(errorMsg.toString()));
event.setCancelled(true);
return;
}
+
sendLocalChat(user, radius, event);
}
}