From 7bcec32134b5bf62d60b235471f6350979b65e76 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Wed, 21 Mar 2012 23:54:57 +0000 Subject: [PATCH] Cleaning up displaynames --- .../essentials/EssentialsPlayerListener.java | 21 ++------ .../src/com/earth2me/essentials/User.java | 54 +++++++++++-------- .../essentials/commands/Commandafk.java | 1 + .../essentials/commands/Commandhelpop.java | 2 +- .../essentials/commands/Commandlist.java | 10 ++-- .../essentials/commands/Commandme.java | 5 +- .../essentials/commands/Commandrealname.java | 1 + .../essentials/commands/Commandseen.java | 12 +++-- .../essentials/commands/Commandsuicide.java | 1 + .../essentials/commands/Commandwhois.java | 1 + .../textreader/KeywordReplacer.java | 1 + 11 files changed, 58 insertions(+), 51 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index c1bd9bbe0..43adf0a6f 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -43,10 +43,7 @@ public class EssentialsPlayerListener implements Listener { final User user = ess.getUser(event.getPlayer()); updateCompass(user); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayNick(); - } + user.setDisplayNick(); } @EventHandler(priority = EventPriority.LOWEST) @@ -69,10 +66,7 @@ public class EssentialsPlayerListener implements Listener } } user.updateActivity(true); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayNick(); - } + user.setDisplayNick(); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @@ -127,11 +121,7 @@ public class EssentialsPlayerListener implements Listener { ess.getBackup().onPlayerJoin(); final User user = ess.getUser(event.getPlayer()); - - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayNick(); - } + user.setDisplayNick(); user.setLastLoginAddress(user.getAddress().getAddress().getHostAddress()); user.updateActivity(false); if (user.isAuthorized("essentials.sleepingignored")) @@ -297,10 +287,7 @@ public class EssentialsPlayerListener implements Listener public void onPlayerChangedWorld(final PlayerChangedWorldEvent event) { final User user = ess.getUser(event.getPlayer()); - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayNick(); - } + user.setDisplayNick(); updateCompass(user); if (ess.getSettings().getNoGodWorlds().contains(event.getPlayer().getLocation().getWorld().getName())) diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index 3d5cbb398..a41fd1b5f 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -71,10 +71,12 @@ public class User extends UserData implements Comparable, IReplyTo, IUser return false; } - try { + try + { return ess.getPermissionsHandler().hasPermission(base, node); } - catch (Exception ex) { + catch (Exception ex) + { ess.getLogger().log(Level.SEVERE, "Permission System Error: " + ess.getPermissionsHandler().getName() + " returned: " + ex.getMessage()); return false; } @@ -289,6 +291,10 @@ public class User extends UserData implements Comparable, IReplyTo, IUser { final String prefix = ess.getPermissionsHandler().getPrefix(base).replace('&', '§'); nickname.insert(0, prefix); + if (prefix.length() < 2 || prefix.charAt(0) != '&') + { + nickname.insert(0, "&f"); + } } if (!ess.getSettings().disableSuffix()) { @@ -310,24 +316,28 @@ public class User extends UserData implements Comparable, IReplyTo, IUser public void setDisplayNick() { - String name = getNick(true); - setDisplayName(name); - if (name.length() > 16) + if (base.isOnline() && ess.getSettings().changeDisplayName()) { - name = getNick(false); - } - if (name.length() > 16) - { - name = name.substring(0, name.charAt(15) == '§' ? 15 : 16); - } - try - { - setPlayerListName(name); - } - catch (IllegalArgumentException e) - { - if (ess.getSettings().isDebug()) { - logger.log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player."); + String name = getNick(true); + setDisplayName(name); + if (name.length() > 16) + { + name = getNick(false); + } + if (name.length() > 16) + { + name = Util.stripColor(name); + } + try + { + setPlayerListName(name); + } + catch (IllegalArgumentException e) + { + if (ess.getSettings().isDebug()) + { + logger.log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player."); + } } } } @@ -335,10 +345,6 @@ public class User extends UserData implements Comparable, IReplyTo, IUser @Override public String getDisplayName() { - if (base.isOnline() && ess.getSettings().changeDisplayName()) - { - setDisplayNick(); - } return super.getDisplayName() == null ? super.getName() : super.getDisplayName(); } @@ -498,6 +504,7 @@ public class User extends UserData implements Comparable, IReplyTo, IUser setAfk(false); if (broadcast && !isHidden()) { + setDisplayNick(); ess.broadcastMessage(this, _("userIsNotAway", getDisplayName())); } } @@ -530,6 +537,7 @@ public class User extends UserData implements Comparable, IReplyTo, IUser setAfk(true); if (!isHidden()) { + setDisplayNick(); ess.broadcastMessage(this, _("userIsAway", getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java index a1c83606c..c71883571 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandafk.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandafk.java @@ -31,6 +31,7 @@ public class Commandafk extends EssentialsCommand private void toggleAfk(User user) { + user.setDisplayNick(); if (!user.toggleAfk()) { //user.sendMessage(_("markedAsNotAway")); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java index 20cd5cdd3..f26154f71 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhelpop.java @@ -22,7 +22,7 @@ public class Commandhelpop extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - + user.setDisplayNick(); final String message = _("helpOp", user.getDisplayName(), Util.stripColor(getFinalArg(args, 0))); logger.log(Level.INFO, message); for (Player onlinePlayer : server.getOnlinePlayers()) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java index 77788c7c2..7e699328b 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandlist.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandlist.java @@ -44,8 +44,10 @@ public class Commandlist extends EssentialsCommand if (showhidden && playerHidden > 0) { online = _("listAmountHidden", server.getOnlinePlayers().length - playerHidden, playerHidden, server.getMaxPlayers()); - } else { - online = _("listAmount",server.getOnlinePlayers().length - playerHidden, server.getMaxPlayers()); + } + else + { + online = _("listAmount", server.getOnlinePlayers().length - playerHidden, server.getMaxPlayers()); } sender.sendMessage(online); @@ -73,7 +75,7 @@ public class Commandlist extends EssentialsCommand for (String group : groups) { final StringBuilder groupString = new StringBuilder(); - groupString.append(_("listGroupTag",Util.replaceColor(group))); + groupString.append(_("listGroupTag", Util.replaceColor(group))); final List users = sort.get(group); Collections.sort(users); boolean first = true; @@ -95,6 +97,7 @@ public class Commandlist extends EssentialsCommand { groupString.append(_("listHiddenTag")); } + user.setDisplayNick(); groupString.append(user.getDisplayName()); groupString.append("§f"); } @@ -136,6 +139,7 @@ public class Commandlist extends EssentialsCommand { onlineUsers.append(_("listHiddenTag")); } + user.setDisplayNick(); onlineUsers.append(user.getDisplayName()); onlineUsers.append("§f"); } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandme.java b/Essentials/src/com/earth2me/essentials/commands/Commandme.java index 1530f3ad7..0bf2a536d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandme.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandme.java @@ -31,11 +31,12 @@ public class Commandme extends EssentialsCommand { message = Util.replaceColor(message); } - else { + else + { message = Util.stripColor(message); } - + user.setDisplayNick(); ess.broadcastMessage(user, _("action", user.getDisplayName(), message)); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java index b48ac5bcb..6f9049756 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandrealname.java @@ -31,6 +31,7 @@ public class Commandrealname extends EssentialsCommand { continue; } + u.setDisplayNick(); final String displayName = Util.stripColor(u.getDisplayName()).toLowerCase(Locale.ENGLISH); if (!whois.equals(displayName) && !displayName.equals(Util.stripColor(ess.getSettings().getNicknamePrefix()) + whois) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java index 2783fb68e..38abb2dab 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandseen.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandseen.java @@ -17,16 +17,16 @@ public class Commandseen extends EssentialsCommand @Override protected void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { - seen(server,sender,args,true); + seen(server, sender, args, true); } - + @Override protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception { - seen(server,user,args,user.isAuthorized("essentials.seen.banreason")); + seen(server, user, args, user.isAuthorized("essentials.seen.banreason")); } - - protected void seen (final Server server, final CommandSender sender, final String[] args, final boolean show) throws Exception + + protected void seen(final Server server, final CommandSender sender, final String[] args, final boolean show) throws Exception { if (args.length < 1) { @@ -35,6 +35,7 @@ public class Commandseen extends EssentialsCommand try { User player = getPlayer(server, args, 0); + player.setDisplayNick(); sender.sendMessage(_("seenOnline", player.getDisplayName(), Util.formatDateDiff(player.getLastLogin()))); } catch (NoSuchFieldException e) @@ -44,6 +45,7 @@ public class Commandseen extends EssentialsCommand { throw new Exception(_("playerNotFound")); } + player.setDisplayNick(); sender.sendMessage(_("seenOffline", player.getDisplayName(), Util.formatDateDiff(player.getLastLogout()))); if (player.isBanned()) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java index d6afe707a..50933c8f5 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsuicide.java @@ -21,6 +21,7 @@ public class Commandsuicide extends EssentialsCommand user.damage(1000); user.setHealth(0); user.sendMessage(_("suicideMessage")); + user.setDisplayNick(); ess.broadcastMessage(user,_("suicideSuccess", user.getDisplayName())); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java index 8adc4c95c..4f1c2267a 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java @@ -53,6 +53,7 @@ public class Commandwhois extends EssentialsCommand continue; } sender.sendMessage(""); + user.setDisplayNick(); sender.sendMessage(_("whoisIs", user.getDisplayName(), user.getName())); sender.sendMessage(_("whoisHealth", user.getHealth())); sender.sendMessage(_("whoisExp", SetExpFix.getTotalExperience(user), user.getLevel())); diff --git a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java index 4c4e3364b..d79483699 100644 --- a/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java +++ b/Essentials/src/com/earth2me/essentials/textreader/KeywordReplacer.java @@ -37,6 +37,7 @@ public class KeywordReplacer implements IText if (sender instanceof Player) { final User user = ess.getUser(sender); + user.setDisplayNick(); displayName = user.getDisplayName(); userName = user.getName(); ipAddress = user.getAddress().getAddress().toString();