Package com.palmergames.bukkit.towny

Examples of com.palmergames.bukkit.towny.TownyException


                try {
                    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"));
                } catch (TownyException x) {
                    TownyMessaging.sendErrorMsg(player, x.getMessage());
                    return;
                }
                try {
                  if (split[0].equalsIgnoreCase("bonus")) {
                    if (split.length == 2) {
                          try {
                            int bought = townBuyBonusTownBlocks(town, Integer.parseInt(split[1].trim()));
                            double cost = bought * TownySettings.getPurchasedBonusBlocksCost();
                            TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_buy"), bought, "bonus town blocks", TownyFormatter.formatMoney(cost)));
                          } catch (NumberFormatException e) {
                            throw new TownyException(TownySettings.getLangString("msg_error_must_be_int"));
                          }
                    } else {
                          throw new TownyException(String.format(TownySettings.getLangString("msg_must_specify_amnt"), "/town buy bonus"));
                      }
                  }
 
          TownyUniverse.getDataSource().saveTown(town);
                } catch (TownyException x) {
View Full Code Here


         * @return The number of purchased bonus blocks.
         * @throws TownyException
         */
      public static int townBuyBonusTownBlocks(Town town, int inputN) throws TownyException {
        if (inputN < 0)
          throw new TownyException(TownySettings.getLangString("msg_err_negative"));
       
        int current = town.getPurchasedBlocks();
       
        int n;
        if (current + inputN > TownySettings.getMaxPurchedBlocks()) {
          n = TownySettings.getMaxPurchedBlocks() - current;
        } else {
          n = inputN;
        }
       
        if (n == 0)
          return n;
       
        try {
          double cost = n * TownySettings.getPurchasedBonusBlocksCost();
                if (TownySettings.isUsingEconomy() && !town.pay(cost, String.format("Town Buy Bonus (%d)", n)))
                  throw new TownyException(String.format(TownySettings.getLangString("msg_no_funds_to_buy"), n, "bonus town blocks", cost + TownyEconomyObject.getEconomyCurrency()));
          } catch (EconomyException e1) {
                throw new TownyException("Economy Error");
          }
         
        town.addPurchasedBlocks(n);
       
        return n;
View Full Code Here

        public void newTown(Player player, String name, String mayorName) {
                TownyUniverse universe = plugin.getTownyUniverse();
                try {
                        if (universe.isWarTime())
                                throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
                       
                        if (!TownyUniverse.getPermissionSource().isTownyAdmin(player) && ((TownySettings.isTownCreationAdminOnly() && !plugin.isPermissions())
                          || (plugin.isPermissions() && !TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_NEW.getNode()))))
                                throw new TownyException(TownySettings.getNotPermToNewTownLine());
                       
                        if (TownySettings.hasTownLimit() && TownyUniverse.getDataSource().getTowns().size() >= TownySettings.getTownLimit())
                                throw new TownyException(TownySettings.getLangString("msg_err_universe_limit"));
                       
                        if (!TownySettings.isValidRegionName(name))
                                throw new TownyException(String.format(TownySettings.getLangString("msg_err_invalid_name"), name));
                       
                        Resident resident = TownyUniverse.getDataSource().getResident(mayorName);
                        if (resident.hasTown())
                                throw new TownyException(String.format(TownySettings.getLangString("msg_err_already_res"), resident.getName()));

                        TownyWorld world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
                       
                        if (!world.isUsingTowny())
                                throw new TownyException(TownySettings.getLangString("msg_set_use_towny_off"));
                       
                        Coord key = Coord.parseCoord(player);
                        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"));
                       
                        if (TownySettings.getMaxDistanceBetweenHomeblocks() > 0)
                                if ((world.getMinDistanceFromOtherTowns(key) > TownySettings.getMaxDistanceBetweenHomeblocks()) && world.hasTowns())
                                        throw new TownyException(TownySettings.getLangString("msg_too_far"));

                        if (TownySettings.isUsingEconomy() && !resident.pay(TownySettings.getNewTownPrice(), "New Town Cost"))
                                throw new TownyException(String.format(TownySettings.getLangString("msg_no_funds_new_town"), (resident.getName().equals(player.getName()) ? "You" : resident.getName())));

                        newTown(universe, world, name, resident, key, player.getLocation());                   
                        TownyMessaging.sendGlobalMessage(TownySettings.getNewTownMsg(player.getName(), name));
                } catch (TownyException x) {
                        TownyMessaging.sendErrorMsg(player, x.getMessage());
View Full Code Here

                Resident resident;
                Town town;
                try {
                        //TODO: Allow leaving town during war.
                        if (plugin.getTownyUniverse().isWarTime())
                                throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
                       
                        resident = TownyUniverse.getDataSource().getResident(player.getName());
                        town = resident.getTown();
                        plugin.deleteCache(resident.getName());
                       
View Full Code Here

                   
                    if (playerNation == targetNation) {
                      townSpawnPermission = TownSpawnLevel.PART_OF_NATION;
                    } else if (targetNation.hasEnemy(playerNation)) {
                      // Prevent enemies from using spawn travel.
                            throw new TownyException(TownySettings.getLangString("msg_err_public_spawn_enemy"));
                    } else if (targetNation.hasAlly(playerNation)) {
                      townSpawnPermission = TownSpawnLevel.NATION_ALLY;
                    } else {
                        townSpawnPermission = TownSpawnLevel.UNAFFILIATED;
                      }
                  } else {
                    townSpawnPermission = TownSpawnLevel.UNAFFILIATED;
                  }
                }
               
                TownyMessaging.sendDebugMsg(townSpawnPermission.toString() + " " + townSpawnPermission.isAllowed());
                townSpawnPermission.checkIfAllowed(plugin, player);
               
                if (!(isTownyAdmin || townSpawnPermission == TownSpawnLevel.TOWN_RESIDENT) && !town.isPublic())
                  throw new TownyException(TownySettings.getLangString("msg_err_not_public"));
               
                if (!isTownyAdmin) {
                    // Prevent spawn travel while in disallowed zones (if configured)
                    List<String> disallowedZones = TownySettings.getDisallowedTownSpawnZones();
                   
                    if (!disallowedZones.isEmpty()) {
                        String inTown = null;
                        try {
                            Location loc = plugin.getCache(player).getLastLocation();
                            inTown = plugin.getTownyUniverse().getTownName(loc);
                        } catch (NullPointerException e) {
                            inTown = plugin.getTownyUniverse().getTownName(player.getLocation());
                        }
                       
                        if (inTown == null && disallowedZones.contains("unclaimed"))
                            throw new TownyException(String.format(TownySettings.getLangString("msg_err_town_spawn_disallowed_from"), "the Wilderness"));
                        if (inTown != null && resident.hasNation() && TownyUniverse.getDataSource().getTown(inTown).hasNation()) {
                            Nation inNation = TownyUniverse.getDataSource().getTown(inTown).getNation();
                            Nation playerNation = resident.getTown().getNation();
                            if (inNation.hasEnemy(playerNation) && disallowedZones.contains("enemy"))
                                throw new TownyException(String.format(TownySettings.getLangString("msg_err_town_spawn_disallowed_from"), "Enemy areas"));
                            if (!inNation.hasAlly(playerNation) && !inNation.hasEnemy(playerNation) && disallowedZones.contains("neutral"))
                                throw new TownyException(String.format(TownySettings.getLangString("msg_err_town_spawn_disallowed_from"), "Neutral towns"));
                        }
                    }
                }
               
                double travelCost = townSpawnPermission.getCost();
               
                // Check if need/can pay
                if (travelCost > 0 && TownySettings.isUsingEconomy() && (resident.getHoldingBalance() < travelCost))
                  throw new TownyException(notAffordMSG);
               
                // Used later to make sure the chunk we teleport to is loaded.
                Chunk chunk = town.getSpawn().getWorld().getChunkAt(town.getSpawn().getBlock());
               
                // Essentials tests
View Full Code Here

                        try {
                                Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                                Town town = resident.getTown();

                                if (!resident.isMayor())
                                    throw new TownyException(TownySettings.getLangString("msg_not_mayor"));
                                if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_DELETE.getNode())))
                                  throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
                               
                                TownyUniverse.getDataSource().removeTown(town);
                                TownyMessaging.sendGlobalMessage(TownySettings.getDelTownMsg(town));
                        } catch (TownyException x) {
                                TownyMessaging.sendErrorMsg(player, x.getMessage());
                                return;
                        }
                else
                        try {
                                if (!TownyUniverse.getPermissionSource().isTownyAdmin(player))
                                        throw new TownyException(TownySettings.getLangString("msg_err_admin_only_delete_town"));
                                Town town = TownyUniverse.getDataSource().getTown(split[0]);
                                TownyUniverse.getDataSource().removeTown(town);
                                TownyMessaging.sendGlobalMessage(TownySettings.getDelTownMsg(town));
                        } catch (TownyException x) {
                                TownyMessaging.sendErrorMsg(player, x.getMessage());
View Full Code Here

                try {
                        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"));
                } catch (TownyException x) {
                        TownyMessaging.sendErrorMsg(player, x.getMessage());
                        return;
                }
View Full Code Here

                Town town;
                try {
                        resident = TownyUniverse.getDataSource().getResident(player.getName());
                        town = resident.getTown();
                        if (!resident.isMayor())
                                throw new TownyException(TownySettings.getLangString("msg_not_mayor"));
                } catch (TownyException x) {
                        TownyMessaging.sendErrorMsg(player, x.getMessage());
                        return;
                }
View Full Code Here

                Town town;
                try {
                        resident = TownyUniverse.getDataSource().getResident(player.getName());
                        town = resident.getTown();
                        if (!resident.isMayor())
                                throw new TownyException(TownySettings.getLangString("msg_not_mayor"));
                } catch (TownyException x) {
                        TownyMessaging.sendErrorMsg(player, x.getMessage());
                        return;
                }
View Full Code Here

                        if (specifiedTown == null)
                                town = resident.getTown();
                        else
                                town = specifiedTown;
                        if (!TownyUniverse.getPermissionSource().isTownyAdmin((Player)sender) && !resident.isMayor() && !town.hasAssistant(resident))
                                throw new TownyException(TownySettings.getLangString("msg_not_mayor_ass"));
                  }
                       
                } catch (TownyException x) {
                        TownyMessaging.sendErrorMsg(sender, x.getMessage());
                        return;
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.