Esempio n. 1
0
  @Override
  public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {

    this.sender = sender;

    if (sender instanceof Player) {
      player = (Player) sender;
      isConsole = false;
      System.out.println(
          "[PLAYER_COMMAND] "
              + player.getName()
              + ": /"
              + commandLabel
              + " "
              + StringMgmt.join(args));

    } else {
      isConsole = true;
      this.player = null;
    }

    try {
      return parseTownyAdminCommand(args);
    } catch (TownyException e) {
      TownyMessaging.sendErrorMsg(sender, e.getMessage());
    }

    return true;
  }
Esempio n. 2
0
  public void parseAdminNationCommand(String[] split) throws TownyException {

    if (split.length == 0 || split[0].equalsIgnoreCase("?")) {

      sender.sendMessage(ChatTools.formatTitle("/townyadmin nation"));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"), "/townyadmin nation", "[nation]", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin nation",
              "[nation] add [] .. []",
              ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin nation",
              "[nation] rename [newname]",
              ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin nation",
              "[nation] delete",
              ""));

      return;
    }
    try {
      Nation nation = TownyUniverse.getDataSource().getNation(split[0]);
      if (split.length == 1) {
        TownyMessaging.sendMessage(getSender(), TownyFormatter.getStatus(nation));
        return;
      }

      if (!TownyUniverse.getPermissionSource()
          .testPermission(
              player,
              PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_NATION.getNode(split[1].toLowerCase())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

      if (split[1].equalsIgnoreCase("add")) {
        /*
         * if (isConsole) { sender.sendMessage(
         * "[Towny] InputError: This command was designed for use in game only."
         * ); return; }
         */
        NationCommand.nationAdd(
            nation, TownyUniverse.getDataSource().getTowns(StringMgmt.remArgs(split, 2)));

      } else if (split[1].equalsIgnoreCase("delete")) {

        TownyUniverse.getDataSource().removeNation(nation);

      } else if (split[1].equalsIgnoreCase("rename")) {

        if (!NameValidation.isBlacklistName(split[2])) {
          TownyUniverse.getDataSource().renameNation(nation, split[2]);
          TownyMessaging.sendNationMessage(
              nation,
              String.format(
                  TownySettings.getLangString("msg_nation_set_name"),
                  ((getSender() instanceof Player) ? player.getName() : "CONSOLE"),
                  nation.getName()));
        } else
          TownyMessaging.sendErrorMsg(getSender(), TownySettings.getLangString("msg_invalid_name"));
      }

    } catch (NotRegisteredException e) {
      TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
    } catch (AlreadyRegisteredException e) {
      TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
    }
  }
Esempio n. 3
0
  public void parseAdminTownCommand(String[] split) throws TownyException {

    // TODO Make this use the actual town command procedually.

    if (split.length == 0 || split[0].equalsIgnoreCase("?")) {
      sender.sendMessage(ChatTools.formatTitle("/townyadmin town"));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town]", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin town",
              "[town] add/kick [] .. []",
              ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin town",
              "[town] rename [newname]",
              ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town] delete", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"), "/townyadmin town", "[town] spawn", ""));
      sender.sendMessage(
          ChatTools.formatCommand(
              TownySettings.getLangString("admin_sing"),
              "/townyadmin town",
              "[town] outpost #",
              ""));

      return;
    }

    try {

      Town town = TownyUniverse.getDataSource().getTown(split[0]);

      if (split.length == 1) {
        TownyMessaging.sendMessage(getSender(), TownyFormatter.getStatus(town));
        return;
      }

      if (!TownyUniverse.getPermissionSource()
          .testPermission(
              player,
              PermissionNodes.TOWNY_COMMAND_TOWNYADMIN_TOWN.getNode(split[1].toLowerCase())))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

      if (split[1].equalsIgnoreCase("add")) {
        /*
         * if (isConsole) { sender.sendMessage(
         * "[Towny] InputError: This command was designed for use in game only."
         * ); return; }
         */
        TownCommand.townAdd(getSender(), town, StringMgmt.remArgs(split, 2));

      } else if (split[1].equalsIgnoreCase("kick")) {

        TownCommand.townKickResidents(
            getSender(),
            town.getMayor(),
            town,
            TownyUniverse.getValidatedResidents(getSender(), StringMgmt.remArgs(split, 2)));

      } else if (split[1].equalsIgnoreCase("delete")) {

        TownyUniverse.getDataSource().removeTown(town);

      } else if (split[1].equalsIgnoreCase("rename")) {

        if (!NameValidation.isBlacklistName(split[2])) {
          TownyUniverse.getDataSource().renameTown(town, split[2]);
          TownyMessaging.sendTownMessage(
              town,
              String.format(
                  TownySettings.getLangString("msg_town_set_name"),
                  ((getSender() instanceof Player) ? player.getName() : "CONSOLE"),
                  town.getName()));
        } else
          TownyMessaging.sendErrorMsg(getSender(), TownySettings.getLangString("msg_invalid_name"));

      } else if (split[1].equalsIgnoreCase("spawn")) {

        TownCommand.townSpawn(player, StringMgmt.remArgs(split, 2), town, "", false);

      } else if (split[1].equalsIgnoreCase("outpost")) {

        TownCommand.townSpawn(player, StringMgmt.remArgs(split, 2), town, "", true);
      }

    } catch (NotRegisteredException e) {
      TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
    } catch (TownyException e) {
      TownyMessaging.sendErrorMsg(getSender(), e.getMessage());
    }
  }
