revert e18ec1

This commit is contained in:
Len 2022-05-24 21:03:47 +02:00
parent eceeaf1dca
commit 0611f5d695

View File

@ -374,6 +374,12 @@ 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();
new AltitudeListener(this.dataStore, this);
if (getServer().getPluginManager().isPluginEnabled("Pl3xMap")) {
pl3xmapHook = new Pl3xMapHook(this);
@ -2744,7 +2750,50 @@ public class GriefPrevention extends JavaPlugin
}
//helper method to resolve a player by name
ConcurrentHashMap<String, UUID> playerNameToIDMap = new ConcurrentHashMap<>(); // TODO REMOVE ME
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();
}
}
}
}
public OfflinePlayer resolvePlayerByName(String name)