diff options
24 files changed, 219 insertions, 169 deletions
diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 8dc046c4e..0abca5136 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -519,3 +519,4 @@ inventoryClearingAllStack=\u00a76Cleared all\u00a7c {0} \u00a76from {1}\u00a76. inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76from {2}\u00a76. inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_cs.properties b/Essentials/src/messages_cs.properties index 02f76cfe0..c5dd4c304 100644 --- a/Essentials/src/messages_cs.properties +++ b/Essentials/src/messages_cs.properties @@ -525,3 +525,4 @@ inventoryClearingStack=\u00a76Odstraneno\u00a7c {0}\u00a7cz {1} \u00a76od {2}\u0 inventoryClearFail=\u00a74Hrac {0} \u00a74nema\u00a7c {1} \u00a74z\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_da.properties b/Essentials/src/messages_da.properties index dfc8c7783..22df30bc2 100644 --- a/Essentials/src/messages_da.properties +++ b/Essentials/src/messages_da.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_de.properties b/Essentials/src/messages_de.properties index ad743b2eb..ca66fa09c 100644 --- a/Essentials/src/messages_de.properties +++ b/Essentials/src/messages_de.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a7c {0} {1} \u00a76von {2} \u00a76entfernt. inventoryClearFail=\u00a74Spieler {0} \u00a74hat keine\u00a7c {1} {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 8dc046c4e..0abca5136 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -519,3 +519,4 @@ inventoryClearingAllStack=\u00a76Cleared all\u00a7c {0} \u00a76from {1}\u00a76. inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76from {2}\u00a76. inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_es.properties b/Essentials/src/messages_es.properties index bd11391f3..9e42b7351 100644 --- a/Essentials/src/messages_es.properties +++ b/Essentials/src/messages_es.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_fi.properties b/Essentials/src/messages_fi.properties index 9e55910d6..4fd8d63b8 100644 --- a/Essentials/src/messages_fi.properties +++ b/Essentials/src/messages_fi.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_fr.properties b/Essentials/src/messages_fr.properties index c31d7851f..c3d4fb018 100644 --- a/Essentials/src/messages_fr.properties +++ b/Essentials/src/messages_fr.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a7c{0} \u00a7c {1} \u00a76ont \u00e9t\u00e9 supprim\u inventoryClearFail=\u00a74Le joueur {0} \u00a74n''a pas\u00a7c {1}\u00a7c {2}\u00a74 sur lui. +localNoOne= diff --git a/Essentials/src/messages_it.properties b/Essentials/src/messages_it.properties index 6930605d5..fc7feecfe 100644 --- a/Essentials/src/messages_it.properties +++ b/Essentials/src/messages_it.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_nl.properties b/Essentials/src/messages_nl.properties index 9dcdceda5..19f06a24a 100644 --- a/Essentials/src/messages_nl.properties +++ b/Essentials/src/messages_nl.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76\u00a7c {0} \u00a76stuks\u00a7c {1} \u00a76zijn ve inventoryClearFail=\u00a74Player {0} \u00a74heeft geen\u00a7c {1} \u00a74stuks\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_pl.properties b/Essentials/src/messages_pl.properties index 5a95201c8..c528fcd6d 100644 --- a/Essentials/src/messages_pl.properties +++ b/Essentials/src/messages_pl.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_pt.properties b/Essentials/src/messages_pt.properties index edec32a72..dcfd4369d 100644 --- a/Essentials/src/messages_pt.properties +++ b/Essentials/src/messages_pt.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_ro.properties b/Essentials/src/messages_ro.properties index c7700a095..f64e2e105 100644 --- a/Essentials/src/messages_ro.properties +++ b/Essentials/src/messages_ro.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_sv.properties b/Essentials/src/messages_sv.properties index 7bcdeebb8..c68077845 100644 --- a/Essentials/src/messages_sv.properties +++ b/Essentials/src/messages_sv.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Tog bort \u00a7c {0} \u00a76av\u00a7c {1} \u00a76f inventoryClearFail=\u00a74Spelaren {0} \u00a74har inte \u00a7c {1} \u00a74av\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_zh.properties b/Essentials/src/messages_zh.properties index 08d811ac2..fbec9bbfd 100644 --- a/Essentials/src/messages_zh.properties +++ b/Essentials/src/messages_zh.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_zh_HK.properties b/Essentials/src/messages_zh_HK.properties index ea78e8b05..75f79317c 100644 --- a/Essentials/src/messages_zh_HK.properties +++ b/Essentials/src/messages_zh_HK.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/messages_zh_TW.properties b/Essentials/src/messages_zh_TW.properties index 54d46f19b..fb51da23b 100644 --- a/Essentials/src/messages_zh_TW.properties +++ b/Essentials/src/messages_zh_TW.properties @@ -520,3 +520,4 @@ inventoryClearingStack=\u00a76Removed\u00a7c {0} \u00a76of\u00a7c {1} \u00a76fro inventoryClearFail=\u00a74Player {0} \u00a74does not have\u00a7c {1} \u00a74of\u00a7c {2}\u00a74. +localNoOne= diff --git a/Essentials/src/net/ess3/api/events/LocalChatSpyEvent.java b/Essentials/src/net/ess3/api/events/LocalChatSpyEvent.java index 8b3142967..d1de2204d 100644 --- a/Essentials/src/net/ess3/api/events/LocalChatSpyEvent.java +++ b/Essentials/src/net/ess3/api/events/LocalChatSpyEvent.java @@ -1,5 +1,9 @@ package net.ess3.api.events; +import static com.earth2me.essentials.I18n._; +import java.util.IllegalFormatException; +import java.util.Set; +import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -8,22 +12,95 @@ import org.bukkit.event.HandlerList; public class LocalChatSpyEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); - private boolean cancelled; + private boolean cancelled = false; + private String message; + private String format; + private Player player; + private final Set<Player> recipients; - public LocalChatSpyEvent() + public LocalChatSpyEvent(final boolean async, final Player who, final String format, final String message, final Set<Player> players) { + super(async); + this.format = _("chatTypeSpy").concat(format); + this.message = message; + recipients = players; + player = who; + } + /** + * Gets the message that the player is attempting to send. This message will be used with {@link #getFormat()}. + * + * @return Message the player is attempting to send + */ + public String getMessage() + { + return message; } - @Override - public HandlerList getHandlers() + /** + * Sets the message that the player will send. This message will be used with {@link #getFormat()}. + * + * @param message New message that the player will send + */ + public void setMessage(String message) { - return handlers; + this.message = message; } - public static HandlerList getHandlerList() + /** + * Gets the format to use to display this chat message. When this event finishes execution, the first format + * parameter is the {@link Player#getDisplayName()} and the second parameter is {@link #getMessage()} + * + * @return {@link String#format(String, Object...)} compatible format string + */ + public String getFormat() { - return handlers; + return format; + } + + /** + * Sets the format to use to display this chat message. When this event finishes execution, the first format + * parameter is the {@link Player#getDisplayName()} and the second parameter is {@link #getMessage()} + * + * @param format {@link String#format(String, Object...)} compatible format string + * @throws IllegalFormatException if the underlying API throws the exception + * @throws NullPointerException if format is null + * @see String#format(String, Object...) + */ + public void setFormat(final String format) throws IllegalFormatException, NullPointerException + { + // Oh for a better way to do this! + try + { + String.format(format, player, message); + } + catch (RuntimeException ex) + { + ex.fillInStackTrace(); + throw ex; + } + + this.format = format; + } + + /** + * Gets a set of recipients that this chat message will be displayed to. + * + * @return All Players who will see this chat message + */ + public Set<Player> getRecipients() + { + return recipients; + } + + /** + * Returns the player involved in this event + * + * @return Player who is involved in this event + */ + public final Player getPlayer() + { + return player; } @Override @@ -33,8 +110,19 @@ public class LocalChatSpyEvent extends Event implements Cancellable } @Override - public void setCancelled(boolean cancelled) + public void setCancelled(boolean cancel) + { + this.cancelled = cancel; + } + + @Override + public HandlerList getHandlers() { - this.cancelled = cancelled; + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; } } diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java index f16579a4d..bd975ebab 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java @@ -16,7 +16,6 @@ import org.bukkit.plugin.java.JavaPlugin; public class EssentialsChat extends JavaPlugin { private static final Logger LOGGER = Logger.getLogger("Minecraft"); - private transient Map<String, IEssentialsChatListener> chatListener; @Override public void onEnable() @@ -33,35 +32,16 @@ public class EssentialsChat extends JavaPlugin return; } - chatListener = new ConcurrentSkipListMap<String, IEssentialsChatListener>(); final Map<AsyncPlayerChatEvent, ChatStore> chatStore = Collections.synchronizedMap(new HashMap<AsyncPlayerChatEvent, ChatStore>()); - final EssentialsChatPlayerListenerLowest playerListenerLowest = new EssentialsChatPlayerListenerLowest(getServer(), ess, chatListener, chatStore); - final EssentialsChatPlayerListenerNormal playerListenerNormal = new EssentialsChatPlayerListenerNormal(getServer(), ess, chatListener, chatStore); - final EssentialsChatPlayerListenerHighest playerListenerHighest = new EssentialsChatPlayerListenerHighest(getServer(), ess, chatListener, chatStore); + 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); } - - @Override - public void onDisable() - { - if (chatListener != null) - { - chatListener.clear(); - } - } - - public void addEssentialsChatListener(final String plugin, final IEssentialsChatListener listener) - { - chatListener.put(plugin, listener); - } - - public IEssentialsChatListener removeEssentialsChatListener(final String plugin) - { - return chatListener.remove(plugin); - } + } diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java index 83996ea21..d47ba6a5c 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -19,17 +19,14 @@ public abstract class EssentialsChatPlayer implements Listener { protected transient IEssentials ess; protected final static Logger logger = Logger.getLogger("Minecraft"); - protected final transient Map<String, IEssentialsChatListener> listeners; protected final transient Server server; protected final transient Map<AsyncPlayerChatEvent, ChatStore> chatStorage; public EssentialsChatPlayer(final Server server, - final IEssentials ess, - final Map<String, IEssentialsChatListener> listeners, + final IEssentials ess, final Map<AsyncPlayerChatEvent, ChatStore> chatStorage) { this.ess = ess; - this.listeners = listeners; this.server = server; this.chatStorage = chatStorage; } @@ -43,31 +40,7 @@ public abstract class EssentialsChatPlayer implements Listener if (event.isCancelled()) { return true; - } - synchronized (listeners) - { - for (Map.Entry<String, IEssentialsChatListener> listener : listeners.entrySet()) - { - try - { - if (listener.getValue().shouldHandleThisChat(event)) - { - return true; - } - } - catch (Throwable t) - { - if (ess.getSettings().isDebug()) - { - logger.log(Level.WARNING, "Error with EssentialsChat listener of " + listener.getKey() + ": " + t.getMessage(), t); - } - else - { - logger.log(Level.WARNING, "Error with EssentialsChat listener of " + listener.getKey() + ": " + t.getMessage()); - } - } - } - } + } return false; } @@ -120,76 +93,4 @@ public abstract class EssentialsChatPlayer implements Listener } return true; } - - protected void sendLocalChat(final AsyncPlayerChatEvent event, final ChatStore chatStore) - { - event.setCancelled(true); - final User sender = chatStore.getUser(); - logger.info(_("localFormat", sender.getName(), event.getMessage())); - final Location loc = sender.getLocation(); - final World world = loc.getWorld(); - - if (charge(event, chatStore) == false) - { - return; - } - - for (Player onlinePlayer : event.getRecipients()) - { - String type = _("chatTypeLocal"); - final User onlineUser = ess.getUser(onlinePlayer); - if (!onlineUser.equals(sender)) - { - boolean abort = false; - final Location playerLoc = onlineUser.getLocation(); - if (playerLoc.getWorld() != world) - { - abort = true; - } - else - { - final double delta = playerLoc.distanceSquared(loc); - if (delta > chatStore.getRadius()) - { - abort = true; - } - } - if (abort) - { - if (onlineUser.isAuthorized("essentials.chat.spy")) - { - type = type.concat(_("chatTypeSpy")); - } - else - { - continue; - } - } - } - - String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage())); - synchronized (listeners) - { - for (Map.Entry<String, IEssentialsChatListener> listener : listeners.entrySet()) - { - try - { - message = listener.getValue().modifyMessage(event, onlinePlayer, message); - } - catch (Throwable t) - { - if (ess.getSettings().isDebug()) - { - logger.log(Level.WARNING, "Error with EssentialsChat listener of " + listener.getKey() + ": " + t.getMessage(), t); - } - else - { - logger.log(Level.WARNING, "Error with EssentialsChat listener of " + listener.getKey() + ": " + t.getMessage()); - } - } - } - } - onlineUser.sendMessage(message); - } - } } diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java index 9af8cf593..2e65c8959 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java @@ -12,10 +12,9 @@ public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer { public EssentialsChatPlayerListenerHighest(final Server server, final IEssentials ess, - final Map<String, IEssentialsChatListener> listeners, final Map<AsyncPlayerChatEvent, ChatStore> chatStorage) { - super(server, ess, listeners, chatStorage); + super(server, ess, chatStorage); } @EventHandler(priority = EventPriority.HIGHEST) diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java index 7eaaf2e0f..51472163f 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java @@ -19,10 +19,9 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer { public EssentialsChatPlayerListenerLowest(final Server server, final IEssentials ess, - final Map<String, IEssentialsChatListener> listeners, final Map<AsyncPlayerChatEvent, ChatStore> chatStorage) { - super(server, ess, listeners, chatStorage); + super(server, ess, chatStorage); } @EventHandler(priority = EventPriority.LOWEST) @@ -36,11 +35,12 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer final User user = ess.getUser(event.getPlayer()); - if (user == null) { + if (user == null) + { event.setCancelled(true); return; } - + final ChatStore chatStore = new ChatStore(ess, user, getChatType(event.getMessage())); setChatStore(event, chatStore); @@ -51,16 +51,16 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer String group = user.getGroup(); String world = user.getWorld().getName(); Team team = user.getScoreboard().getPlayerTeam(user.getBase()); - + String format = ess.getSettings().getChatFormat(group); format = format.replace("{0}", group); format = format.replace("{1}", world); format = format.replace("{2}", world.substring(0, 1).toUpperCase(Locale.ENGLISH)); - format = format.replace("{3}", team == null ? "" : team.getPrefix()); - format = format.replace("{4}", team == null ? "" : team.getSuffix()); - format = format.replace("{5}", team == null ? "" : team.getDisplayName()); + format = format.replace("{3}", team == null ? "" : team.getPrefix()); + format = format.replace("{4}", team == null ? "" : team.getSuffix()); + format = format.replace("{5}", team == null ? "" : team.getDisplayName()); synchronized (format) - { + { event.setFormat(format); } } diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java index 910518302..4fe8e7df5 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java @@ -3,9 +3,17 @@ package com.earth2me.essentials.chat; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.User; +import static com.earth2me.essentials.chat.EssentialsChatPlayer.logger; +import java.util.HashSet; +import java.util.Iterator; import java.util.Locale; import java.util.Map; +import java.util.Set; +import net.ess3.api.events.LocalChatSpyEvent; +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.player.AsyncPlayerChatEvent; @@ -15,12 +23,11 @@ public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer { public EssentialsChatPlayerListenerNormal(final Server server, final IEssentials ess, - final Map<String, IEssentialsChatListener> listeners, final Map<AsyncPlayerChatEvent, ChatStore> chatStorage) { - super(server, ess, listeners, chatStorage); + super(server, ess, chatStorage); } - + @EventHandler(priority = EventPriority.NORMAL) @Override public void onPlayerChat(final AsyncPlayerChatEvent event) @@ -33,40 +40,110 @@ 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 - */ + */ long radius = ess.getSettings().getChatRadius(); if (radius < 1) { return; } radius *= radius; - + final ChatStore chatStore = getChatStore(event); final User user = chatStore.getUser(); chatStore.setRadius(radius); - + if (event.getMessage().length() > 1 && chatStore.getType().length() > 0) { final StringBuilder permission = new StringBuilder(); permission.append("essentials.chat.").append(chatStore.getType()); - + if (user.isAuthorized(permission.toString())) { final StringBuilder format = new StringBuilder(); format.append(chatStore.getType()).append("Format"); event.setMessage(event.getMessage().substring(1)); - event.setFormat(_(format.toString(), event.getFormat())); + 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; } - - sendLocalChat(event, chatStore); + + final Location loc = user.getLocation(); + final World world = loc.getWorld(); + + if (charge(event, chatStore) == false) + { + return; + } + + Set<Player> outList = event.getRecipients(); + Set<Player> spyList = new HashSet<Player>(); + + try + { + outList.add(event.getPlayer()); + } + catch (UnsupportedOperationException ex) + { + if (ess.getSettings().isDebug()) + { + ess.getLogger().info("Plugin triggered custom chat event, local chat handling aborted."); + } + return; + } + + String type = _("chatTypeLocal"); + event.setFormat(type.concat(event.getFormat())); + + logger.info(_("localFormat", user.getName(), event.getMessage())); + + final Iterator<Player> it = outList.iterator(); + while (it.hasNext()) + { + final Player onlinePlayer = it.next(); + final User onlineUser = ess.getUser(onlinePlayer); + if (!onlineUser.equals(user)) + { + boolean abort = false; + final Location playerLoc = onlineUser.getLocation(); + if (playerLoc.getWorld() != world) + { + abort = true; + } + else + { + final double delta = playerLoc.distanceSquared(loc); + if (delta > chatStore.getRadius()) + { + abort = true; + } + } + if (abort) + { + if (onlineUser.isAuthorized("essentials.chat.spy")) + { + spyList.add(onlinePlayer); + } + outList.remove(onlinePlayer); + } + } + } + + LocalChatSpyEvent spyEvent = new LocalChatSpyEvent(event.isAsynchronous(), event.getPlayer(), event.getFormat(), event.getMessage(), spyList); + server.getPluginManager().callEvent(spyEvent); + + if (!spyEvent.isCancelled()) + { + for (Player onlinePlayer : spyEvent.getRecipients()) + { + onlinePlayer.sendMessage(String.format(event.getFormat(), user.getDisplayName(), event.getMessage())); + } + } } } diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/IEssentialsChatListener.java b/EssentialsChat/src/com/earth2me/essentials/chat/IEssentialsChatListener.java deleted file mode 100644 index abf5893ea..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/IEssentialsChatListener.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.earth2me.essentials.chat; - -import org.bukkit.entity.Player; -import org.bukkit.event.player.AsyncPlayerChatEvent; - - -public interface IEssentialsChatListener -{ - boolean shouldHandleThisChat(AsyncPlayerChatEvent event); - - String modifyMessage(AsyncPlayerChatEvent event, Player target, String message); -} |