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";
|
||||
|
||||
//check the cache
|
||||
String playerName = GriefPrevention.uuidToNameMap.get(playerID);
|
||||
if(playerName != null) return playerName;
|
||||
|
||||
//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 player = GriefPrevention.instance.getServer().getOfflinePlayer(playerID);
|
||||
if(player.hasPlayedBefore())
|
||||
{
|
||||
OfflinePlayer [] players = GriefPrevention.instance.getServer().getOfflinePlayers();
|
||||
for(int i = 0; i < players.length; i++)
|
||||
return player.getName();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(players[i].getUniqueId().equals(playerID))
|
||||
{
|
||||
playerName = players[i].getName();
|
||||
break;
|
||||
return "someone";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(playerName == null)
|
||||
{
|
||||
playerName = "someone";
|
||||
}
|
||||
|
||||
//cache the result
|
||||
GriefPrevention.cacheUUIDNamePair(playerID, playerName);
|
||||
|
||||
//return result
|
||||
return playerName;
|
||||
}
|
||||
|
||||
//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)
|
||||
{
|
||||
//limit memory footprint
|
||||
if(GriefPrevention.uuidToNameMap.size() >= 500) GriefPrevention.uuidToNameMap.clear();
|
||||
|
||||
GriefPrevention.uuidToNameMap.put(playerID, playerName);
|
||||
|
||||
//always store the reverse mapping
|
||||
//store the reverse mapping
|
||||
GriefPrevention.instance.playerNameToIDMap.put(playerName, 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_lockTrapDoors && (
|
||||
clickedBlockType == Material.TRAP_DOOR ||
|
||||
clickedBlockType == Material.IRON_TRAPDOOR)) ||
|
||||
clickedBlockType == Material.TRAP_DOOR)) ||
|
||||
|
||||
(GriefPrevention.instance.config_claims_lockFenceGates && (
|
||||
clickedBlockType == Material.FENCE_GATE ||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user