From 293474d99b4802bd38e6794b484d91212e8893c8 Mon Sep 17 00:00:00 2001 From: EdGruberman Date: Thu, 9 Aug 2012 09:27:40 -0700 Subject: [PATCH] [Bleeding] Use case from player data for OfflinePlayer. Fixes BUKKIT-519 If a plugin looks up a player that is offline they may not know the correct capitalization for the name. In this case they're likely to get it wrong and since we cache the result even after the player joins the server all future request for an OfflinePlayer will return one with incorrect case. When looking up a player who has played on the server before we can get the correct case from the player data file saved by the server. If the player has never played before this point we cannot do anything and will still have the same issue but this is not a solvable problem. --- .../java/org/bukkit/craftbukkit/CraftServer.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0cb25a617e..e757b437e7 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1019,6 +1019,10 @@ public final class CraftServer implements Server { } public OfflinePlayer getOfflinePlayer(String name) { + return getOfflinePlayer(name, true); + } + + public OfflinePlayer getOfflinePlayer(String name, boolean search) { OfflinePlayer result = getPlayerExact(name); String lname = name.toLowerCase(); @@ -1026,6 +1030,17 @@ public final class CraftServer implements Server { result = offlinePlayers.get(lname); if (result == null) { + if (search) { + WorldNBTStorage storage = (WorldNBTStorage) console.worlds.get(0).getDataManager(); + for (String dat : storage.getPlayerDir().list(new DatFileFilter())) { + String datName = dat.substring(0, dat.length() - 4); + if (datName.equalsIgnoreCase(name)) { + name = datName; + break; + } + } + } + result = new CraftOfflinePlayer(this, name); offlinePlayers.put(lname, result); }