From 3e3c7f0d545955912f925b08049adf38372e5472 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Fri, 2 Mar 2012 19:05:30 +0000 Subject: [PATCH] Only update displayname on world change, not every teleport. --- .../essentials/EssentialsPlayerListener.java | 15 ++++----- .../src/com/earth2me/essentials/User.java | 31 ++++++++++--------- .../src/com/earth2me/essentials/UserData.java | 19 +++++++++--- 3 files changed, 38 insertions(+), 27 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java index 0779c01ab..1b9464da4 100644 --- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java +++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java @@ -233,18 +233,13 @@ public class EssentialsPlayerListener implements Listener return; } - final User user = ess.getUser(event.getPlayer()); //There is TeleportCause.COMMMAND but plugins have to actively pass the cause in on their teleports. if ((event.getCause() == TeleportCause.PLUGIN || event.getCause() == TeleportCause.COMMAND) && ess.getSettings().registerBackInListener()) { + final User user = ess.getUser(event.getPlayer()); user.setLastLocation(); } - if (ess.getSettings().changeDisplayName()) - { - user.setDisplayNick(); - } - updateCompass(user); } @EventHandler(priority = EventPriority.HIGH) @@ -307,9 +302,15 @@ public class EssentialsPlayerListener implements Listener @EventHandler(priority = EventPriority.MONITOR) 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())) { - User user = ess.getUser(event.getPlayer()); if (user.isGodModeEnabledRaw()) { user.sendMessage(_("noGodWorldWarning")); diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java index ba34548fe..125962da9 100644 --- a/Essentials/src/com/earth2me/essentials/User.java +++ b/Essentials/src/com/earth2me/essentials/User.java @@ -249,7 +249,7 @@ public class User extends UserData implements Comparable, IReplyTo, IUser return teleportRequestHere; } - public String getNick(boolean addprefixsuffix) + public String getNick(final boolean addprefixsuffix) { final StringBuilder nickname = new StringBuilder(); final String nick = getNickname(); @@ -261,28 +261,28 @@ public class User extends UserData implements Comparable, IReplyTo, IUser { nickname.append(ess.getSettings().getNicknamePrefix()).append(nick); } - if (isOp()) - { - try - { - nickname.insert(0, ess.getSettings().getOperatorColor().toString()); - nickname.append("§f"); - } - catch (Exception e) - { - } - } if (addprefixsuffix && ess.getSettings().addPrefixSuffix()) { + if (isOp()) + { + try + { + nickname.insert(0, ess.getSettings().getOperatorColor().toString()); + } + catch (Exception e) + { + } + } + if (!ess.getSettings().disablePrefix()) { - final String prefix = ess.getPermissionsHandler().getPrefix(base).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName()); + final String prefix = ess.getPermissionsHandler().getPrefix(base).replace('&', '§'); nickname.insert(0, prefix); } if (!ess.getSettings().disableSuffix()) { - final String suffix = ess.getPermissionsHandler().getSuffix(base).replace('&', '§').replace("{WORLDNAME}", this.getWorld().getName()); + final String suffix = ess.getPermissionsHandler().getSuffix(base).replace('&', '§'); nickname.append(suffix); if (suffix.length() < 2 || !suffix.substring(suffix.length() - 2, suffix.length() - 1).equals("§")) { @@ -330,6 +330,7 @@ public class User extends UserData implements Comparable, IReplyTo, IUser return super.getDisplayName() == null ? super.getName() : super.getDisplayName(); } + @Override public Teleport getTeleport() { return teleport; @@ -385,7 +386,7 @@ public class User extends UserData implements Comparable, IReplyTo, IUser catch (Throwable ex) { } - } + } super.setMoney(value); Trade.log("Update", "Set", "API", getName(), new Trade(value, ess), null, null, null, ess); } diff --git a/Essentials/src/com/earth2me/essentials/UserData.java b/Essentials/src/com/earth2me/essentials/UserData.java index cda2fa511..1fdc98254 100644 --- a/Essentials/src/com/earth2me/essentials/UserData.java +++ b/Essentials/src/com/earth2me/essentials/UserData.java @@ -44,7 +44,7 @@ public abstract class UserData extends PlayerExtension implements IConf savedInventory = _getSavedInventory(); teleportEnabled = getTeleportEnabled(); ignoredPlayers = getIgnoredPlayers(); - godmode = getGodModeEnabled(); + godmode = _getGodModeEnabled(); muted = getMuted(); muteTimeout = _getMuteTimeout(); jailed = getJailed(); @@ -58,6 +58,7 @@ public abstract class UserData extends PlayerExtension implements IConf isNPC = _isNPC(); arePowerToolsEnabled = _arePowerToolsEnabled(); kitTimestamps = _getKitTimestamps(); + nickname = _getNickname(); } private double money; @@ -189,13 +190,21 @@ public abstract class UserData extends PlayerExtension implements IConf return false; } - public String getNickname() + private String nickname; + + public String _getNickname() { return config.getString("nickname"); } + + public String getNickname() + { + return nickname; + } public void setNickname(String nick) { + nickname = nick; config.setProperty("nickname", nick); config.save(); } @@ -515,7 +524,7 @@ public abstract class UserData extends PlayerExtension implements IConf } private boolean godmode; - private boolean getGodModeEnabled() + private boolean _getGodModeEnabled() { return config.getBoolean("godmode", false); } @@ -817,12 +826,12 @@ public abstract class UserData extends PlayerExtension implements IConf private Map _getKitTimestamps() { - + if (config.isConfigurationSection("timestamps.kits")) { return config.getConfigurationSection("timestamps.kits").getValues(false); } - return new HashMap(); + return new HashMap(); } public Long getKitTimestamp(final String name)