コード例 #1
0
 /*     */ public boolean run(
     CommandSender sender,
     Player sender_p,
     Command cmd,
     String commandLabel,
     String[] args,
     boolean senderIsConsole)
       /*     */ {
   /*  19 */ if (args.length < 1) {
     /*  21 */ return false;
     /*     */ }
   /*  25 */ if (args[0].equalsIgnoreCase("list"))
   /*     */ {
     /*  27 */ playerMsg(
         "Whitelisted players: " + TFM_Util.playerListToNames(server.getWhitelistedPlayers()));
     /*  28 */ return true;
     /*     */ }
   /*  32 */ if (args[0].equalsIgnoreCase("count"))
   /*     */ {
     /*  34 */ int onlineWPs = 0;
     /*  35 */ int offlineWPs = 0;
     /*  36 */ int totalWPs = 0;
     /*  38 */ for (OfflinePlayer player : server.getWhitelistedPlayers())
     /*     */ {
       /*  40 */ if (player.isOnline()) {
         /*  42 */ onlineWPs++;
         /*     */ } else {
         /*  46 */ offlineWPs++;
         /*     */ }
       /*  48 */ totalWPs++;
       /*     */ }
     /*  51 */ playerMsg("Online whitelisted players: " + onlineWPs);
     /*  52 */ playerMsg("Offline whitelisted players: " + offlineWPs);
     /*  53 */ playerMsg("Total whitelisted players: " + totalWPs);
     /*     */
     /*  55 */ return true;
     /*     */ }
   /*  59 */ if ((!senderIsConsole) && (!TFM_AdminList.isSuperAdmin(sender)))
   /*     */ {
     /*  61 */ sender.sendMessage(TFM_Command.MSG_NO_PERMS);
     /*  62 */ return true;
     /*     */ }
   /*  66 */ if (args[0].equalsIgnoreCase("on"))
   /*     */ {
     /*  68 */ TFM_Util.adminAction(sender.getName(), "Turning the whitelist on.", true);
     /*  69 */ server.setWhitelist(true);
     /*  70 */ return true;
     /*     */ }
   /*  74 */ if (args[0].equalsIgnoreCase("off"))
   /*     */ {
     /*  76 */ TFM_Util.adminAction(sender.getName(), "Turning the whitelist off.", true);
     /*  77 */ server.setWhitelist(false);
     /*  78 */ return true;
     /*     */ }
   /*  82 */ if (args[0].equalsIgnoreCase("add"))
   /*     */ {
     /*  84 */ if (args.length < 2) {
       /*  86 */ return false;
       /*     */ }
     /*  89 */ String search_name = args[1].trim().toLowerCase();
     /*     */
     /*  91 */ OfflinePlayer player = getPlayer(search_name);
     /*  93 */ if (player == null) {
       /*  95 */ player = TFM_DepreciationAggregator.getOfflinePlayer(server, search_name);
       /*     */ }
     /*  98 */ TFM_Util.adminAction(
         sender.getName(), "Adding " + player.getName() + " to the whitelist.", false);
     /*  99 */ player.setWhitelisted(true);
     /* 100 */ return true;
     /*     */ }
   /* 104 */ if ("remove".equals(args[0]))
   /*     */ {
     /* 106 */ if (args.length < 2) {
       /* 108 */ return false;
       /*     */ }
     /* 111 */ String search_name = args[1].trim().toLowerCase();
     /*     */
     /* 113 */ OfflinePlayer player = getPlayer(search_name);
     /* 115 */ if (player == null) {
       /* 117 */ player = TFM_DepreciationAggregator.getOfflinePlayer(server, search_name);
       /*     */ }
     /* 120 */ if (player.isWhitelisted())
     /*     */ {
       /* 122 */ TFM_Util.adminAction(
           sender.getName(), "Removing " + player.getName() + " from the whitelist.", false);
       /* 123 */ player.setWhitelisted(false);
       /* 124 */ return true;
       /*     */ }
     /* 128 */ playerMsg("That player is not whitelisted");
     /* 129 */ return true;
     /*     */ }
   /* 135 */ if (args[0].equalsIgnoreCase("addall"))
   /*     */ {
     /* 137 */ TFM_Util.adminAction(
         sender.getName(), "Adding all online players to the whitelist.", false);
     /* 138 */ int counter = 0;
     /* 139 */ for (Player player : server.getOnlinePlayers()) {
       /* 141 */ if (!player.isWhitelisted())
       /*     */ {
         /* 143 */ player.setWhitelisted(true);
         /* 144 */ counter++;
         /*     */ }
       /*     */ }
     /* 148 */ playerMsg("Whitelisted " + counter + " players.");
     /* 149 */ return true;
     /*     */ }
   /* 153 */ if (!senderIsConsole)
   /*     */ {
     /* 155 */ sender.sendMessage(TFM_Command.MSG_NO_PERMS);
     /* 156 */ return true;
     /*     */ }
   /* 160 */ if (args[0].equalsIgnoreCase("purge"))
   /*     */ {
     /* 162 */ TFM_Util.adminAction(
         sender.getName(), "Removing all players from the whitelist.", false);
     /* 163 */ playerMsg(
         "Removed " + TFM_ServerInterface.purgeWhitelist() + " players from the whitelist.");
     /*     */
     /* 165 */ return true;
     /*     */ }
   /* 169 */ return false;
   /*     */ }
