From abd86347c70005c0a4d36400d16472019c3a9d7a Mon Sep 17 00:00:00 2001 From: snowleo Date: Mon, 19 Dec 2011 12:57:09 +0100 Subject: [PATCH] Always return an offlineplayer object with the name, that the user wants. --- .../src/com/earth2me/essentials/Essentials.java | 15 ++++++++++++--- .../com/earth2me/essentials/OfflinePlayer.java | 15 +++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index 648a99ce3..c8152248e 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -36,7 +36,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; -import java.util.logging.LogRecord; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -440,7 +439,12 @@ public class Essentials extends JavaPlugin implements IEssentials } if (base instanceof String) { - return userMap.getUser((String)base); + final User user = userMap.getUser((String)base); + if (user != null && user.getBase() instanceof OfflinePlayer) + { + ((OfflinePlayer)user.getBase()).setName((String)base); + } + return user; } return null; } @@ -472,7 +476,12 @@ public class Essentials extends JavaPlugin implements IEssentials @Override public User getOfflineUser(final String name) { - return userMap.getUser(name); + final User user = userMap.getUser(name); + if (user != null && user.getBase() instanceof OfflinePlayer) + { + ((OfflinePlayer)user.getBase()).setName(name); + } + return user; } @Override diff --git a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java index e05a07576..097c4c883 100644 --- a/Essentials/src/com/earth2me/essentials/OfflinePlayer.java +++ b/Essentials/src/com/earth2me/essentials/OfflinePlayer.java @@ -26,11 +26,11 @@ import org.bukkit.util.Vector; public class OfflinePlayer implements Player { private final transient IEssentials ess; - private Location location = new Location(null, 0, 0, 0, 0, 0); - private World world; - private UUID uniqueId = UUID.randomUUID(); + private transient Location location = new Location(null, 0, 0, 0, 0, 0); + private transient World world; + private final transient UUID uniqueId = UUID.randomUUID(); @Delegate(types = org.bukkit.OfflinePlayer.class) - private final org.bukkit.OfflinePlayer base; + private transient org.bukkit.OfflinePlayer base; public OfflinePlayer(final String name, final IEssentials ess) { @@ -822,4 +822,11 @@ public class OfflinePlayer implements Player { throw new UnsupportedOperationException("Not supported yet."); } + + void setName(final String name) + { + if (!this.base.getName().equalsIgnoreCase(name)) { + this.base = ess.getServer().getOfflinePlayer(name); + } + } }