Ejemplo n.º 1
0
 /**
  * @param maxListing Maximum lines to return. Value of -1 return all.
  * @return A list of the current scores per town sorted in descending order.
  */
 public List<String> getScores(int maxListing) {
   List<String> output = new ArrayList<String>();
   output.add(ChatTools.formatTitle("War - Top Scores"));
   KeyValueTable<Town, Integer> kvTable = new KeyValueTable<Town, Integer>(townScores);
   kvTable.sortByValue();
   kvTable.revese();
   int n = 0;
   for (KeyValue<Town, Integer> kv : kvTable.getKeyValues()) {
     n++;
     if (maxListing != -1 && n > maxListing) break;
     Town town = (Town) kv.key;
     output.add(
         String.format(
             Colors.Blue + "%40s " + Colors.Gold + "|" + Colors.LightGray + " %4d",
             TownyFormatter.getFormattedName(town),
             (Integer) kv.value));
   }
   return output;
 }
Ejemplo 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());
    }
  }
Ejemplo 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());
    }
  }
Ejemplo n.º 4
0
  private void buildTAPanel() {

    ta_panel.clear();
    Runtime run = Runtime.getRuntime();
    ta_panel.add(ChatTools.formatTitle(TownySettings.getLangString("ta_panel_1")));
    ta_panel.add(
        Colors.Blue
            + "["
            + Colors.LightBlue
            + "Towny"
            + Colors.Blue
            + "] "
            + Colors.Green
            + TownySettings.getLangString("ta_panel_2")
            + Colors.LightGreen
            + TownyUniverse.isWarTime()
            + Colors.Gray
            + " | "
            + Colors.Green
            + TownySettings.getLangString("ta_panel_3")
            + (TownyTimerHandler.isHealthRegenRunning()
                ? Colors.LightGreen + "On"
                : Colors.Rose + "Off")
            + Colors.Gray
            + " | "
            + (Colors.Green
                + TownySettings.getLangString("ta_panel_5")
                + (TownyTimerHandler.isDailyTimerRunning()
                    ? Colors.LightGreen + "On"
                    : Colors.Rose + "Off")));
    /*
     * ta_panel.add(Colors.Blue + "[" + Colors.LightBlue + "Towny" +
     * Colors.Blue + "] " + Colors.Green +
     * TownySettings.getLangString("ta_panel_4") +
     * (TownySettings.isRemovingWorldMobs() ? Colors.LightGreen + "On" :
     * Colors.Rose + "Off") + Colors.Gray + " | " + Colors.Green +
     * TownySettings.getLangString("ta_panel_4_1") +
     * (TownySettings.isRemovingTownMobs() ? Colors.LightGreen + "On" :
     * Colors.Rose + "Off"));
     *
     * try { TownyEconomyObject.checkEconomy(); ta_panel.add(Colors.Blue +
     * "[" + Colors.LightBlue + "Economy" + Colors.Blue + "] " +
     * Colors.Green + TownySettings.getLangString("ta_panel_6") +
     * Colors.LightGreen + TownyFormatter.formatMoney(getTotalEconomy()) +
     * Colors.Gray + " | " + Colors.Green +
     * TownySettings.getLangString("ta_panel_7") + Colors.LightGreen +
     * getNumBankAccounts()); } catch (Exception e) { }
     */
    ta_panel.add(
        Colors.Blue
            + "["
            + Colors.LightBlue
            + TownySettings.getLangString("ta_panel_8")
            + Colors.Blue
            + "] "
            + Colors.Green
            + TownySettings.getLangString("ta_panel_9")
            + Colors.LightGreen
            + MemMgmt.getMemSize(run.totalMemory())
            + Colors.Gray
            + " | "
            + Colors.Green
            + TownySettings.getLangString("ta_panel_10")
            + Colors.LightGreen
            + Thread.getAllStackTraces().keySet().size()
            + Colors.Gray
            + " | "
            + Colors.Green
            + TownySettings.getLangString("ta_panel_11")
            + Colors.LightGreen
            + TownyFormatter.getTime());
    ta_panel.add(Colors.Yellow + MemMgmt.getMemoryBar(50, run));
  }