Perf: Faster player name lookup by UUID.
This commit is contained in:
parent
0bd36427c7
commit
b7cb5dba51
|
|
@ -2283,49 +2283,21 @@ public class GriefPrevention extends JavaPlugin
|
||||||
if(playerID == null) return "someone";
|
if(playerID == null) return "someone";
|
||||||
|
|
||||||
//check the cache
|
//check the cache
|
||||||
String playerName = GriefPrevention.uuidToNameMap.get(playerID);
|
OfflinePlayer player = GriefPrevention.instance.getServer().getOfflinePlayer(playerID);
|
||||||
if(playerName != null) return playerName;
|
if(player.hasPlayedBefore())
|
||||||
|
|
||||||
//try online players next
|
|
||||||
Player player = GriefPrevention.instance.getServer().getPlayer(playerID);
|
|
||||||
if(player != null) playerName = player.getName();
|
|
||||||
|
|
||||||
//then search offline players
|
|
||||||
if(playerName == null)
|
|
||||||
{
|
{
|
||||||
OfflinePlayer [] players = GriefPrevention.instance.getServer().getOfflinePlayers();
|
return player.getName();
|
||||||
for(int i = 0; i < players.length; i++)
|
|
||||||
{
|
|
||||||
if(players[i].getUniqueId().equals(playerID))
|
|
||||||
{
|
|
||||||
playerName = players[i].getName();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if(playerName == null)
|
|
||||||
{
|
{
|
||||||
playerName = "someone";
|
return "someone";
|
||||||
}
|
}
|
||||||
|
|
||||||
//cache the result
|
|
||||||
GriefPrevention.cacheUUIDNamePair(playerID, playerName);
|
|
||||||
|
|
||||||
//return result
|
|
||||||
return playerName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//cache for player name lookups, to save searches of all offline players
|
//cache for player name lookups, to save searches of all offline players
|
||||||
static ConcurrentHashMap<UUID, String> uuidToNameMap = new ConcurrentHashMap<UUID, String>();
|
|
||||||
static void cacheUUIDNamePair(UUID playerID, String playerName)
|
static void cacheUUIDNamePair(UUID playerID, String playerName)
|
||||||
{
|
{
|
||||||
//limit memory footprint
|
//store the reverse mapping
|
||||||
if(GriefPrevention.uuidToNameMap.size() >= 500) GriefPrevention.uuidToNameMap.clear();
|
|
||||||
|
|
||||||
GriefPrevention.uuidToNameMap.put(playerID, playerName);
|
|
||||||
|
|
||||||
//always store the reverse mapping
|
|
||||||
GriefPrevention.instance.playerNameToIDMap.put(playerName, playerID);
|
GriefPrevention.instance.playerNameToIDMap.put(playerName, playerID);
|
||||||
GriefPrevention.instance.playerNameToIDMap.put(playerName.toLowerCase(), playerID);
|
GriefPrevention.instance.playerNameToIDMap.put(playerName.toLowerCase(), playerID);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1180,8 +1180,7 @@ class PlayerEventHandler implements Listener
|
||||||
(GriefPrevention.instance.config_claims_preventButtonsSwitches && clickedBlockType == Material.BED_BLOCK) ||
|
(GriefPrevention.instance.config_claims_preventButtonsSwitches && clickedBlockType == Material.BED_BLOCK) ||
|
||||||
|
|
||||||
(GriefPrevention.instance.config_claims_lockTrapDoors && (
|
(GriefPrevention.instance.config_claims_lockTrapDoors && (
|
||||||
clickedBlockType == Material.TRAP_DOOR ||
|
clickedBlockType == Material.TRAP_DOOR)) ||
|
||||||
clickedBlockType == Material.IRON_TRAPDOOR)) ||
|
|
||||||
|
|
||||||
(GriefPrevention.instance.config_claims_lockFenceGates && (
|
(GriefPrevention.instance.config_claims_lockFenceGates && (
|
||||||
clickedBlockType == Material.FENCE_GATE ||
|
clickedBlockType == Material.FENCE_GATE ||
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user