Eliminate usage of deprecated org.bukkit.Server.matchPlayer

Suppress unchecked cast warnings in Module_players.
This commit is contained in:
StevenLawson 2014-07-19 17:39:42 -04:00
parent 7f7312c0a2
commit 2b597867f0
2 changed files with 32 additions and 15 deletions

View File

@ -1,6 +1,5 @@
package me.StevenLawson.TotalFreedomMod.Commands; package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_Log; import me.StevenLawson.TotalFreedomMod.TFM_Log;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerData; import me.StevenLawson.TotalFreedomMod.TFM_PlayerData;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
@ -134,23 +133,42 @@ public abstract class TFM_Command
return true; return true;
} }
public Player getPlayer(final String partialname) public Player getPlayer(final String partialName)
{ {
List<Player> matches = server.matchPlayer(partialname); if (partialName == null || partialName.isEmpty())
if (matches.isEmpty())
{ {
for (Player player : server.getOnlinePlayers())
{
if (player.getDisplayName().toLowerCase().contains(partialname.toLowerCase()))
{
return player;
}
}
return null; 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;
} }
} }

View File

@ -4,8 +4,6 @@ import java.util.UUID;
import me.StevenLawson.TotalFreedomMod.TFM_AdminList; import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@ -18,6 +16,7 @@ public class Module_players extends TFM_HTTPD_Module
} }
@Override @Override
@SuppressWarnings("unchecked")
public NanoHTTPD.Response getResponse() public NanoHTTPD.Response getResponse()
{ {
final JSONObject responseObject = new JSONObject(); final JSONObject responseObject = new JSONObject();