mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
Eliminate usage of deprecated org.bukkit.Server.matchPlayer
Suppress unchecked cast warnings in Module_players.
This commit is contained in:
parent
7f7312c0a2
commit
2b597867f0
@ -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<Player> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user