From f4c67a5c3264098dbd3a3a26bc1a352d84c13fe1 Mon Sep 17 00:00:00 2001 From: Adam Thomas Date: Wed, 14 Oct 2015 18:56:08 +0100 Subject: [PATCH] SPIGOT-1232: CraftServer.getPlayer(String name) returns incorrect results in some cases. Use the absolute value of the delta to prevent negative values resulting in a better match. --- src/main/java/org/bukkit/craftbukkit/CraftServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 82a41b0442..90064eaec4 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -397,7 +397,7 @@ public final class CraftServer implements Server { int delta = Integer.MAX_VALUE; for (Player player : getOnlinePlayers()) { if (player.getName().toLowerCase().startsWith(lowerName)) { - int curDelta = player.getName().length() - lowerName.length(); + int curDelta = Math.abs(player.getName().length() - lowerName.length()); if (curDelta < delta) { found = player; delta = curDelta;