public static boolean process(Player commandSender, String[] args) {
    Plugin plugin = Plugin.getInstance();
    if (!plugin.getSettings().getBoolean("disableBuyCommand")) {
      if (plugin.isAuthenticated(commandSender)) {
        String pageToView = "1";

        if (args.length > 1) {
          if (args[1].equalsIgnoreCase("page") && args.length == 3) {
            pageToView = args[2];
          } else {
            if (args.length == 2 && isNumber(args[1])) {
              int packageID = Integer.valueOf(args[1]);

              boolean packageExists = false;
              PackageModal packageModel = null;

              for (PackageModal row : plugin.getPackageManager().getPackagesForSale()) {
                if (row.getOrder() == packageID) {
                  packageExists = true;
                  packageModel = row;

                  break;
                }
              }

              if (packageExists == true) {
                String buyNowLink =
                    plugin.getServerStore()
                        + "/checkout/packages?action=add&package="
                        + packageModel.getId()
                        + "&ign="
                        + commandSender.getName();

                if (plugin.getSettings().getBoolean("directPay")) {
                  buyNowLink =
                      plugin.getServerStore()
                          + "/checkout/packages?popup=true&action=add&direct=true&package="
                          + packageModel.getId()
                          + "&ign="
                          + commandSender.getName();
                }

                VisitLinkTask.call((Player) commandSender, buyNowLink);
              } else {
                commandSender.sendMessage(Chat.header());
                commandSender.sendMessage(Chat.seperator());
                commandSender.sendMessage(
                    Chat.seperator()
                        + ChatColor.RED
                        + plugin.getLanguage().getString("packageNotFound"));
                commandSender.sendMessage(Chat.seperator());
                commandSender.sendMessage(Chat.footer());
              }

              return true;
            } else {
              commandSender.sendMessage(Chat.header());
              commandSender.sendMessage(Chat.seperator());
              commandSender.sendMessage(
                  Chat.seperator()
                      + ChatColor.RED
                      + plugin.getLanguage().getString("invalidBuyCommand"));
              commandSender.sendMessage(Chat.seperator());
              commandSender.sendMessage(Chat.footer());
            }
          }
        }

        if (isNumber(pageToView) && pageToView.length() < 5) {
          Integer pageNumber = Integer.parseInt(pageToView);

          List<PackageModal> packages = plugin.getPackageManager().getPackagesForSale();

          if (packages.size() == 0) {
            commandSender.sendMessage(Chat.header());
            commandSender.sendMessage(Chat.seperator());
            commandSender.sendMessage(
                Chat.seperator()
                    + ChatColor.RED
                    + plugin.getLanguage().getString("noPackagesForSale"));
            commandSender.sendMessage(Chat.seperator());
            commandSender.sendMessage(Chat.footer());
          } else {
            int pageCount = (int) Math.ceil(packages.size() / 3.0);

            int startingPoint = -3 + (3 * pageNumber);
            int finishPoint = 0 + (3 * pageNumber);

            if (finishPoint > packages.size() || finishPoint < 3) finishPoint = packages.size();
            if (startingPoint > packages.size() || startingPoint < 0)
              startingPoint = packages.size();

            List<PackageModal> packagesToDisplay = packages.subList(startingPoint, finishPoint);

            if (packagesToDisplay.size() > 0) {
              plugin.getChatManager().disableChat((Player) commandSender);

              commandSender.sendMessage(Chat.header());
              commandSender.sendMessage(Chat.seperator());
              commandSender.sendMessage(
                  Chat.seperator()
                      + ChatColor.GREEN
                      + plugin.getLanguage().getString("toPurchase")
                      + " "
                      + ChatColor.LIGHT_PURPLE
                      + "/"
                      + plugin.getBuyCommand()
                      + " <ID>");

              if (pageCount > 1) {
                commandSender.sendMessage(
                    Chat.seperator()
                        + ChatColor.GREEN
                        + plugin.getLanguage().getString("howToNavigate")
                        + " "
                        + ChatColor.LIGHT_PURPLE
                        + "/"
                        + plugin.getBuyCommand()
                        + " page <1-"
                        + pageCount
                        + ">");
              }

              commandSender.sendMessage(Chat.seperator());

              for (PackageModal row : packagesToDisplay) {
                commandSender.sendMessage(
                    Chat.seperator()
                        + ChatColor.YELLOW
                        + plugin.getLanguage().getString("packageId")
                        + ": "
                        + ChatColor.LIGHT_PURPLE
                        + row.getOrder());
                commandSender.sendMessage(
                    Chat.seperator()
                        + ChatColor.YELLOW
                        + plugin.getLanguage().getString("packageName")
                        + ": "
                        + ChatColor.LIGHT_PURPLE
                        + row.getName());
                commandSender.sendMessage(
                    Chat.seperator()
                        + ChatColor.YELLOW
                        + plugin.getLanguage().getString("packagePrice")
                        + ": "
                        + ChatColor.LIGHT_PURPLE
                        + row.getPrice()
                        + ' '
                        + plugin.getServerCurrency());
                commandSender.sendMessage(Chat.seperator());
              }

              commandSender.sendMessage(
                  Chat.seperator()
                      + ChatColor.RED
                      + plugin.getLanguage().getString("turnChatBackOn"));
              commandSender.sendMessage(Chat.seperator());
              commandSender.sendMessage(Chat.footer());
            } else {
              commandSender.sendMessage(Chat.header());
              commandSender.sendMessage(Chat.seperator());
              commandSender.sendMessage(
                  Chat.seperator()
                      + ChatColor.RED
                      + plugin.getLanguage().getString("pageNotFound"));
              commandSender.sendMessage(Chat.seperator());
              commandSender.sendMessage(Chat.footer());
            }
          }

          return true;
        }

        commandSender.sendMessage(Chat.header());
        commandSender.sendMessage(Chat.seperator());
        commandSender.sendMessage(
            Chat.seperator() + ChatColor.RED + plugin.getLanguage().getString("invalidBuyCommand"));
        commandSender.sendMessage(Chat.seperator());
        commandSender.sendMessage(Chat.footer());
      }
    } else {
      VisitLinkTask.call((Player) commandSender, plugin.getServerStore());
    }

    return true;
  }
 private CommandFetchTask(boolean offlineCommands, Player[] players) {
   this.plugin = Plugin.getInstance();
   this.offlineCommands = offlineCommands;
   this.players = players;
 }
  public void run() {
    try {
      lastExecution = System.currentTimeMillis();
      if (!plugin.isAuthenticated(null)) {
        return;
      }

      // Create an array of player names
      String[] playerNames;
      if (players.length > 0) {
        ArrayList<String> tmpPlayerNames = new ArrayList<String>(players.length);
        for (Player player : players) {
          tmpPlayerNames.add(player.getName());
        }
        playerNames = tmpPlayerNames.toArray(new String[tmpPlayerNames.size()]);
      } else {
        playerNames = new String[0];
      }

      JSONObject apiResponse =
          plugin.getApi().fetchPlayerCommands(new JSONArray(playerNames), offlineCommands);

      if (apiResponse == null || apiResponse.getInt("code") != 0) {
        plugin.getLogger().severe("No response/invalid key during package check.");
        return;
      }

      JSONObject apiPayload = apiResponse.getJSONObject("payload");
      JSONArray commandsPayload = apiPayload.getJSONArray("commands");

      for (int i = 0; i < commandsPayload.length(); i++) {
        JSONObject row = commandsPayload.getJSONObject(i);

        String uuid = null;
        int commandId = row.getInt("id");
        String username = row.getString("ign");

        if (!row.isNull("uuid")) {
          uuid = row.getString("uuid");
        }

        boolean requireOnline = row.getBoolean("requireOnline");
        String command = row.getString("command");
        int delay = row.getInt("delay");
        int requiredInventorySlots = row.getInt("requireInventorySlot");

        Player player = requireOnline ? getPlayer(players, username) : null;

        if (requireOnline == false || player != null) {
          String c = command;
          String u = username;

          Plugin.getInstance()
              .getCommandExecutor()
              .queueCommand(commandId, c, u, uuid, delay, requiredInventorySlots);
        }
      }

      // If the plugin is disabled here our commands won't get executed so we return
      if (!Plugin.getInstance().isEnabled()) {
        return;
      }

      Plugin.getInstance().getCommandExecutor().scheduleExecutor();

      plugin.getLogger().info("Package checker successfully executed.");
    } catch (Exception e) {
      e.printStackTrace();
      ReportTask.setLastException(e);
    }
  }
 public static void call(boolean offlineCommands, Player... players) {
   Plugin.getInstance().addTask(new CommandFetchTask(offlineCommands, players));
 }