Example #1
0
  public Help help() {

    Help help = new Help();
    help.setCommand(getCommandName());
    help.setArguments("[player]");

    String giveHelp =
        PluginConfig.getInstance()
            .getConfig(ResourcesConfig.class)
            .getResource("payrank.current.help");

    help.setDescription(giveHelp);

    return help;
  }
Example #2
0
  public void run(
      PayRankPlugin plugin,
      CommandSender sender,
      List<String> arguments,
      HashSet<PayRankPermission> permissions)
      throws ArgumentsMissingException, InvalidPermissionsException {

    // check arguments
    if (arguments.size() > 1) {
      throw new ArgumentsMissingException();
    }

    String searchPlayer = null;

    // if no arguments, we'll check the main permission
    if (arguments.size() == 0) {

      // check permissions
      if (!permissions.contains(getPermission())) {

        if (PluginConfig.getInstance().getConfig(SettingsConfig.class).isLoggingDebug()) {
          logger.info("Player does not have the payrank.current permission");
        }

        throw new InvalidPermissionsException();
      }

      // set the search player to the sender
      searchPlayer = sender.getName();

    } else if (arguments.size() == 1) {

      // if one argument, we'll check the permission.others
      if (!permissions.contains(getPermissionOthers())) {

        if (PluginConfig.getInstance().getConfig(SettingsConfig.class).isLoggingDebug()) {
          logger.info("Player does not have the payrank.current.others permission");
        }

        throw new InvalidPermissionsException();
      }

      // set the search player to the parameter
      searchPlayer = arguments.get(0);
    }

    if (PluginConfig.getInstance().getConfig(SettingsConfig.class).isLoggingDebug()) {

      logger.info("Attempting to find current rank...");
      logger.info("Search for player: " + searchPlayer);
    }

    // get the players information
    PlayerInfo playerInfo = getPlayerInfoUtil().getPlayerInfo(plugin, sender, searchPlayer);
    if (playerInfo != null) {

      if (PluginConfig.getInstance().getConfig(SettingsConfig.class).isLoggingDebug()) {

        logger.info("Player: " + playerInfo.getPlayer());
        logger.info("World: " + playerInfo.getPlayer().getWorld());
        logger.info("Name: " + playerInfo.getPlayer().getName());
        logger.info("Current Rank: " + playerInfo.getCurrentRank());
      }

      // check to make sure they have a current rank
      if (playerInfo.getCurrentRank() != null) {

        // if the sender isn't the player, send the sender a different message
        if (sender != playerInfo.getPlayer()) {

          // tell the sender we're done
          String completedSender =
              PluginConfig.getInstance()
                  .getConfig(ResourcesConfig.class)
                  .getResource("payrank.current.completed.sender");

          completedSender =
              completedSender.replaceAll(
                  "<rank>",
                  ChatColor.BLUE + playerInfo.getCurrentRank().getName() + ChatColor.GREEN);

          completedSender =
              completedSender.replaceAll(
                  "<player>", ChatColor.AQUA + playerInfo.getPlayer().getName() + ChatColor.GREEN);

          // give the error back to the caller
          sender.sendMessage(ChatColor.GREEN + completedSender);

        } else {

          // tell the player we're done
          String completedPlayer =
              PluginConfig.getInstance()
                  .getConfig(ResourcesConfig.class)
                  .getResource("payrank.current.completed.player");

          completedPlayer =
              completedPlayer.replaceAll(
                  "<rank>",
                  ChatColor.BLUE + playerInfo.getCurrentRank().getName() + ChatColor.GREEN);

          // give the error back to the caller
          sender.sendMessage(ChatColor.GREEN + completedPlayer);
        }

        return;

      } else {

        // give the error back to the caller
        String cannotFindRankSender =
            PluginConfig.getInstance()
                .getConfig(ResourcesConfig.class)
                .getResource("payrank.current.cannotFindRank.sender");

        sender.sendMessage(ChatColor.RED + cannotFindRankSender);
      }
    }
  }