diff options
author | ementalo <ementalodev@gmx.co.uk> | 2012-05-28 00:37:28 +0100 |
---|---|---|
committer | ementalo <ementalodev@gmx.co.uk> | 2012-05-28 00:37:28 +0100 |
commit | 373a48da5412c6005f7ad2fe4bec41c68d4eb2a2 (patch) | |
tree | 3ebc11bffcb1dde3f3bd338fca97656d03511e70 /EssentialsChat/src | |
parent | 45c1e347b0698318ebd3772c540a9a52b6509daf (diff) | |
parent | b69a16bcf0abac1ebd2ca3d35520cfcb5b433e88 (diff) | |
download | Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.tar Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.tar.gz Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.tar.lz Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.tar.xz Essentials-373a48da5412c6005f7ad2fe4bec41c68d4eb2a2.zip |
Master -> 3.0
Diffstat (limited to 'EssentialsChat/src')
13 files changed, 390 insertions, 255 deletions
diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java b/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java new file mode 100644 index 000000000..9a8bd9e88 --- /dev/null +++ b/EssentialsChat/src/com/earth2me/essentials/chat/ChatPermissions.java @@ -0,0 +1,22 @@ +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<String, IPermission> permissions = new HashMap<String, IPermission>(); + + 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 index d353d5d6c..887ac8337 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/ChatStore.java @@ -1,25 +1,24 @@ package com.earth2me.essentials.chat; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.economy.Trade; +import com.earth2me.essentials.api.IEssentials; +import com.earth2me.essentials.api.IUser; public class ChatStore { - private final User user; - private final String type; - private final Trade charge; - private long radius; + private final transient IUser user; + private final transient String type; + private final transient Trade charge; - ChatStore(final IEssentials ess, final User user, final String type) + public ChatStore(final IEssentials ess, final IUser user, final String type) { this.user = user; this.type = type; this.charge = new Trade(getLongType(), ess); } - public User getUser() + public IUser getUser() { return user; } @@ -34,18 +33,8 @@ public class ChatStore return type; } - public String getLongType() + public final String getLongType() { return type.length() == 0 ? "chat" : "chat-" + type; } - - public long getRadius() - { - return radius; - } - - public void setRadius(long radius) - { - this.radius = radius; - } } diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java index 436bb55e5..a4d4283a7 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChat.java @@ -1,10 +1,12 @@ package com.earth2me.essentials.chat; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; +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.concurrent.ConcurrentSkipListMap; import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.event.player.PlayerChatEvent; @@ -15,13 +17,12 @@ 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() { final PluginManager pluginManager = getServer().getPluginManager(); - final IEssentials ess = (IEssentials)pluginManager.getPlugin("Essentials"); + final IEssentials ess = (IEssentials)pluginManager.getPlugin("Essentials3"); if (!this.getDescription().getVersion().equals(ess.getDescription().getVersion())) { LOGGER.log(Level.WARNING, _("versionMismatchAll")); @@ -32,35 +33,21 @@ public class EssentialsChat extends JavaPlugin return; } - chatListener = new ConcurrentSkipListMap<String, IEssentialsChatListener>(); final Map<PlayerChatEvent, ChatStore> chatStore = new HashMap<PlayerChatEvent, 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); + final EssentialsLocalChatEventListener localChatListener = new EssentialsLocalChatEventListener(getServer(), ess); + pluginManager.registerEvents(localChatListener, 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 6bdab0919..6a86de1f1 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayer.java @@ -1,15 +1,19 @@ package com.earth2me.essentials.chat; -import com.earth2me.essentials.ChargeException; +import com.earth2me.essentials.api.ChargeException; import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.Trade; -import com.earth2me.essentials.User; +import com.earth2me.essentials.economy.Trade; +import com.earth2me.essentials.utils.Util; +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.permissions.Permissions; +import java.util.Locale; import java.util.Map; import java.util.logging.Logger; -import org.bukkit.Location; import org.bukkit.Server; -import org.bukkit.World; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChatEvent; @@ -18,18 +22,15 @@ import org.bukkit.event.player.PlayerChatEvent; 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 static Logger LOGGER = Logger.getLogger("Minecraft"); protected final transient Server server; protected final transient Map<PlayerChatEvent, ChatStore> chatStorage; public EssentialsChatPlayer(final Server server, final IEssentials ess, - final Map<String, IEssentialsChatListener> listeners, final Map<PlayerChatEvent, ChatStore> chatStorage) { this.ess = ess; - this.listeners = listeners; this.server = server; this.chatStorage = chatStorage; } @@ -38,35 +39,6 @@ public abstract class EssentialsChatPlayer implements Listener { } - public boolean isAborted(final PlayerChatEvent event) - { - if (event.isCancelled()) - { - return true; - } - for (IEssentialsChatListener listener : listeners.values()) - { - if (listener.shouldHandleThisChat(event)) - { - return true; - } - } - return false; - } - - public String getChatType(final String message) - { - switch (message.charAt(0)) - { - case '!': - return "shout"; - case '?': - return "question"; - default: - return ""; - } - } - public ChatStore getChatStore(final PlayerChatEvent event) { return chatStorage.get(event); @@ -82,12 +54,7 @@ public abstract class EssentialsChatPlayer implements Listener return chatStorage.remove(event); } - protected void charge(final User user, final Trade charge) throws ChargeException - { - charge.charge(user); - } - - protected boolean charge(final PlayerChatEvent event, final ChatStore chatStore) + protected void chargeChat(final PlayerChatEvent event, final ChatStore chatStore) { try { @@ -95,34 +62,85 @@ public abstract class EssentialsChatPlayer implements Listener } catch (ChargeException e) { - ess.showError(chatStore.getUser(), e, chatStore.getLongType()); + ess.getCommandHandler().showCommandError(chatStore.getUser(), chatStore.getLongType(), e); event.setCancelled(true); - return false; } - return true; } - protected void sendLocalChat(final PlayerChatEvent event, final ChatStore chatStore) + protected void charge(final CommandSender sender, final Trade charge) throws ChargeException { - 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 (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(); - if (charge(event, chatStore) == false) + 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; } - for (Player onlinePlayer : server.getOnlinePlayers()) + radius *= radius; + + final IUser user = chatStore.getUser(); + + if (event.getMessage().length() > 1 && chatStore.getType().length() > 0) { - String type = _("chatTypeLocal"); - final User onlineUser = ess.getUser(onlinePlayer); - //TODO: remove reference to op - if (onlineUser.isIgnoredPlayer(sender.getName()) && !sender.isOp()) + if (ChatPermissions.getPermission(chatStore.getType()).isAuthorized(user)) { - continue; + final StringBuilder format = new StringBuilder(); + format.append(chatStore.getType()).append("Format"); + event.setMessage(event.getMessage().substring(1)); + event.setFormat(_(format.toString(), event.getFormat())); + return; } if (!onlineUser.equals(sender)) { @@ -145,12 +163,16 @@ public abstract class EssentialsChatPlayer implements Listener } } - String message = String.format(event.getFormat(), type.concat(sender.getDisplayName()), event.getMessage()); - for (IEssentialsChatListener listener : listeners.values()) - { - message = listener.modifyMessage(event, onlinePlayer, message); - } - onlineUser.sendMessage(message); + 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/EssentialsChatPlayerListenerLowest.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java deleted file mode 100644 index 599c39dda..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerLowest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.earth2me.essentials.chat; - -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; -import com.earth2me.essentials.Util; -import java.util.Locale; -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<String, IEssentialsChatListener> listeners, - final Map<PlayerChatEvent, ChatStore> chatStorage) - { - super(server, ess, listeners, chatStorage); - } - - @EventHandler(priority = EventPriority.LOWEST) - @Override - public void onPlayerChat(final PlayerChatEvent event) - { - if (isAborted(event)) - { - return; - } - - final User user = ess.getUser(event.getPlayer()); - final ChatStore chatStore = new ChatStore(ess, user, getChatType(event.getMessage())); - setChatStore(event, chatStore); - - /** - * This listener should apply the general chat formatting only...then return control back the event handler - */ - 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) - })); - } -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java deleted file mode 100644 index fdaccdc8d..000000000 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerNormal.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.earth2me.essentials.chat; - -import static com.earth2me.essentials.I18n._; -import com.earth2me.essentials.IEssentials; -import com.earth2me.essentials.User; -import java.util.Locale; -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<String, IEssentialsChatListener> listeners, - final Map<PlayerChatEvent, ChatStore> chatStorage) - { - super(server, ess, listeners, chatStorage); - } - - @EventHandler(priority = EventPriority.NORMAL) - @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 - */ - 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())); - 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); - } -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java new file mode 100644 index 000000000..2eae385a9 --- /dev/null +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEvent.java @@ -0,0 +1,110 @@ +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; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + 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 new file mode 100644 index 000000000..401fa1142 --- /dev/null +++ b/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsLocalChatEventListener.java @@ -0,0 +1,71 @@ +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; +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; + private static final Logger LOGGER = Logger.getLogger("Minecraft"); + + 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); + //TODO: remove reference to op + if (user.isIgnoringPlayer(sender.getName()) && !sender.isOp()) + { + continue; + } + if (!user.equals(sender)) + { + final Location playerLoc = user.getLocation(); + if (playerLoc.getWorld() != world) + { + continue; + } + final double delta = playerLoc.distanceSquared(loc); + + if (delta > event.getRadius()) + { + if (Permissions.CHAT_SPY.isAuthorized(user)) + { + type = type.concat(_("chatTypeSpy")); + } + else + { + continue; + } + } + } + + final String message = type.concat(String.format(event.getFormat(), sender.getDisplayName(), event.getMessage())); + user.sendMessage(message); + } + } +}
\ No newline at end of file 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 5c9c5c219..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.PlayerChatEvent; - - -public interface IEssentialsChatListener -{ - boolean shouldHandleThisChat(PlayerChatEvent event); - - String modifyMessage(PlayerChatEvent event, Player target, String message); -} diff --git a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java b/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java index e8f785228..576c93e6f 100644 --- a/EssentialsChat/src/com/earth2me/essentials/chat/EssentialsChatPlayerListenerHighest.java +++ b/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerHighest.java @@ -1,6 +1,8 @@ -package com.earth2me.essentials.chat; +package com.earth2me.essentials.chat.listenerlevel; -import com.earth2me.essentials.IEssentials; +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; @@ -12,10 +14,9 @@ public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer { public EssentialsChatPlayerListenerHighest(final Server server, final IEssentials ess, - final Map<String, IEssentialsChatListener> listeners, final Map<PlayerChatEvent, ChatStore> chatStorage) { - super(server, ess, listeners, chatStorage); + super(server, ess, chatStorage); } @EventHandler(priority = EventPriority.HIGHEST) @@ -23,14 +24,10 @@ public class EssentialsChatPlayerListenerHighest extends EssentialsChatPlayer public void onPlayerChat(final PlayerChatEvent event) { final ChatStore chatStore = delChatStore(event); - if (isAborted(event)) + if (event.isCancelled()) { return; } - - /** - * This file should handle charging the user for the action before returning control back - */ - charge(event, chatStore); + 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 new file mode 100644 index 000000000..3fcff995c --- /dev/null +++ b/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerLowest.java @@ -0,0 +1,36 @@ +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<PlayerChatEvent, ChatStore> 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 new file mode 100644 index 000000000..c456b700d --- /dev/null +++ b/EssentialsChat/src/com/earth2me/essentials/chat/listenerlevel/EssentialsChatPlayerListenerNormal.java @@ -0,0 +1,33 @@ +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<PlayerChatEvent, ChatStore> 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 af0ed0c13..488ef7b50 100644 --- a/EssentialsChat/src/plugin.yml +++ b/EssentialsChat/src/plugin.yml @@ -2,9 +2,9 @@ name: EssentialsChat main: com.earth2me.essentials.chat.EssentialsChat # Note to developers: This next line cannot change, or the automatic versioning system will break. -version: TeamCity -website: http://tiny.cc/EssentialsCommands +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: [Essentials] +depend: [Essentials3] #softdepend: [Factions]
\ No newline at end of file |