Пример #1
0
  public void removeTerritoryFromTown(String territName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    if (!localSender.hasMayoralPermissions()) {
      localSender.notifyInsufPermissions();
      return;
    }

    Town to = localSender.getActiveTown();

    if (to == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    territName = MCTownsRegion.formatRegionName(to, TownLevel.TERRITORY, territName);

    if (!townManager.removeTerritory(territName))
      localSender.sendMessage(
          ERR
              + "Error: Territory \""
              + territName
              + "\" does not exist and was not removed (because it doesn't exist!)");
    else localSender.sendMessage(SUCC + "Territory removed.");
  }
Пример #2
0
  public void addTerritorytoTown(String territName) {
    if (localSender.isConsole()) {
      localSender.notifyConsoleNotSupported();
      return;
    }

    boolean autoActive = !cmd.hasFlag(ECommand.DISABLE_AUTOACTIVE);
    boolean admin = cmd.hasFlag(ECommand.ADMIN);
    boolean adminAllowed = localSender.hasExternalPermissions(Perms.ADMIN.toString());

    if (!adminAllowed && admin) {
      localSender.sendMessage(
          ChatColor.DARK_RED
              + "You're not permitted to run this command with administrative priviliges!");
      return;
    }

    if (!(MCTConfig.MAYORS_CAN_BUY_TERRITORIES.getBoolean() || adminAllowed)) {
      localSender.sendMessage(
          ChatColor.BLUE + "Mayors are not allowed to add territories and you're not an admin.");
      return;
    }

    Town t = localSender.getActiveTown();

    if (t == null) {
      localSender.notifyActiveTownNotSet();
      return;
    }

    if ((t.getSize() < MCTConfig.MIN_NUM_PLAYERS_TO_BUY_TERRITORY.getInt()) && !admin) {
      localSender.sendMessage(
          ERR + "You don't have enough people in your town to buy territories yet.");
      localSender.sendMessage(
          ERR
              + "You have "
              + t.getSize()
              + " people, but you need a total of "
              + MCTConfig.MIN_NUM_PLAYERS_TO_BUY_TERRITORY.getInt()
              + "!");
      return;
    }

    territName = MCTownsRegion.formatRegionName(t, TownLevel.TERRITORY, territName);

    World w = localSender.getPlayer().getWorld();

    if (w == null) {
      localSender.sendMessage(
          ERR + "You are in an invalid World. (Player::getWorld() returned null)");
      return;
    }

    ProtectedRegion region = this.getSelectedRegion(territName);

    if (region == null) {
      localSender.sendMessage(ERR + "No region selected!");
      return;
    }

    int max = MCTConfig.TERRITORY_XZ_SIZE_LIMIT.getInt(),
        cur = WGUtils.getNumXZBlocksInRegion(region);
    if (cur > max && !localSender.hasExternalPermissions(Perms.ADMIN.toString())) {
      localSender.sendMessageF(
          "%sYou're not allowed to make a territory that big. (Current: %s, Limit: %s)",
          ERR, cur, max);
      return;
    }

    BigDecimal colPrice = new BigDecimal(MCTConfig.PRICE_PER_XZ_BLOCK.getString());
    // charge the player if they're not running this as an admin and buyable territories is enabled
    // and the price is more than 0
    if (!admin && colPrice.compareTo(BigDecimal.ZERO) > 0) {
      BigDecimal price = colPrice.multiply(new BigDecimal(WGUtils.getNumXZBlocksInRegion(region)));

      if (t.getBank().getCurrencyBalance().compareTo(price) < 0) {
        // If they can't afford it...
        localSender.sendMessage(
            ERR
                + "There is not enough money in your "
                + INFO
                + "town's bank account"
                + ERR
                + " to buy a region that large.");
        localSender.sendMessage(ERR + "Total Price: " + price);
        localSender.sendMessage(
            INFO + "Add money to your town's bank with: /town bank deposit currency <amount>");
        return;
      }

      // otherwise...
      t.getBank().withdrawCurrency(price);

      localSender.sendMessage(
          ChatColor.GREEN + "Purchase success! Total price was: " + price.toString());
    }

    try {
      townManager.addTerritory(territName, w, region, t);
    } catch (TownManager.InvalidWorldGuardRegionNameException
        | TownManager.RegionAlreadyExistsException ex) {
      localSender.sendMessage(ERR + ex.getLocalizedMessage());
      return;
    }

    region.getOwners().addPlayer(UUIDs.getNameForUUID(t.getMayor()));
    for (String assistantName : t.getAssistantNames()) region.getOwners().addPlayer(assistantName);

    localSender.sendMessage(SUCC + "Territory added.");

    if (autoActive) {
      localSender.setActiveTerritory(townManager.getTerritory(territName));
      localSender.sendMessage(
          ChatColor.LIGHT_PURPLE + "Active territory set to newly created territory.");
    }
  }