From a1c8d1ac4132eb7baebb719ef93b720408f63a9b Mon Sep 17 00:00:00 2001 From: snowleo Date: Sun, 11 Dec 2011 09:22:27 +0100 Subject: Fix sorting of users in /who --- Essentials/src/com/earth2me/essentials/User.java | 2 +- Essentials/src/com/earth2me/essentials/Util.java | 11 +++++++++++ .../src/com/earth2me/essentials/commands/Commandrealname.java | 6 +++--- .../src/com/earth2me/essentials/commands/Commandwhois.java | 5 ++--- .../src/com/earth2me/essentials/signs/SignProtection.java | 4 ++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index abe11179b..8c678d734 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -175,7 +175,7 @@ public class User extends UserData implements Comparable, IReplyTo, IUser @Override public int compareTo(final User other) { - return this.getName().compareToIgnoreCase(other.getName()); + return Util.stripColor(this.getDisplayName()).compareToIgnoreCase(Util.stripColor(other.getDisplayName())); } @Override diff --git a/Essentials/src/com/earth2me/essentials/Util.java b/Essentials/src/com/earth2me/essentials/Util.java index fe86fd167..6a1df197f 100644 --- a/Essentials/src/com/earth2me/essentials/Util.java +++ b/Essentials/src/com/earth2me/essentials/Util.java @@ -477,4 +477,15 @@ public class Util } return buf.toString(); } + private static transient final Pattern COLOR_PATTERN = Pattern.compile("(?i)\u00A7[0-9A-F]"); + + public static String stripColor(final String input) + { + if (input == null) + { + return null; + } + + return COLOR_PATTERN.matcher(input).replaceAll(""); + } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index 6266b5178..b48ac5bcb 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -2,8 +2,8 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; +import com.earth2me.essentials.Util; import java.util.Locale; -import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,9 +31,9 @@ public class Commandrealname extends EssentialsCommand { continue; } - final String displayName = ChatColor.stripColor(u.getDisplayName()).toLowerCase(Locale.ENGLISH); + final String displayName = Util.stripColor(u.getDisplayName()).toLowerCase(Locale.ENGLISH); if (!whois.equals(displayName) - && !displayName.equals(ChatColor.stripColor(ess.getSettings().getNicknamePrefix()) + whois) + && !displayName.equals(Util.stripColor(ess.getSettings().getNicknamePrefix()) + whois) && !whois.equalsIgnoreCase(u.getName())) { continue; diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index c5d10a2e8..7e211455e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -4,7 +4,6 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; import java.util.Locale; -import org.bukkit.ChatColor; import org.bukkit.Server; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -37,7 +36,7 @@ public class Commandwhois extends EssentialsCommand showhidden = true; } final String whois = args[0].toLowerCase(Locale.ENGLISH); - final int prefixLength = ChatColor.stripColor(ess.getSettings().getNicknamePrefix()).length(); + final int prefixLength = Util.stripColor(ess.getSettings().getNicknamePrefix()).length(); for (Player onlinePlayer : server.getOnlinePlayers()) { final User user = ess.getUser(onlinePlayer); @@ -45,7 +44,7 @@ public class Commandwhois extends EssentialsCommand { continue; } - final String nickName = ChatColor.stripColor(user.getNickname()); + final String nickName = Util.stripColor(user.getNickname()); if (!whois.equalsIgnoreCase(nickName) && !whois.substring(prefixLength).equalsIgnoreCase(nickName) && !whois.equalsIgnoreCase(user.getName())) diff --git a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java index e82759655..f64b6f3f1 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignProtection.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignProtection.java @@ -5,8 +5,8 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.IEssentials; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; +import com.earth2me.essentials.Util; import java.util.*; -import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -147,7 +147,7 @@ public class SignProtection extends EssentialsSign { return SignProtectionState.OWNER; } - if (ChatColor.stripColor(sign.getLine(3)).equalsIgnoreCase(username)) + if (Util.stripColor(sign.getLine(3)).equalsIgnoreCase(username)) { return SignProtectionState.OWNER; } -- cgit v1.2.3