diff options
Diffstat (limited to 'EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java')
-rw-r--r-- | EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java new file mode 100644 index 000000000..363e4ca6e --- /dev/null +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java @@ -0,0 +1,76 @@ +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; +import java.util.Map; +import org.bukkit.Server; +import org.bukkit.event.player.PlayerChatEvent; + + +public class EssentialsChatPlayerListenerNormal extends EssentialsChatPlayer +{ + public EssentialsChatPlayerListenerNormal(Server server, IEssentials ess, Map<String, IEssentialsChatListener> listeners) + { + super(server, ess, listeners); + } + + @Override + public void onPlayerChat(final PlayerChatEvent event) + { + if (isAborted(event)) + { + return; + } + + /** + * 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()); + 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); + + StringBuilder format = new StringBuilder(); + format.append(chatType).append("Format"); + + StringBuilder errorMsg = new StringBuilder(); + errorMsg.append("notAllowedTo").append(chatType.substring(0, 1).toUpperCase()).append(chatType.substring(1)); + + if (user.isAuthorized(permission.toString())) + { + charge(user, command.toString()); + event.setMessage(event.getMessage().substring(1)); + event.setFormat(_(format.toString(), event.getFormat())); + return; + } + + user.sendMessage(_(errorMsg.toString())); + event.setCancelled(true); + return; + } + } + catch (ChargeException ex) + { + ess.showError(user, ex, "Shout"); + event.setCancelled(true); + return; + } + sendLocalChat(user, radius, event); + } +} |