From 11a4fdfcd5efb8515641af9d795a35b7cfd5c89b Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 10 Apr 2012 01:52:06 -0400 Subject: [PATCH] Fixed party & admin chat handling --- Changelog.txt | 3 +- .../gmail/nossr50/config/LoadProperties.java | 4 -- .../nossr50/listeners/mcPlayerListener.java | 54 +++++++++---------- src/main/resources/config.yml | 2 - 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 7d1f4acde..46da30b3d 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -18,7 +18,8 @@ Version 1.3.06-dev ! Changed PlayerProfile constructor to always take a boolean ! Changed getPlayerProfile function to work for online & offline users ! Changed Archery's Daze to deal 4 DMG on proc (2 Hearts) - ! Changed /addlevel command to work for offline users + ! Changed /addlevel command to work for offline users + ! Changed party & admin chat handling to be nicer to developers Version 1.3.05 + Added Skill Shot to Archery which increases damage dealt by 10% every 50 skill levels (caps at 200%) diff --git a/src/main/java/com/gmail/nossr50/config/LoadProperties.java b/src/main/java/com/gmail/nossr50/config/LoadProperties.java index 7ac9bc5d6..c0b002099 100644 --- a/src/main/java/com/gmail/nossr50/config/LoadProperties.java +++ b/src/main/java/com/gmail/nossr50/config/LoadProperties.java @@ -25,7 +25,6 @@ public class LoadProperties extends ConfigLoader{ mcstatsEnable, addxpEnable, ptpEnable, mmoeditEnable, mcremoveEnable, mcgodEnable, mcabilityEnable, mctopEnable, addlevelsEnable, mcrefreshEnable, aEnable, pEnable; - public static Boolean aDisplayNames, pDisplayNames; public static int ptpCommandCooldown; public static Boolean donateMessage; @@ -460,9 +459,6 @@ public class LoadProperties extends ConfigLoader{ aEnable = config.getBoolean("Commands.a.Enabled", true); pEnable = config.getBoolean("Commands.p.Enabled", true); - aDisplayNames = config.getBoolean("Commands.a.Display_Names", true); - pDisplayNames = config.getBoolean("Commands.p.Display_Names", true); - ptpCommandCooldown = config.getInt("Commands.ptp.Cooldown", 30); animalXP = config.getDouble("Experience.Combat.Multiplier.Animals", 1.0); diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index 6d978d6be..5dea39673 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -1,5 +1,8 @@ package com.gmail.nossr50.listeners; +import java.util.HashSet; +import java.util.Set; + import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -291,51 +294,42 @@ public class mcPlayerListener implements Listener { PlayerProfile PP = Users.getProfile(player); boolean partyChat = PP.getPartyChatMode(); boolean adminChat = PP.getAdminChatMode(); + Set recipients = event.getRecipients(); + + Set intendedRecipients = new HashSet(); + String header = ""; if (partyChat || adminChat) { - event.setCancelled(true); - String name = ""; - boolean displayNames = false; - ChatColor color = ChatColor.WHITE; - String logHeader = ""; - - /* Set the pChat & aChat specific stuff */ if (partyChat) { + if (!PP.inParty()) { player.sendMessage("You're not in a party, type /p to leave party chat mode."); //TODO: Use mcLocale return; } - displayNames = LoadProperties.pDisplayNames; - color = ChatColor.GREEN; - logHeader = "[P](" + PP.getParty() + ")<"; - } - else if (adminChat) { - displayNames = LoadProperties.aDisplayNames; - color = ChatColor.AQUA; - logHeader = "[A]<"; + header = ChatColor.GREEN + "[P] (" + PP.getParty() + ") "; + + for (Player x : plugin.getServer().getOnlinePlayers()) { + if (Party.getInstance().inSameParty(player, x)) { + intendedRecipients.add(x); + } + } + } - /* Format & display */ - if (displayNames) { - name = player.getDisplayName(); - } - else { - name = player.getName(); - } + if (adminChat) { + header = ChatColor.AQUA + "[A] "; - String format = color + "(" + ChatColor.WHITE + name + color + ") " + event.getMessage(); - - for (Player x : plugin.getServer().getOnlinePlayers()) { - if (partyChat && Party.getInstance().inSameParty(player, x)) - x.sendMessage(format); - else if (adminChat && (x.isOp() || mcPermissions.getInstance().adminChat(x))) { - x.sendMessage(format); + for (Player x : plugin.getServer().getOnlinePlayers()) { + if (x.isOp() || mcPermissions.getInstance().adminChat(x)) { + intendedRecipients.add(x); + } } } - Bukkit.getLogger().info(logHeader + name + ">" + event.getMessage()); + recipients.retainAll(intendedRecipients); + event.setFormat(header + "<%1$s> " + ChatColor.WHITE + "%2$s"); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3f36d9722..f42edde87 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -315,10 +315,8 @@ Commands: Cooldown: 30 p: Enabled: true - Display_Names: true a: Enabled: true - Display_Names: true # # Settings for Spout features