SHARE
TWEET

Untitled

a guest Feb 25th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class PlayerManager {
  3.  
  4.     private final NetworkAPI plugin;
  5.     private final ConcurrentHashMap<UUID, PlayerData> cache = new ConcurrentHashMap<>();
  6.  
  7.     public PlayerManager(NetworkAPI plugin) {
  8.         this.plugin = plugin;
  9.     }
  10.  
  11.     public PlayerData getPlayerData(UUID player) {
  12.         if (player == null) throw new NullPointerException("Parameter player is null !");
  13.  
  14.         PlayerData data = cache.get(player);
  15.         data.refreshIfNeeded();
  16.         if (data == null) this.plugin.log(Level.WARNING, player + " is not in the cache !");
  17.  
  18.         return data;
  19.     }
  20.  
  21.     public PlayerData getPlayerDataByName(String name) {
  22.         for (PlayerData data : cache.values()) {
  23.             if (data.getEffectiveName().equals(name))
  24.                 return data;
  25.         }
  26.  
  27.         return null;
  28.     }
  29.  
  30.     public void loadPlayer(UUID player) {
  31.         PlayerData playerData = new PlayerData(player, plugin, this);
  32.         cache.put(player, playerData);
  33.     }
  34.  
  35.     public void unloadPlayer(UUID player) {
  36.         if (!cache.contains(player)) {
  37.             this.plugin.log(Level.WARNING, player + " is not in the cache !");
  38.             return;
  39.         }
  40.         cache.get(player).updateData();
  41.         Bukkit.getScheduler().runTaskLater(this.plugin, () -> cache.remove(player), 2L);
  42.     }
  43.  
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top