Package com.palmergames.bukkit.towny

Examples of com.palmergames.bukkit.towny.TownyException


      Resident resident;
      Town town;
      TownyWorld world;
      try {
        if (plugin.getTownyUniverse().isWarTime())
          throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));

        if (!TownyUniverse.getPermissionSource().isTownyAdmin(player) && plugin.isPermissions() && !TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_CLAIM.getNode()))
          throw new TownyException(TownySettings.getLangString("msg_no_perms_claim"));

        resident = TownyUniverse.getDataSource().getResident(player.getName());
        town = resident.getTown();
        if (!resident.isMayor() && !town.hasAssistant(resident))
          throw new TownyException(TownySettings.getLangString("msg_not_mayor_ass"));
        world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());

        if (!world.isUsingTowny())
          throw new TownyException(TownySettings.getLangString("msg_set_use_towny_off"));

        double blockCost = 0;
        List<WorldCoord> selection;
        boolean attachedToEdge = true;
        Coord key = Coord.parseCoord(plugin.getCache(player).getLastLocation());

        if (split.length == 1 && split[0].equalsIgnoreCase("outpost")) {
          if ((TownySettings.isAllowingOutposts())
            && (!plugin.isPermissions() || ((plugin.isPermissions()) && TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_CLAIM_OUTPOST.getNode())))){

            if (world.hasTownBlock(key))
              throw new TownyException(String.format(TownySettings.getLangString("msg_already_claimed_1"), key));

            if (world.getMinDistanceFromOtherTowns(key) < TownySettings.getMinDistanceFromTownHomeblocks())
              throw new TownyException(TownySettings.getLangString("msg_too_close"));

            selection = new ArrayList<WorldCoord>();
            selection.add(new WorldCoord(world, key));
            blockCost = TownySettings.getOutpostCost();
            attachedToEdge = false;
          } else
            throw new TownyException(TownySettings.getLangString("msg_outpost_disable"));
        } else {
          selection = TownyUtil.selectWorldCoordArea(town, new WorldCoord(world, key), split);
          blockCost = TownySettings.getClaimPrice();
        }

        TownyMessaging.sendDebugMsg("townClaim: Pre-Filter Selection " + Arrays.toString(selection.toArray(new WorldCoord[0])));
        selection = TownyUtil.filterTownOwnedBlocks(selection);
        TownyMessaging.sendDebugMsg("townClaim: Post-Filter Selection " + Arrays.toString(selection.toArray(new WorldCoord[0])));
        checkIfSelectionIsValid(town, selection, attachedToEdge, blockCost, false);

        try {
          double cost = blockCost * selection.size();
          if (TownySettings.isUsingEconomy() && !town.pay(cost, String.format("Town Claim (%d)", selection.size())))
            throw new TownyException(String.format(TownySettings.getLangString("msg_no_funds_claim"), selection.size(), cost + TownyEconomyObject.getEconomyCurrency()));
        } catch (EconomyException e1) {
          throw new TownyException("Economy Error");
        }

        new TownClaim(plugin, player, town, selection, true, false).start();

        //for (WorldCoord worldCoord : selection)
View Full Code Here


                        Resident resident;
                        Town town;
                        TownyWorld world;
                        try {
                                if (plugin.getTownyUniverse().isWarTime())
                                        throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
                               
                                resident = TownyUniverse.getDataSource().getResident(player.getName());
                                town = resident.getTown();
                                if (!resident.isMayor())
                                        if (!town.hasAssistant(resident))
                                                throw new TownyException(TownySettings.getLangString("msg_not_mayor_ass"));
                world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
                               
                                List<WorldCoord> selection;
                                if (split.length == 1 && split[0].equalsIgnoreCase("all"))
                                  new TownClaim(plugin, player, town, null, false, false).start();
View Full Code Here

               
                //System.out.print("isEdgeBlock: "+ isEdgeBlock(owner, selection));
               
                if (attachedToEdge && !isEdgeBlock(owner, selection) && !town.getTownBlocks().isEmpty()) {
                        if (selection.size() == 0)
                                throw new TownyException(TownySettings.getLangString("msg_already_claimed_2"));
                        else
                                throw new TownyException(TownySettings.getLangString("msg_err_not_attached_edge"));
                }
               
                if (owner instanceof Town) {
                        //Town town = (Town)owner;
                        int available = TownySettings.getMaxTownBlocks(town) - town.getTownBlocks().size();
                        TownyMessaging.sendDebugMsg("Claim Check Available: " + available);
                        TownyMessaging.sendDebugMsg("Claim Selection Size: " + selection.size());
                        if (available - selection.size() < 0)
                                throw new TownyException(TownySettings.getLangString("msg_err_not_enough_blocks"));
                }
               
                try {
                        double cost = blockCost * selection.size();
                        if (TownySettings.isUsingEconomy() && !owner.canPayFromHoldings(cost))
                                throw new TownyException(String.format(TownySettings.getLangString("msg_err_cant_afford_blocks"), selection.size(), cost + TownyEconomyObject.getEconomyCurrency()));
                } catch (EconomyException e1) {
                        throw new TownyException("Economy Error");
                }
        }