コード例 #2
0
  @Override
  public boolean run(
      CommandSender sender,
      Player sender_p,
      Command cmd,
      String commandLabel,
      String[] args,
      boolean senderIsConsole) {
    if (args.length < 1) {
      return false;
    }

    // list
    if (args[0].equalsIgnoreCase("list")) {
      playerMsg(
          "Whitelisted players: " + TFM_Util.playerListToNames(server.getWhitelistedPlayers()));
      return true;
    }

    // count
    if (args[0].equalsIgnoreCase("count")) {
      int onlineWPs = 0;
      int offlineWPs = 0;
      int totalWPs = 0;

      for (OfflinePlayer player : server.getWhitelistedPlayers()) {
        if (player.isOnline()) {
          onlineWPs++;
        } else {
          offlineWPs++;
        }
        totalWPs++;
      }

      playerMsg("Online whitelisted players: " + onlineWPs);
      playerMsg("Offline whitelisted players: " + offlineWPs);
      playerMsg("Total whitelisted players: " + totalWPs);

      return true;
    }

    // all commands past this line are superadmin-only
    if (!(senderIsConsole || TFM_AdminList.isSuperAdmin(sender))) {
      sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
      return true;
    }

    // on
    if (args[0].equalsIgnoreCase("on")) {
      TFM_Util.adminAction(sender.getName(), "Turning the whitelist on.", true);
      server.setWhitelist(true);
      return true;
    }

    // off
    if (args[0].equalsIgnoreCase("off")) {
      TFM_Util.adminAction(sender.getName(), "Turning the whitelist off.", true);
      server.setWhitelist(false);
      return true;
    }

    // add
    if (args[0].equalsIgnoreCase("add")) {
      if (args.length < 2) {
        return false;
      }

      String search_name = args[1].trim().toLowerCase();

      OfflinePlayer player = getPlayer(search_name);

      if (player == null) {
        player = server.getOfflinePlayer(search_name);
      }

      TFM_Util.adminAction(
          sender.getName(), "Adding " + player.getName() + " to the whitelist.", false);
      player.setWhitelisted(true);
      return true;
    }

    // remove
    if ("remove".equals(args[0])) {
      if (args.length < 2) {
        return false;
      }

      String search_name = args[1].trim().toLowerCase();

      OfflinePlayer player = getPlayer(search_name);

      if (player == null) {
        player = server.getOfflinePlayer(search_name);
      }

      if (player.isWhitelisted()) {
        TFM_Util.adminAction(
            sender.getName(), "Removing " + player.getName() + " from the whitelist.", false);
        player.setWhitelisted(false);
        return true;
      } else {
        playerMsg("That player is not whitelisted");
        return true;
      }
    }

    // addall
    if (args[0].equalsIgnoreCase("addall")) {
      TFM_Util.adminAction(sender.getName(), "Adding all online players to the whitelist.", false);
      int counter = 0;
      for (Player player : server.getOnlinePlayers()) {
        if (!player.isWhitelisted()) {
          player.setWhitelisted(true);
          counter++;
        }
      }

      playerMsg("Whitelisted " + counter + " players.");
      return true;
    }

    // all commands past this line are console/telnet only
    if (!senderIsConsole) {
      sender.sendMessage(TotalFreedomMod.MSG_NO_PERMS);
      return true;
    }

    // purge
    if (args[0].equalsIgnoreCase("purge")) {
      TFM_Util.adminAction(sender.getName(), "Removing all players from the whitelist.", false);
      playerMsg("Removed " + TFM_ServerInterface.purgeWhitelist() + " players from the whitelist.");

      return true;
    }

    // none of the commands were executed
    return false;
  }