浏览代码

Fixed party & admin chat handling

GJ 13 年之前
父节点
当前提交
11a4fdfcd5

+ 2 - 1
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%)

+ 0 - 4
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);

+ 23 - 29
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<Player> recipients = event.getRecipients();
 
-        if (partyChat || adminChat) {
-            event.setCancelled(true);
+        Set<Player> intendedRecipients = new HashSet<Player>();
+        String header = "";
 
-            String name = "";
-            boolean displayNames = false;
-            ChatColor color = ChatColor.WHITE;
-            String logHeader = "";
+        if (partyChat || adminChat) {
 
-            /* 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();
             }
 
-            String format = color + "(" + ChatColor.WHITE + name + color + ") " + event.getMessage();
+            if (adminChat) {
+                header = ChatColor.AQUA + "[A] ";
 
-            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");
         }
     }
 

+ 0 - 2
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