@EventHandler(priority = EventPriority.LOWEST) public void onPlayerQuit(PlayerQuitEvent e) { Managers.log("[Player] Saving details for player " + e.getPlayer().getName()); Managers.getStatisticManager() .saveStatistic(getPlayerDetails(e.getPlayer()), PlayerDetails.class); players.remove(e.getPlayer()); }
public PlayerManager() { Managers.log("[Player] Starting Manager..."); players = Collections.synchronizedMap(new LinkedHashMap<String, PlayerDetails>()); shutdown = false; Managers.getStatisticManager().registerStatistic(PlayerDetails.class); Bukkit.getScheduler() .scheduleSyncRepeatingTask( Managers.getActivePlugin(), new Runnable() { @Override public void run() { saveAll(); } }, 1200, 18000); Runnable r = new Runnable() { @Override public void run() { Random r = new Random(); while (!shutdown) { for (PlayerDetails d : players.values()) { if (d.giveMana) d.modifyPowerBy((int) Math.round(1 * d.getLevel() * (Math.random() + 1))); } try { Thread.sleep(r.nextInt(10000) + 5000); } catch (InterruptedException e) { throw new RuntimeException(e); } } } }; Thread t = new Thread(r); t.setDaemon(true); t.setName("MineQuest-PlayerMana"); t.start(); Runnable run = new Runnable() { @Override public void run() { while (!shutdown) { synchronized (players) { for (PlayerDetails d : players.values()) { try { d.updateMinecraftView(); } catch (NullPointerException e) { Managers.log( Level.WARNING, "[Player] Thread NPE! Can't keep up! Did the system time change, is the server overloaded, or has the player changed worlds?"); } } } try { Thread.sleep(50); } catch (InterruptedException e) { throw new RuntimeException(e); } } } }; Thread th = new Thread(run); th.setDaemon(true); th.setName("MineQuest-PlayerUpdateView"); th.start(); }
@EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJoin(PlayerJoinEvent e) { Managers.log("[Player] Retrieving details for player " + e.getPlayer().getName()); playerAcct(e.getPlayer()); }