Esempio n. 4
0
  public boolean parseTownyAdminCommand(String[] split) throws TownyException {

    if (split.length == 0) {
      buildTAPanel();
      for (String line : ta_panel) {
        sender.sendMessage(line);
      }

    } else if (split[0].equalsIgnoreCase("?") || split[0].equalsIgnoreCase("help")) {
      for (String line : ta_help) {
        sender.sendMessage(line);
      }
    } else {

      if (split[0].equalsIgnoreCase("set")) {

        adminSet(StringMgmt.remFirstArg(split));
        return true;

      } else if (split[0].equalsIgnoreCase("town")) {

        parseAdminTownCommand(StringMgmt.remFirstArg(split));
        return true;

      } else if (split[0].equalsIgnoreCase("nation")) {

        parseAdminNationCommand(StringMgmt.remFirstArg(split));
        return true;

      } else if (split[0].equalsIgnoreCase("toggle")) {

        parseToggleCommand(StringMgmt.remFirstArg(split));
        return true;
      }

      if ((!isConsole)
          && (!TownyUniverse.getPermissionSource()
              .testPermission(
                  player,
                  PermissionNodes.TOWNY_COMMAND_TOWNYADMIN.getNode(split[0].toLowerCase()))))
        throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));

      if (split[0].equalsIgnoreCase("givebonus")) {

        giveBonus(StringMgmt.remFirstArg(split));

      } else if (split[0].equalsIgnoreCase("reload")) {

        reloadTowny(false);

      } else if (split[0].equalsIgnoreCase("reset")) {

        reloadTowny(true);

      } else if (split[0].equalsIgnoreCase("backup")) {

        try {
          TownyUniverse.getDataSource().backup();
          TownyMessaging.sendMsg(getSender(), TownySettings.getLangString("mag_backup_success"));

        } catch (IOException e) {
          TownyMessaging.sendErrorMsg(getSender(), "Error: " + e.getMessage());
        }

      } else if (split[0].equalsIgnoreCase("newday")) {

        TownyTimerHandler.newDay();

      } else if (split[0].equalsIgnoreCase("purge")) {

        purge(StringMgmt.remFirstArg(split));

      } else if (split[0].equalsIgnoreCase("delete")) {
        String[] newSplit = StringMgmt.remFirstArg(split);
        residentDelete(player, newSplit);
      } else if (split[0].equalsIgnoreCase("unclaim")) {

        parseAdminUnclaimCommand(StringMgmt.remFirstArg(split));
        /*
         * else if (split[0].equalsIgnoreCase("seed") &&
         * TownySettings.getDebug()) seedTowny(); else if
         * (split[0].equalsIgnoreCase("warseed") &&
         * TownySettings.getDebug()) warSeed(player);
         */

      } else {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_sub"));
        return false;
      }
    }

    return true;
  }