From 46648e2547353f13e172d615725e727ad0f52b17 Mon Sep 17 00:00:00 2001 From: NuclearW Date: Wed, 18 Apr 2012 13:18:25 -0400 Subject: [PATCH] Added ChatAPI Allows an external plugin to send admin and party chat In addition to previous events allows for full control of the chat channels --- .../java/com/gmail/nossr50/api/ChatAPI.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/com/gmail/nossr50/api/ChatAPI.java diff --git a/src/main/java/com/gmail/nossr50/api/ChatAPI.java b/src/main/java/com/gmail/nossr50/api/ChatAPI.java new file mode 100644 index 000000000..9c5582f93 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/api/ChatAPI.java @@ -0,0 +1,64 @@ +package com.gmail.nossr50.api; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import com.gmail.nossr50.Users; +import com.gmail.nossr50.mcPermissions; +import com.gmail.nossr50.events.chat.McMMOAdminChatEvent; +import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; + +public class ChatAPI { + /** + * Send a message to all members of a party + *
+ * This function is designed for API usage. + * + * @param sender The name of the sender to display in the chat + * @param party The name of the party to send to + * @param message The message to send + */ + public void sendPartyChat(String sender, String party, String message) { + McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(sender, party, message); + Bukkit.getPluginManager().callEvent(chatEvent); + + if(chatEvent.isCancelled()) return; + + String pPrefix = ChatColor.GREEN + "(" + ChatColor.WHITE + chatEvent.getSender() + ChatColor.GREEN + ") "; + + Bukkit.getLogger().info("[P](" + chatEvent.getParty() + ")" + "<" + chatEvent.getSender() + "> " + chatEvent.getMessage()); + + for (Player player : Bukkit.getServer().getOnlinePlayers()) { + if (Users.getProfile(player).inParty()) { + if (Users.getProfile(player).getParty().equalsIgnoreCase(chatEvent.getParty())) { + player.sendMessage(pPrefix + chatEvent.getMessage()); + } + } + } + } + + /** + * Send a message to administrators + *
+ * This function is designed for API usage. + * + * @param sender The name of the sender to display in the chat + * @param message The message to send + */ + public void sendAdminChat(String sender, String message) { + McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(sender, message); + Bukkit.getPluginManager().callEvent(chatEvent); + + if(chatEvent.isCancelled()) return; + + String aPrefix = ChatColor.AQUA + "{" + ChatColor.WHITE + chatEvent.getSender() + ChatColor.AQUA + "} "; + + Bukkit.getLogger().info("[A]<" + chatEvent.getSender() + "> " + chatEvent.getMessage()); + + for (Player player : Bukkit.getServer().getOnlinePlayers()) { + if (mcPermissions.getInstance().adminChat(player) || player.isOp()) + player.sendMessage(aPrefix + chatEvent.getMessage()); + } + } +}