summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTravis Watkins <amaranth@ubuntu.com>2014-04-12 02:38:53 -0500
committerTravis Watkins <amaranth@ubuntu.com>2014-04-12 03:12:26 -0500
commit7b409ed4e91e3fec383372af8fb52f547d8490a9 (patch)
tree124ca76e94228515e4be804da5979e23e85f9133 /src
parent8f771c737850130534b0fade70494f7ce3cbc8fd (diff)
downloadcraftbukkit-7b409ed4e91e3fec383372af8fb52f547d8490a9.tar
craftbukkit-7b409ed4e91e3fec383372af8fb52f547d8490a9.tar.gz
craftbukkit-7b409ed4e91e3fec383372af8fb52f547d8490a9.tar.lz
craftbukkit-7b409ed4e91e3fec383372af8fb52f547d8490a9.tar.xz
craftbukkit-7b409ed4e91e3fec383372af8fb52f547d8490a9.zip
Use fetched GameProfile for getOfflinePlayer(String)
When getting an OfflinePlayer by name we lookup their UUID and then use that to fetch the OfflinePlayer. If the player has not played on this server before the resulting OfflinePlayer will return null for getName(). As this is unintuitive we now create the OfflinePlayer directly using the profile we looked up and make OfflinePlayer prefer that data.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java5
-rw-r--r--src/main/java/org/bukkit/craftbukkit/CraftServer.java20
2 files changed, 19 insertions, 6 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
index bec41346..d92f5037 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java
@@ -49,6 +49,11 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
return player.getName();
}
+ // This might not match lastKnownName but if not it should be more correct
+ if (profile.getName() != null) {
+ return profile.getName();
+ }
+
NBTTagCompound data = getBukkitData();
if (data != null) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 748d887d..c4ef9fa3 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1260,14 +1260,22 @@ public final class CraftServer implements Server {
public OfflinePlayer getOfflinePlayer(String name) {
Validate.notNull(name, "Name cannot be null");
- // This is potentially blocking :(
- GameProfile profile = MinecraftServer.getServer().getUserCache().a(name);
- if (profile == null) {
- // Make an OfflinePlayer using an offline mode UUID since the name has no profile
- return getOfflinePlayer(new GameProfile(java.util.UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name));
+ OfflinePlayer result = getPlayerExact(name);
+ if (result == null) {
+ // This is potentially blocking :(
+ GameProfile profile = MinecraftServer.getServer().getUserCache().a(name);
+ if (profile == null) {
+ // Make an OfflinePlayer using an offline mode UUID since the name has no profile
+ result = getOfflinePlayer(new GameProfile(java.util.UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name));
+ } else {
+ // Use the GameProfile even when we get a UUID so we ensure we still have a name
+ result = getOfflinePlayer(profile);
+ }
+ } else {
+ offlinePlayers.remove(result.getUniqueId());
}
- return getOfflinePlayer(profile.getId());
+ return result;
}
public OfflinePlayer getOfflinePlayer(java.util.UUID id) {