Cleaning up displaynames

This commit is contained in:
KHobbits 2012-03-21 23:54:57 +00:00
parent 3e88fb44f4
commit 7bcec32134
11 changed files with 58 additions and 51 deletions

View File

@ -43,11 +43,8 @@ public class EssentialsPlayerListener implements Listener
{
final User user = ess.getUser(event.getPlayer());
updateCompass(user);
if (ess.getSettings().changeDisplayName())
{
user.setDisplayNick();
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(final PlayerChatEvent event)
@ -69,11 +66,8 @@ public class EssentialsPlayerListener implements Listener
}
}
user.updateActivity(true);
if (ess.getSettings().changeDisplayName())
{
user.setDisplayNick();
}
}
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerMove(final PlayerMoveEvent event)
@ -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.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();
}
updateCompass(user);
if (ess.getSettings().getNoGodWorlds().contains(event.getPlayer().getLocation().getWorld().getName()))

View File

@ -71,10 +71,12 @@ public class User extends UserData implements Comparable<User>, 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<User>, 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())
{
@ -309,6 +315,8 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
public void setDisplayNick()
{
if (base.isOnline() && ess.getSettings().changeDisplayName())
{
String name = getNick(true);
setDisplayName(name);
@ -318,7 +326,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
if (name.length() > 16)
{
name = name.substring(0, name.charAt(15) == '§' ? 15 : 16);
name = Util.stripColor(name);
}
try
{
@ -326,19 +334,17 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
}
catch (IllegalArgumentException e)
{
if (ess.getSettings().isDebug()) {
if (ess.getSettings().isDebug())
{
logger.log(Level.INFO, "Playerlist for " + name + " was not updated. Name clashed with another online player.");
}
}
}
}
@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<User>, IReplyTo, IUser
setAfk(false);
if (broadcast && !isHidden())
{
setDisplayNick();
ess.broadcastMessage(this, _("userIsNotAway", getDisplayName()));
}
}
@ -530,6 +537,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, IUser
setAfk(true);
if (!isHidden())
{
setDisplayNick();
ess.broadcastMessage(this, _("userIsAway", getDisplayName()));
}
}

View File

@ -31,6 +31,7 @@ public class Commandafk extends EssentialsCommand
private void toggleAfk(User user)
{
user.setDisplayNick();
if (!user.toggleAfk())
{
//user.sendMessage(_("markedAsNotAway"));

View File

@ -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())

View File

@ -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<User> 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");
}

View File

@ -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));
}
}

View File

@ -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)

View File

@ -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())
{

View File

@ -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()));
}
}

View File

@ -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()));

View File

@ -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();