View Full Code Here

        private void townWithdraw(Player player, int amount) {
                Resident resident;
                Town town;
                try {
                        if(!TownySettings.getTownBankAllowWithdrawls())
                                throw new TownyException(TownySettings.getLangString("msg_err_withdraw_disabled"));
                       
                        if (amount < 0)
                                throw new TownyException(TownySettings.getLangString("msg_err_negative_money"));
                       
                        resident = TownyUniverse.getDataSource().getResident(player.getName());
                        town = resident.getTown();
                       
                        town.withdrawFromBank(resident, amount);
View Full Code Here

                        town = resident.getTown();
                       
                        double bankcap = TownySettings.getTownBankCap();
                        if (bankcap > 0) {
                                if(amount + town.getHoldingBalance() > bankcap)
                                        throw new TownyException(String.format(TownySettings.getLangString("msg_err_deposit_capped"), bankcap));
                        }
                       
                        if (amount < 0)
                                throw new TownyException(TownySettings.getLangString("msg_err_negative_money"));
                       
                        if (!resident.payTo(amount, town, "Town Deposit"))
                                throw new TownyException(TownySettings.getLangString("msg_insuf_funds"));
                       
                        TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_xx_deposited_xx"), resident.getName(), amount, "town"));
                } catch (TownyException x) {
                        TownyMessaging.sendErrorMsg(player, x.getMessage());
                } catch (EconomyException x) {
View Full Code Here

  }
 
  public static boolean callAttackCellEvent(Towny plugin, Player player, Block block, WorldCoord worldCoord) throws TownyException {
    int topY = block.getWorld().getHighestBlockYAt(block.getX(), block.getZ()) - 1;
    if (block.getY() < topY)
      throw new TownyException(TownySettings.getLangString("msg_err_enemy_war_must_be_placed_above_ground"));
   
    TownyUniverse universe = plugin.getTownyUniverse();
    Resident attackingResident;
    Town landOwnerTown, attackingTown;
    Nation landOwnerNation, attackingNation;
   
    try {
      attackingResident = TownyUniverse.getDataSource().getResident(player.getName());
      attackingTown = attackingResident.getTown();
      attackingNation = attackingTown.getNation();
    } catch (NotRegisteredException e) {
      throw new TownyException(TownySettings.getLangString("msg_err_dont_belong_nation"));
    }
   
    try {
      landOwnerTown = worldCoord.getTownBlock().getTown();
      landOwnerNation = landOwnerTown.getNation();
    } catch (NotRegisteredException e) {
      throw new TownyException(TownySettings.getLangString("msg_err_enemy_war_not_part_of_nation"));
    }
   
    // Check Neutrality
    if (landOwnerNation.isNeutral())
      throw new TownyException(String.format(TownySettings.getLangString("msg_err_enemy_war_is_neutral"), landOwnerNation.getFormattedName()));
    if (!TownyUniverse.getPermissionSource().isTownyAdmin(player) && attackingNation.isNeutral())
      throw new TownyException(String.format(TownySettings.getLangString("msg_err_enemy_war_is_neutral"), attackingNation.getFormattedName()));
   
    // Check Minimum Players Online
    checkIfTownHasMinOnlineForWar(universe, landOwnerTown);
    checkIfNationHasMinOnlineForWar(universe, landOwnerNation);
    checkIfTownHasMinOnlineForWar(universe, attackingTown);
    checkIfNationHasMinOnlineForWar(universe, attackingNation);
   
    // Check that attack takes place on the edge of a town
    if (!TownyUtil.isOnEdgeOfOwnership(landOwnerTown, worldCoord))
      throw new TownyException(TownySettings.getLangString("msg_err_enemy_war_not_on_edge_of_town"));
   
    // Call Event (and make sure an attack isn't already under way)
    CellAttackEvent cellAttackEvent = new CellAttackEvent(player, block);
    plugin.getServer().getPluginManager().callEvent(cellAttackEvent);
   
    if (cellAttackEvent.isCancelled()) {
      if (cellAttackEvent.hasReason())
        throw new TownyException(cellAttackEvent.getReason());
      else
        return false;
    }
   
    // Successful Attack
View Full Code Here

 
  public static void checkIfTownHasMinOnlineForWar(TownyUniverse universe, Town town) throws TownyException {
    int requiredOnline = TownyWarConfig.getMinPlayersOnlineInTownForWar();
    int onlinePlayerCount = TownyUniverse.getOnlinePlayers(town).size();
    if (onlinePlayerCount < requiredOnline)
      throw new TownyException(String.format(TownySettings.getLangString("msg_err_enemy_war_require_online"), requiredOnline, town.getFormattedName()));
  }
View Full Code Here

 
  public static void checkIfNationHasMinOnlineForWar(TownyUniverse universe, Nation nation) throws TownyException {
    int requiredOnline = TownyWarConfig.getMinPlayersOnlineInNationForWar();
    int onlinePlayerCount = TownyUniverse.getOnlinePlayers(nation).size();
    if (onlinePlayerCount < requiredOnline)
      throw new TownyException(String.format(TownySettings.getLangString("msg_err_enemy_war_require_online"), requiredOnline, nation.getFormattedName()));
  }
View Full Code Here

    public void setType(String typeName) throws TownyException {
        if (typeName.equalsIgnoreCase("reset")) typeName = "default";
        TownBlockType type = TownBlockType.lookup(typeName);
        if (type == null)
            throw new TownyException(TownySettings.getLangString("msg_err_not_block_type"));
        setType(type);
    }
View Full Code Here

          return TownBlockStatus.PLOT_FRIEND;
        else if (resident.hasTown() && isAlly(owner.getTown(), resident.getTown()))
          return TownBlockStatus.PLOT_ALLY;
        else
          // Exit out and use town permissions
          throw new TownyException();
      } catch (NotRegisteredException x) {
      } catch (TownyException x) {
      }

      // Town resident destroy rights
      if (!resident.hasTown())
        throw new TownyException();

      if (resident.getTown() != town) {
        // Allied destroy rights
        if (isAlly(town, resident.getTown()))
          return TownBlockStatus.TOWN_ALLY;
View Full Code Here

TOP

Related Classes of com.palmergames.bukkit.towny.TownyException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.