diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java index e61ac82..c24a793 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/TFM_Command.java @@ -1,6 +1,5 @@ package me.StevenLawson.TotalFreedomMod.Commands; -import java.util.List; import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_AdminList; @@ -134,23 +133,42 @@ public abstract class TFM_Command return true; } - public Player getPlayer(final String partialname) + public Player getPlayer(final String partialName) { - List matches = server.matchPlayer(partialname); - if (matches.isEmpty()) + if (partialName == null || partialName.isEmpty()) { - for (Player player : server.getOnlinePlayers()) - { - if (player.getDisplayName().toLowerCase().contains(partialname.toLowerCase())) - { - return player; - } - } return null; } - else + + final Player[] players = server.getOnlinePlayers(); + + // Check exact matches first. + for (Player player : players) { - return matches.get(0); + if (partialName.equalsIgnoreCase(player.getName())) + { + return player; + } } + + // Then check partial matches in name. + for (Player player : players) + { + if (player.getName().toLowerCase().contains(partialName.toLowerCase())) + { + return player; + } + } + + // Then check partial matches in display name. + for (Player player : players) + { + if (player.getDisplayName().toLowerCase().contains(partialName.toLowerCase())) + { + return player; + } + } + + return null; } } diff --git a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_players.java b/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_players.java index f4c958b..d39653a 100644 --- a/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_players.java +++ b/src/me/StevenLawson/TotalFreedomMod/HTTPD/Module_players.java @@ -4,8 +4,6 @@ import java.util.UUID; import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; -import org.bukkit.Bukkit; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.json.simple.JSONArray; import org.json.simple.JSONObject; @@ -18,6 +16,7 @@ public class Module_players extends TFM_HTTPD_Module } @Override + @SuppressWarnings("unchecked") public NanoHTTPD.Response getResponse() { final JSONObject responseObject = new JSONObject();