@EventHandler(priority = EventPriority.LOWEST) public void onPlayerJoin(final PlayerJoinEvent event) { final Player player = event.getPlayer(); lastLogout.remove(player.getName()); CombinedData.getData(player).lastJoinTime = System.currentTimeMillis(); addOnlinePlayer(player); }
@Override public void checkConsistency(final Player[] onlinePlayers) { // Check online player tracking consistency. int missing = 0; int changed = 0; int expectedSize = 0; for (int i = 0; i < onlinePlayers.length; i++) { final Player player = onlinePlayers[i]; final String name = player.getName(); // if (player.isOnline()){ expectedSize += 1 + (name.equals(name.toLowerCase()) ? 0 : 1); if (!this.onlinePlayers.containsKey(name)) { missing++; // TODO: Add the player [problem: messy NPC plugins?]? } if (player != this.onlinePlayers.get(name)) { changed++; // Update the reference. addOnlinePlayer(player); // } } } // TODO: Consider checking lastLogout for too long gone players. final int storedSize = this.onlinePlayers.size(); if (missing != 0 || changed != 0 || expectedSize != storedSize) { final List<String> details = new LinkedList<String>(); if (missing != 0) { details.add("missing online players (" + missing + ")"); } if (expectedSize != storedSize) { // TODO: Consider checking for not online players and remove them. details.add( "wrong number of online players (" + storedSize + " instead of " + expectedSize + ")"); } if (changed != 0) { details.add("changed player instances (" + changed + ")"); } LogUtil.logWarning( "[NoCheatPlus] DataMan inconsistencies: " + StringUtil.join(details, " | ")); } }
/** Initializing with online players. */ public void onEnable() { final Player[] players = Bukkit.getOnlinePlayers(); for (final Player player : players) { addOnlinePlayer(player); } }