From f73b61f1ced588413dfaabc369fd76573d5a1197 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 7 Jan 2011 10:42:53 +0800 Subject: [PATCH] Better implementation of matchPlayer(String) - return List of potential matches By: Animosity --- .../org/bukkit/craftbukkit/CraftServer.java | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 129749091a..2d0d0c96eb 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit; import java.io.File; +import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -81,28 +82,24 @@ public final class CraftServer implements Server { return entity.a.getPlayer(); } - public Player matchPlayer(String wantedPlayerName) { - Player wantedPlayer = null; - + public List matchPlayer(String partialName) { + List matchedPlayers = new ArrayList(); + for (Player iterPlayer : this.getOnlinePlayers()) { String iterPlayerName = iterPlayer.getName(); - if (wantedPlayerName.equalsIgnoreCase(iterPlayerName)) { + if (partialName.equalsIgnoreCase(iterPlayerName)) { // Exact match - wantedPlayer = this.getPlayer(wantedPlayerName); - break; - } - if (wantedPlayerName.toLowerCase().indexOf(iterPlayerName.toLowerCase()) != -1) { - // Partial match - if (wantedPlayer != null) { - // Multiple matches - return null; - } - wantedPlayer = iterPlayer; + matchedPlayers.add(iterPlayer); + break; + } + if (iterPlayerName.toLowerCase().indexOf(partialName.toLowerCase()) != -1) { + // Partial match + matchedPlayers.add(iterPlayer); } } - return wantedPlayer; + return matchedPlayers; } public PluginManager getPluginManager() {