summaryrefslogtreecommitdiffstats
path: root/EssentialsChat
diff options
context:
space:
mode:
Diffstat (limited to 'EssentialsChat')
-rw-r--r--EssentialsChat/nbproject/project.properties4
-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
-rw-r--r--EssentialsChat/src/plugin.yml2
6 files changed, 62 insertions, 48 deletions
diff --git a/EssentialsChat/nbproject/project.properties b/EssentialsChat/nbproject/project.properties
index e59815e40..8cf7e9081 100644
--- a/EssentialsChat/nbproject/project.properties
+++ b/EssentialsChat/nbproject/project.properties
@@ -63,12 +63,12 @@ dist.jar=${dist.dir}/EssentialsChat.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
-file.reference.bukkit-1.0.0-R1-SNAPSHOT.jar=../lib/bukkit-1.0.0-R1-SNAPSHOT.jar
+file.reference.bukkit.jar=../lib/bukkit.jar
includes=**
jar.compress=true
javac.classpath=\
${reference.Essentials.jar}:\
- ${file.reference.bukkit-1.0.0-R1-SNAPSHOT.jar}
+ ${file.reference.bukkit.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
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);
}
}
diff --git a/EssentialsChat/src/plugin.yml b/EssentialsChat/src/plugin.yml
index d3f5d38df..cc129f825 100644
--- a/EssentialsChat/src/plugin.yml
+++ b/EssentialsChat/src/plugin.yml
@@ -5,6 +5,6 @@ main: com.earth2me.essentials.chat.EssentialsChat
version: TeamCity
website: http://www.earth2me.net:8001/
description: Provides chat control features for Essentials. Requires Permissions.
-authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology]
+authors: [Zenexer, ementalo, Aelux, Brettflan, KimKandor, snowleo, ceulemans, Xeology, KHobbits, Okamosy]
depend: [Essentials]
#softdepend: [Factions] \ No newline at end of file