Remove wastefull cache, to be replace by a better one

This commit is contained in:
destro174 2022-02-20 14:33:40 +01:00
parent a60c542b15
commit e18ec1e55c

View File

@ -378,12 +378,6 @@ public class GriefPrevention extends JavaPlugin
economyHandler = new EconomyHandler(this);
pluginManager.registerEvents(economyHandler, this);
//cache offline players
OfflinePlayer[] offlinePlayers = this.getServer().getOfflinePlayers();
CacheOfflinePlayerNamesThread namesThread = new CacheOfflinePlayerNamesThread(offlinePlayers, this.playerNameToIDMap);
namesThread.setPriority(Thread.MIN_PRIORITY);
namesThread.start();
//load ignore lists for any already-online players
@SuppressWarnings("unchecked")
Collection<Player> players = (Collection<Player>) GriefPrevention.instance.getServer().getOnlinePlayers();
@ -2925,50 +2919,7 @@ public class GriefPrevention extends JavaPlugin
}
//helper method to resolve a player by name
ConcurrentHashMap<String, UUID> playerNameToIDMap = new ConcurrentHashMap<>();
//thread to build the above cache
private class CacheOfflinePlayerNamesThread extends Thread
{
private final OfflinePlayer[] offlinePlayers;
private final ConcurrentHashMap<String, UUID> playerNameToIDMap;
CacheOfflinePlayerNamesThread(OfflinePlayer[] offlinePlayers, ConcurrentHashMap<String, UUID> playerNameToIDMap)
{
this.offlinePlayers = offlinePlayers;
this.playerNameToIDMap = playerNameToIDMap;
}
public void run()
{
long now = System.currentTimeMillis();
final long millisecondsPerDay = 1000 * 60 * 60 * 24;
for (OfflinePlayer player : offlinePlayers)
{
try
{
UUID playerID = player.getUniqueId();
if (playerID == null) continue;
long lastSeen = player.getLastPlayed();
//if the player has been seen in the last 90 days, cache his name/UUID pair
long diff = now - lastSeen;
long daysDiff = diff / millisecondsPerDay;
if (daysDiff <= config_advanced_offlineplayer_cache_days)
{
String playerName = player.getName();
if (playerName == null) continue;
this.playerNameToIDMap.put(playerName, playerID);
this.playerNameToIDMap.put(playerName.toLowerCase(), playerID);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
ConcurrentHashMap<String, UUID> playerNameToIDMap = new ConcurrentHashMap<>(); // TODO REMOVE ME
public OfflinePlayer resolvePlayerByName(String name)