private void processOnlinePlayers() { // Check for online players and execute their commands. List<QueuedPlayer> processNow = new ArrayList<>(); lock.lock(); try { for (Iterator<QueuedPlayer> it = due.values().iterator(); it.hasNext(); ) { QueuedPlayer qp = it.next(); if (platform.isPlayerOnline(qp)) { if (processNow.size() < MAXIMUM_ONLINE_PLAYERS_TO_EXECUTE) { processNow.add(qp); it.remove(); } } } } finally { lock.unlock(); } if (!processNow.isEmpty()) { if (verbose) { platform.log(Level.INFO, String.format("Executing commands for %d online players...", processNow.size())); } for (int i = 0; i < processNow.size(); i++) { QueuedPlayer qp = processNow.get(i); platform.executeAsyncLater(new PlayerCommandExecutor(qp, platform), DELAY_BETWEEN_PLAYERS * (i + 1), TimeUnit.MILLISECONDS); } } }
public boolean canExecute(IBuycraftPlatform platform) { Integer requiredSlots = command.getConditions().get("slots"); if (requiredSlots != null || requireOnline) { if (!platform.isPlayerOnline(player)) { return false; } } if (requiredSlots != null) { int free = platform.getFreeSlots(player); if (free < requiredSlots) { return false; } } Integer delay = command.getConditions().get("delay"); return !(delay != null && delay > 0 && System.currentTimeMillis() - queueTime < TimeUnit.SECONDS.toMillis(delay)); } }