diff --git a/src/main/java/com/gmail/nossr50/commands/party/ACommand.java b/src/main/java/com/gmail/nossr50/commands/party/ACommand.java index e8c9bb9f2..9f4d909de 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/ACommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/ACommand.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.datatypes.PlayerProfile; +import com.gmail.nossr50.events.chat.McMMOAdminChatEvent; import com.gmail.nossr50.locale.mcLocale; public class ACommand implements CommandExecutor { @@ -26,6 +27,13 @@ public class ACommand implements CommandExecutor { aMessage = aMessage + " " + args[i]; } + McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent("Console", aMessage); + Bukkit.getPluginManager().callEvent(chatEvent); + + if(chatEvent.isCancelled()) return true; + + aMessage = chatEvent.getMessage(); + String aPrefix = ChatColor.AQUA + "{" + ChatColor.WHITE + "*Console*" + ChatColor.AQUA + "} "; Bukkit.getLogger().info("[A]<*Console*> " + aMessage); diff --git a/src/main/java/com/gmail/nossr50/commands/party/PCommand.java b/src/main/java/com/gmail/nossr50/commands/party/PCommand.java index bee20a978..5179adfc2 100644 --- a/src/main/java/com/gmail/nossr50/commands/party/PCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/party/PCommand.java @@ -10,6 +10,7 @@ import org.bukkit.entity.Player; import com.gmail.nossr50.Users; import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.datatypes.PlayerProfile; +import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.locale.mcLocale; public class PCommand implements CommandExecutor { @@ -27,6 +28,13 @@ public class PCommand implements CommandExecutor { pMessage = pMessage + " " + args[i]; } + McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent("Console", args[0], pMessage); + Bukkit.getPluginManager().callEvent(chatEvent); + + if(chatEvent.isCancelled()) return true; + + pMessage = chatEvent.getMessage(); + String pPrefix = ChatColor.GREEN + "(" + ChatColor.WHITE + "*Console*" + ChatColor.GREEN + ") "; Bukkit.getLogger().info("[P](" + args[0] + ")" + "<*Console*> " + pMessage); diff --git a/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java b/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java new file mode 100644 index 000000000..0c7f86c32 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/chat/McMMOAdminChatEvent.java @@ -0,0 +1,62 @@ +package com.gmail.nossr50.events.chat; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Called when a chat is sent to the admin chat channel + */ +public class McMMOAdminChatEvent extends Event implements Cancellable { + private boolean cancelled; + private String sender, message; + + public McMMOAdminChatEvent(String sender, String message) { + this.sender = sender; + this.message = message; + } + + /** + * @return String name of the player who sent the chat, or "Console" + */ + public String getSender() { + return sender; + } + + /** + * @return String message that will be sent + */ + public String getMessage() { + return message; + } + + /** + * @param message String message to be sent in chat + */ + public void setMessage(String message) { + this.message = message; + } + + /** Rest of file is required boilerplate for custom events **/ + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + /** Following are required for Cancellable **/ + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } +} diff --git a/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java b/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java new file mode 100644 index 000000000..e527233ec --- /dev/null +++ b/src/main/java/com/gmail/nossr50/events/chat/McMMOPartyChatEvent.java @@ -0,0 +1,70 @@ +package com.gmail.nossr50.events.chat; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Called when a chat is sent to a party channel + */ +public class McMMOPartyChatEvent extends Event implements Cancellable { + private boolean cancelled; + private String sender, party, message; + + public McMMOPartyChatEvent(String sender, String party, String message) { + this.sender = sender; + this.party = party; + this.message = message; + } + + /** + * @return String name of the player who sent the chat, or "Console" + */ + public String getSender() { + return sender; + } + + /** + * @return String name of the party the message will be sent to + */ + public String getParty() { + return party; + } + + /** + * @return String message that will be sent + */ + public String getMessage() { + return message; + } + + /** + * @param message String message to be sent in chat + */ + public void setMessage(String message) { + this.message = message; + } + + /** Rest of file is required boilerplate for custom events **/ + private static final HandlerList handlers = new HandlerList(); + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + /** Following are required for Cancellable **/ + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } +} diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index 6ae39a75b..b1363e2ad 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -39,6 +39,8 @@ import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.datatypes.AbilityType; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.events.chat.McMMOAdminChatEvent; +import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.locale.mcLocale; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.skills.BlastMining; @@ -300,9 +302,7 @@ public class mcPlayerListener implements Listener { ChatColor color = null; if (partyChat || adminChat) { - if (partyChat) { - if (!PP.inParty()) { player.sendMessage("You're not in a party, type /p to leave party chat mode."); //TODO: Use mcLocale return; @@ -310,6 +310,13 @@ public class mcPlayerListener implements Listener { color = ChatColor.GREEN; + McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(player.getName(), PP.getParty(), event.getMessage()); + plugin.getServer().getPluginManager().callEvent(chatEvent); + + if(chatEvent.isCancelled()) return; + + event.setMessage(chatEvent.getMessage()); + for (Player x : plugin.getServer().getOnlinePlayers()) { if (Party.getInstance().inSameParty(player, x)) { intendedRecipients.add(x); @@ -321,6 +328,14 @@ public class mcPlayerListener implements Listener { if (adminChat) { color = ChatColor.AQUA; + + McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(player.getName(), event.getMessage()); + plugin.getServer().getPluginManager().callEvent(chatEvent); + + if(chatEvent.isCancelled()) return; + + event.setMessage(chatEvent.getMessage()); + for (Player x : plugin.getServer().getOnlinePlayers()) { if (x.isOp() || mcPermissions.getInstance().adminChat(x)) { intendedRecipients.add(x);