Change some stuff around with ChatManager, change ChatAPI to route

through ChatManager.
This commit is contained in:
GJ 2013-01-25 18:21:17 -05:00
parent 18a4f5ed40
commit 85b909a7ab
3 changed files with 26 additions and 60 deletions

View File

@ -1,13 +1,8 @@
package com.gmail.nossr50.api; package com.gmail.nossr50.api;
import org.bukkit.entity.Player;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.events.chat.McMMOAdminChatEvent; import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.util.ChatManager;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
public final class ChatAPI { public final class ChatAPI {
@ -23,22 +18,8 @@ public final class ChatAPI {
* @param message The message to send * @param message The message to send
*/ */
public static void sendPartyChat(String sender, String party, String message) { public static void sendPartyChat(String sender, String party, String message) {
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(sender, party, message); ChatManager chatManager = new ChatManager(mcMMO.p, sender, message);
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); chatManager.handlePartyChat(PartyManager.getInstance().getParty(party));
if (chatEvent.isCancelled()) {
return;
}
mcMMO.p.getLogger().info("[P](" + chatEvent.getParty() + ")" + "<" + chatEvent.getSender() + "> " + chatEvent.getMessage());
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
if (Users.getProfile(player).inParty()) {
if (Users.getProfile(player).getParty().getName().equalsIgnoreCase(chatEvent.getParty())) {
player.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Prefix", new Object[] {chatEvent.getSender()} ) + chatEvent.getMessage());
}
}
}
} }
/** /**
@ -50,18 +31,7 @@ public final class ChatAPI {
* @param message The message to send * @param message The message to send
*/ */
public static void sendAdminChat(String sender, String message) { public static void sendAdminChat(String sender, String message) {
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(sender, message); ChatManager chatManager = new ChatManager(mcMMO.p, sender, message);
mcMMO.p.getServer().getPluginManager().callEvent(chatEvent); chatManager.handleAdminChat();
if (chatEvent.isCancelled()) {
return;
}
mcMMO.p.getLogger().info("[A]<" + chatEvent.getSender() + "> " + chatEvent.getMessage());
for (Player player : mcMMO.p.getServer().getOnlinePlayers()) {
if (Permissions.adminChat(player) || player.isOp())
player.sendMessage(LocaleLoader.getString("Commands.AdminChat.Prefix", new Object[] {chatEvent.getSender()} ) + chatEvent.getMessage());
}
} }
} }

View File

@ -23,6 +23,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.SkillType;
import com.gmail.nossr50.skills.Skills; import com.gmail.nossr50.skills.Skills;
@ -344,12 +345,21 @@ public class PlayerListener implements Listener {
} }
if (profile.getPartyChatMode()) { if (profile.getPartyChatMode()) {
ChatManager chatManager = new ChatManager(plugin, player, event); Party party = profile.getParty();
chatManager.handlePartyChat();
if (party == null) {
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return;
}
ChatManager chatManager = new ChatManager(plugin, player.getName(), event.getMessage());
chatManager.handlePartyChat(party);
event.setCancelled(true);
} }
else if (profile.getAdminChatMode()) { else if (profile.getAdminChatMode()) {
ChatManager chatManager = new ChatManager(plugin, player, event); ChatManager chatManager = new ChatManager(plugin, player.getName(), event.getMessage());
chatManager.handleAdminChat(); chatManager.handleAdminChat();
event.setCancelled(true);
} }
} }

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.util; package com.gmail.nossr50.util;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.events.chat.McMMOAdminChatEvent; import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
@ -11,19 +10,17 @@ import com.gmail.nossr50.party.Party;
public class ChatManager { public class ChatManager {
private mcMMO plugin; private mcMMO plugin;
private Player player;
private String playerName; private String playerName;
private AsyncPlayerChatEvent event; private String message;
public ChatManager (mcMMO plugin, Player player, AsyncPlayerChatEvent event) { public ChatManager (mcMMO plugin, String playerName, String message) {
this.plugin = plugin; this.plugin = plugin;
this.player = player; this.playerName = playerName;
this.playerName = player.getName(); this.message = message;
this.event = event;
} }
public void handleAdminChat() { public void handleAdminChat() {
McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(playerName, event.getMessage()); McMMOAdminChatEvent chatEvent = new McMMOAdminChatEvent(playerName, message);
plugin.getServer().getPluginManager().callEvent(chatEvent); plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
@ -39,21 +36,12 @@ public class ChatManager {
otherPlayer.sendMessage(LocaleLoader.getString("Commands.AdminChat.Prefix", new Object[] {playerName}) + adminMessage); otherPlayer.sendMessage(LocaleLoader.getString("Commands.AdminChat.Prefix", new Object[] {playerName}) + adminMessage);
} }
} }
event.setCancelled(true);
} }
public void handlePartyChat() { public void handlePartyChat(Party party) {
Party party = Users.getProfile(player).getParty();
if (party == null) {
player.sendMessage(LocaleLoader.getString("Commands.Party.None"));
return;
}
String partyName = party.getName(); String partyName = party.getName();
McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(playerName, partyName, event.getMessage()); McMMOPartyChatEvent chatEvent = new McMMOPartyChatEvent(playerName, partyName, message);
plugin.getServer().getPluginManager().callEvent(chatEvent); plugin.getServer().getPluginManager().callEvent(chatEvent);
if (chatEvent.isCancelled()) { if (chatEvent.isCancelled()) {
@ -67,7 +55,5 @@ public class ChatManager {
for (Player member : party.getOnlineMembers()) { for (Player member : party.getOnlineMembers()) {
member.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Prefix", new Object[] {playerName}) + partyMessage); member.sendMessage(LocaleLoader.getString("Commands.Party.Chat.Prefix", new Object[] {playerName}) + partyMessage);
} }
event.setCancelled(true);
} }
} }