예제 #1
0
  private void giveBonus(String[] split) throws TownyException {

    Town town;

    try {
      if (split.length != 2)
        throw new TownyException(
            String.format(
                TownySettings.getLangString("msg_err_invalid_input"),
                "Eg: givebonus [town/player] [n]"));
      try {
        town = TownyUniverse.getDataSource().getTown(split[0]);
      } catch (NotRegisteredException e) {
        town = TownyUniverse.getDataSource().getResident(split[0]).getTown();
      }
      try {
        town.setBonusBlocks(town.getBonusBlocks() + Integer.parseInt(split[1].trim()));
        TownyMessaging.sendMsg(
            getSender(),
            String.format(
                TownySettings.getLangString("msg_give_total"),
                town.getName(),
                split[1],
                town.getBonusBlocks()));
      } catch (NumberFormatException nfe) {
        throw new TownyException(TownySettings.getLangString("msg_error_must_be_int"));
      }
      TownyUniverse.getDataSource().saveTown(town);
    } catch (TownyException e) {
      throw new TownyException(e.getMessage());
    }
  }
예제 #2
0
파일: War.java 프로젝트: adegie/Towny
  public void start() {
    warTime = true;

    // Announce

    // Seed spoils of war
    try {
      warSpoils.pay(TownySettings.getBaseSpoilsOfWar(), "Start of War - Base Spoils");
      TownyMessaging.sendMsg(
          "[War] Seeding spoils of war with " + TownySettings.getBaseSpoilsOfWar());
    } catch (EconomyException e) {
      TownyMessaging.sendErrorMsg("[War] Could not seed spoils of war.");
    }

    // Gather all nations at war
    for (Nation nation : TownyUniverse.getDataSource().getNations()) {
      if (!nation.isNeutral()) {
        add(nation);
        TownyMessaging.sendGlobalMessage(
            String.format(TownySettings.getLangString("msg_war_join_nation"), nation.getName()));
      } else if (!TownySettings.isDeclaringNeutral()) {
        try {
          nation.setNeutral(false);
          add(nation);
          TownyMessaging.sendGlobalMessage(
              String.format(TownySettings.getLangString("msg_war_join_forced"), nation.getName()));
        } catch (TownyException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
    // warTimer.scheduleAtFixedRate(new WarTimerTask(this), 0, 1000);
    int id =
        plugin
            .getServer()
            .getScheduler()
            .scheduleAsyncRepeatingTask(
                getPlugin(), new WarTimerTask(this), 0, TimeTools.convertToTicks(5));
    if (id == -1) {
      TownyMessaging.sendErrorMsg("Could not schedule war event loop.");
      end();
    } else addTaskId(id);
    checkEnd();
  }
예제 #3
0
  public void reloadTowny(Boolean reset) {

    if (reset) {
      TownyUniverse.getDataSource().deleteFile(plugin.getConfigPath());
    }
    TownyLogger.shutDown();
    if (plugin.load()) {

      // Register all child permissions for ranks
      TownyPerms.registerPermissionNodes();

      // Update permissions for all online players
      TownyPerms.updateOnlinePerms();
    }

    TownyMessaging.sendMsg(sender, TownySettings.getLangString("msg_reloaded"));
    // TownyMessaging.sendMsg(TownySettings.getLangString("msg_reloaded"));
  }
예제 #4
0
 public void toggleDailyTimer(boolean on) {
   if (on && !isDailyTimerRunning()) {
     long timeTillNextDay = TownyUtil.townyTime();
     TownyMessaging.sendMsg(
         "Time until a New Day: " + TimeMgmt.formatCountdownTime(timeTillNextDay));
     dailyTask =
         getPlugin()
             .getServer()
             .getScheduler()
             .scheduleAsyncRepeatingTask(
                 getPlugin(),
                 new DailyTimerTask(this),
                 MinecraftTools.convertToTicks(timeTillNextDay),
                 MinecraftTools.convertToTicks(TownySettings.getDayInterval()));
     if (dailyTask == -1) TownyMessaging.sendErrorMsg("Could not schedule new day loop.");
   } else if (!on && isDailyTimerRunning()) {
     getPlugin().getServer().getScheduler().cancelTask(dailyTask);
     dailyTask = -1;
   }
   setChangedNotify(TOGGLE_DAILY_TIMER);
 }
예제 #5
0
  public void parseToggleCommand(String[] split) throws TownyException {

    boolean choice;

    if (split.length == 0) {
      // command was '/townyadmin toggle'
      player.sendMessage(ChatTools.formatTitle("/townyadmin toggle"));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "war", ""));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "neutral", ""));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "devmode", ""));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle", "debug", ""));
      player.sendMessage(
          ChatTools.formatCommand("", "/townyadmin toggle", "townwithdraw/nationwithdraw", ""));
      player.sendMessage(ChatTools.formatCommand("", "/townyadmin toggle npc", "[resident]", ""));
      return;
    }

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

    if (split[0].equalsIgnoreCase("war")) {
      choice = TownyUniverse.isWarTime();

      if (!choice) {
        plugin.getTownyUniverse().startWarEvent();
        TownyMessaging.sendMsg(getSender(), TownySettings.getLangString("msg_war_started"));
      } else {
        plugin.getTownyUniverse().endWarEvent();
        TownyMessaging.sendMsg(getSender(), TownySettings.getLangString("msg_war_ended"));
      }
    } else if (split[0].equalsIgnoreCase("neutral")) {

      try {
        choice = !TownySettings.isDeclaringNeutral();
        TownySettings.setDeclaringNeutral(choice);
        TownyMessaging.sendMsg(
            getSender(),
            String.format(
                TownySettings.getLangString("msg_nation_allow_neutral"),
                choice ? "Enabled" : "Disabled"));

      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
        return;
      }

    } else if (split[0].equalsIgnoreCase("devmode")) {
      try {
        choice = !TownySettings.isDevMode();
        TownySettings.setDevMode(choice);
        TownyMessaging.sendMsg(
            getSender(),
            "Dev Mode " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled"));
      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
      }
    } else if (split[0].equalsIgnoreCase("debug")) {
      try {
        choice = !TownySettings.getDebug();
        TownySettings.setDebug(choice);
        TownyMessaging.sendMsg(
            getSender(),
            "Debug Mode " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled"));
      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
      }
    } else if (split[0].equalsIgnoreCase("townwithdraw")) {
      try {
        choice = !TownySettings.getTownBankAllowWithdrawls();
        TownySettings.SetTownBankAllowWithdrawls(choice);
        TownyMessaging.sendMsg(
            getSender(),
            "Town Withdrawls " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled"));
      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
      }
    } else if (split[0].equalsIgnoreCase("nationwithdraw")) {
      try {
        choice = !TownySettings.geNationBankAllowWithdrawls();
        TownySettings.SetNationBankAllowWithdrawls(choice);
        TownyMessaging.sendMsg(
            getSender(),
            "Nation Withdrawls " + (choice ? Colors.Green + "Enabled" : Colors.Red + "Disabled"));
      } catch (Exception e) {
        TownyMessaging.sendErrorMsg(
            getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
      }

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

      if (split.length != 2)
        throw new TownyException(
            String.format(
                TownySettings.getLangString("msg_err_invalid_input"), "Eg: toggle npc [resident]"));

      try {
        Resident resident = TownyUniverse.getDataSource().getResident(split[1]);
        resident.setNPC(!resident.isNPC());

        TownyUniverse.getDataSource().saveResident(resident);

        TownyMessaging.sendMessage(
            sender,
            String.format(
                TownySettings.getLangString("msg_npc_flag"), resident.isNPC(), resident.getName()));

      } catch (NotRegisteredException x) {
        throw new TownyException(
            String.format(TownySettings.getLangString("msg_err_not_registered_1"), split[1]));
      }

    } else {
      // parameter error message
      // neutral/war/townmobs/worldmobs
      TownyMessaging.sendErrorMsg(
          getSender(), TownySettings.getLangString("msg_err_invalid_choice"));
    }
  }
예제 #6
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;
  }