@Override public void run() { run(true); }
@Override public void run() { QueuedPlayer qp = queuedPlayers.poll(); if (qp != null) { platform.executeAsync(new PlayerCommandExecutor(qp, platform)); } }
public void initializeTasks() { try { serverInformation = platform.getApiClient().getServerInformation(); } catch (IOException | ApiException e) { throw new RuntimeException("Can't fetch account information", e); } executorService.schedule(playerFetcher = new DuePlayerFetcher(platform, verbose), 1, TimeUnit.SECONDS); }
@Override public void execute(CommandSender sender, String[] args) { if (args.length != 0) { sender.sendMessage(TextFormat.RED + plugin.getI18n().get("no_params")); return; } if (plugin.getApiClient() == null) { sender.sendMessage(TextFormat.RED + plugin.getI18n().get("need_secret_key")); return; } if (plugin.getDuePlayerFetcher().inProgress()) { sender.sendMessage(TextFormat.RED + plugin.getI18n().get("already_checking_for_purchases")); return; } plugin.getPlatform().executeAsync(() -> plugin.getDuePlayerFetcher().run(false)); sender.sendMessage(TextFormat.GREEN + plugin.getI18n().get("forcecheck_queued")); }
@EventHandler public void onPlayerJoin(PlayerJoinEvent event) { if (plugin.getApiClient() == null) { return; } QueuedPlayer qp = plugin.getDuePlayerFetcher().fetchAndRemoveDuePlayer(event.getPlayer().getName()); if (qp != null) { plugin.getPlayerJoinCheckTask().queue(qp); } } }
@Override public void execute(CommandSender sender, String[] args) { if (args.length != 0) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("no_params")); return; } if (plugin.getApiClient() == null) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("need_secret_key")); return; } if (plugin.getDuePlayerFetcher().inProgress()) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("already_checking_for_purchases")); return; } plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { plugin.getDuePlayerFetcher().run(false); } }); sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("forcecheck_queued")); }
platform.log(Level.INFO, "Executing commands that can be completed now..."); platform.executeAsync(new ImmediateCommandExecutor(platform)); processOnlinePlayers(); } finally { inProgress.set(false);
writer.println("Players in queue: " + duePlayerFetcher.getDuePlayers()); if (listingUpdateTask != null) { writer.println("Listing update last completed: " + listingUpdateTask.getLastUpdate());
@Override public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { if (plugin.getApiClient() == null) { sender.sendMessage(Text.builder(plugin.getI18n().get("need_secret_key")).color(TextColors.RED).build()); return CommandResult.success(); } if (plugin.getDuePlayerFetcher().inProgress()) { sender.sendMessage(Text.builder(plugin.getI18n().get("already_checking_for_purchases")).color(TextColors.RED).build()); return CommandResult.success(); } Sponge.getScheduler().createTaskBuilder().execute(() -> plugin.getDuePlayerFetcher().run(false)).async().submit(plugin); sender.sendMessage(Text.builder(plugin.getI18n().get("forcecheck_queued")).color(TextColors.GREEN).build()); return CommandResult.success(); } }
@Override public void run() { plugin.getDuePlayerFetcher().run(false); } });
@Listener public void onPlayerJoinEvent(ClientConnectionEvent.Join event) { if (plugin.getApiClient() == null) { return; } QueuedPlayer qp = plugin.getDuePlayerFetcher().fetchAndRemoveDuePlayer(event.getTargetEntity().getName()); if (qp != null) { plugin.getPlayerJoinCheckTask().queue(qp); } } }
@Override public void execute(CommandSender sender, String[] args) { if (args.length != 0) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("no_params")); return; } if (plugin.getApiClient() == null) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("need_secret_key")); return; } if (plugin.getDuePlayerFetcher().inProgress()) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("already_checking_for_purchases")); return; } plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() { @Override public void run() { plugin.getDuePlayerFetcher().run(false); } }); sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("forcecheck_queued")); }
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); } } }
@Override public void run() { plugin.getDuePlayerFetcher().run(false); } });
@EventHandler public void onPostLogin(PostLoginEvent event) { if (plugin.getApiClient() == null) { return; } QueuedPlayer qp = plugin.getDuePlayerFetcher().fetchAndRemoveDuePlayer(event.getPlayer().getName()); if (qp != null) { plugin.getPlayerJoinCheckTask().queue(qp); } } }
@Override public void execute(CommandSender sender, String[] args) { if (args.length != 0) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("no_params")); return; } if (plugin.getApiClient() == null) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("need_secret_key")); return; } if (plugin.getDuePlayerFetcher().inProgress()) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("already_checking_for_purchases")); return; } plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new RecentPurchaseSignUpdateFetcher(plugin)); sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("sign_update_queued")); }
@Override public void run() { String currentKey = plugin.getConfiguration().getServerKey(); ApiClient client = new ProductionApiClient(args[0], plugin.getHttpClient()); try { plugin.updateInformation(client); } catch (Exception e) { plugin.getLogger().log(Level.SEVERE, "Unable to verify secret", e); sender.sendMessage(ChatColor.RED + plugin.getI18n().get("secret_does_not_work")); return; } ServerInformation information = plugin.getServerInformation(); plugin.setApiClient(client); plugin.getListingUpdateTask().run(); plugin.getConfiguration().setServerKey(args[0]); try { plugin.saveConfiguration(); } catch (IOException e) { sender.sendMessage(ChatColor.RED + plugin.getI18n().get("secret_cant_be_saved")); } sender.sendMessage(ChatColor.GREEN + plugin.getI18n().get("secret_success", information.getServer().getName(), information.getAccount().getName())); boolean repeatChecks = false; if (currentKey == "INVALID") { repeatChecks = true; } plugin.getDuePlayerFetcher().run(repeatChecks); } });
@EventHandler public void onPlayerJoin(PlayerJoinEvent event) { if (plugin.getApiClient() == null) { return; } QueuedPlayer qp = plugin.getDuePlayerFetcher().fetchAndRemoveDuePlayer(event.getPlayer().getName()); if (qp != null) { plugin.getPlayerJoinCheckTask().queue(qp); } }
@Override public void run() { String currentKey = plugin.getConfiguration().getServerKey(); ApiClient client = new ProductionApiClient((String) args.getOne("secret").get(), plugin.getHttpClient()); try { plugin.updateInformation(client); } catch (IOException | ApiException e) { plugin.getLogger().error("Unable to verify secret", e); src.sendMessage(Text.builder(plugin.getI18n().get("secret_does_not_work")).color(TextColors.RED).build()); return; } ServerInformation information = plugin.getServerInformation(); plugin.setApiClient(client); plugin.getListingUpdateTask().run(); plugin.getConfiguration().setServerKey((String) args.getOne("secret").get()); try { plugin.saveConfiguration(); } catch (IOException e) { src.sendMessage(Text.builder(plugin.getI18n().get("secret_cant_be_saved")).color(TextColors.RED).build()); } src.sendMessage(Text.builder(plugin.getI18n().get("secret_success", information.getServer().getName(), information.getAccount().getName())).color(TextColors.GREEN).build()); boolean repeatChecks = false; if (currentKey == "INVALID") { repeatChecks = true; } plugin.getDuePlayerFetcher().run(repeatChecks); } });
@Override public void run() { String currentKey = plugin.getConfiguration().getServerKey(); ApiClient client = new ProductionApiClient(args[0], plugin.getHttpClient()); try { plugin.updateInformation(client); } catch (IOException | ApiException e) { plugin.getLogger().error("Unable to verify secret", e); sender.sendMessage(TextFormat.RED + plugin.getI18n().get("secret_does_not_work")); return; } ServerInformation information = plugin.getServerInformation(); plugin.setApiClient(client); plugin.getConfiguration().setServerKey(args[0]); try { plugin.saveConfiguration(); } catch (IOException e) { sender.sendMessage(TextFormat.RED + plugin.getI18n().get("secret_cant_be_saved")); } sender.sendMessage(TextFormat.GREEN + plugin.getI18n().get("secret_success", information.getServer().getName(), information.getAccount().getName())); boolean repeatChecks = false; if (currentKey == "INVALID") { repeatChecks = true; } plugin.getDuePlayerFetcher().run(repeatChecks); } });