Only cache offline playernames is requested

This commit is contained in:
destro174 2022-02-20 14:42:41 +01:00
parent e96cbd344b
commit 4608ca9b95

View File

@ -99,6 +99,8 @@ public class GriefPrevention extends JavaPlugin
//log entry manager for GP's custom log files
CustomLogger customLogger;
// hashmap to cache offline playernames
public static HashMap<UUID, String> playerNameCache = new HashMap<>();
//configuration variables, loaded/saved from a config.yml
//claim mode for each world
@ -2669,7 +2671,7 @@ public class GriefPrevention extends JavaPlugin
public enum IgnoreMode
{None, StandardIgnore, AdminIgnore}
private String trustEntryToPlayerName(String entry)
public String trustEntryToPlayerName(String entry)
{
if (entry.startsWith("[") || entry.equals("public"))
{
@ -2944,11 +2946,15 @@ public class GriefPrevention extends JavaPlugin
//parameter validation
if (playerID == null) return "somebody";
if (playerNameCache.containsKey(playerID))
return playerNameCache.get(playerID);
//check the cache
OfflinePlayer player = GriefPrevention.instance.getServer().getOfflinePlayer(playerID);
if (player.hasPlayedBefore() || player.isOnline())
{
return player.getName();
String playerName = player.getName();
playerNameCache.put(playerID, playerName);
return playerName;
}
else
{