Package com.palmergames.bukkit.towny

Examples of com.palmergames.bukkit.towny.TownyException


                tag = "";
        }
       
        public void setTag(String text) throws TownyException {
          if (text.length() > 4)
            throw new TownyException("Tag too long");
        this.tag = text.toUpperCase();
        if (this.tag.matches(" "))
          this.tag = "";
        setChangedName(true);
      }
View Full Code Here


                assistants.clear();
        }

        public void setNeutral(boolean neutral) throws TownyException {
            if (!TownySettings.isDeclaringNeutral() && neutral)
                throw new TownyException(TownySettings.getLangString("msg_err_fight_like_king"));
            else {
            if (neutral) {
              for (Resident resident : getResidents()) {
                  TownyWar.removeAttackerFlags(resident.getName());
              }
View Full Code Here

                return neutral;
        }
       
        public void setKing(Resident king) throws TownyException {
                if (!hasResident(king))
                        throw new TownyException(TownySettings.getLangString("msg_err_king_not_in_nation"));
                if (!king.isMayor())
                        throw new TownyException(TownySettings.getLangString("msg_err_new_king_notmayor"));
                setCapital(king.getTown());
        }
View Full Code Here

                return false;
        }
       
        public void withdrawFromBank(Resident resident, int amount) throws EconomyException, TownyException {
                if (!isKing(resident) && !hasAssistant(resident))
                        throw new TownyException(TownySettings.getLangString("msg_no_access_nation_bank"));
               
                if (TownySettings.isUsingEconomy()) {
                        if (!payTo(amount, resident, "Nation Withdraw"))
                                throw new TownyException(TownySettings.getLangString("msg_err_no_money"));
                } else
                        throw new TownyException(TownySettings.getLangString("msg_err_no_economy"));
        }
View Full Code Here

   
    try {
      townBlock = worldCoord.getTownBlock();
      town = townBlock.getTown();
    } catch (NotRegisteredException e) {
      throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
    }
   
    TownyMessaging.sendMsg(player, String.format("2) %s", worldCoord.toString()));
   
    if (!resident.hasTown() && town.isOpen()) {
      // Town is open, so have the player join the town first.
      TownCommand.townJoin(town, resident);
      TownyMessaging.sendMsg(player, String.format("3) %s", worldCoord.toString()));
    }
   
    TownyMessaging.sendMsg(player, String.format("4) %s", worldCoord.toString()));
   
    if (!resident.hasTown()) {
      // Town is not open, or resident failed to join.
      // You are thus needed to belong to a town in order to claim plots.
      TownyMessaging.sendMsg(player, String.format("5) %s", worldCoord.toString()));
      throw new TownyException(TownySettings.getLangString("msg_err_not_in_town_claim"));
    } else {
      // Resident is (now) in a town.
      try {
        // Check for embassy plot, or if the resident is is the town.
        if (!resident.getTown().equals(town) && !townBlock.getType().equals(TownBlockType.EMBASSY))
          throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));

        try {
          Resident owner = townBlock.getResident();
          if (townBlock.getPlotPrice() != -1) {
            // Plot is for sale
            if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), owner, "Plot - Buy From Seller"))
              throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
           
            int maxPlots = TownySettings.getMaxResidentPlots(resident);
            if (maxPlots >= 0 && resident.getTownBlocks().size() + 1 > maxPlots)
              throw new TownyException(String.format(TownySettings.getLangString("msg_max_plot_own"), maxPlots));
           
            TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(resident.getName(), owner.getName(), townBlock.getPlotPrice()));
            townBlock.setPlotPrice(-1);
            townBlock.setResident(resident);
           
            // Set the plot permissions to mirror the new owners.
            townBlock.setType(townBlock.getType());

            TownyUniverse.getDataSource().saveResident(owner);
            TownyUniverse.getDataSource().saveTownBlock(townBlock);
           
            plugin.updateCache();
            return true;
          } else if (town.isMayor(resident) || town.hasAssistant(resident)) {
            //Plot isn't for sale but re-possessing for town.
           
            if (TownySettings.isUsingEconomy() && !town.payTo(0.0, owner, "Plot - Buy Back"))
              throw new TownyException(TownySettings.getLangString("msg_town_no_money_purchase_plot"));
           
            TownyMessaging.sendTownMessage(town, TownySettings.getBuyResidentPlotMsg(town.getName(), owner.getName(), 0.0));
            townBlock.setResident(null);
            townBlock.setPlotPrice(-1);
           
            // Set the plot permissions to mirror the towns.
            townBlock.setType(townBlock.getType());

            TownyUniverse.getDataSource().saveResident(owner);
            TownyUniverse.getDataSource().saveTownBlock(townBlock);

            return true;
          } else {
            //Should never reach here.
            throw new AlreadyRegisteredException(String.format(TownySettings.getLangString("msg_already_claimed"), owner.getName()));
          }
               
        } catch (NotRegisteredException e) {
          //Plot has no owner so it's the town selling it
          TownyMessaging.sendMsg(player, String.format("6) %s", worldCoord.toString()));
          if (townBlock.getPlotPrice() == -1)
              throw new TownyException(TownySettings.getLangString("msg_err_plot_nfs"));
          TownyMessaging.sendMsg(player, String.format("7) %s", worldCoord.toString()));
          if (TownySettings.isUsingEconomy() && !resident.payTo(townBlock.getPlotPrice(), town, "Plot - Buy From Town"))
              throw new TownyException(TownySettings.getLangString("msg_no_money_purchase_plot"));
          TownyMessaging.sendMsg(player, String.format("8) %s", worldCoord.toString()));
          townBlock.setPlotPrice(-1);
          townBlock.setResident(resident);
         
          // Set the plot permissions to mirror the new owners.
          townBlock.setType(townBlock.getType());
          TownyUniverse.getDataSource().saveTownBlock(townBlock);
          TownyMessaging.sendMsg(player, String.format("9) %s", worldCoord.toString()));
          return true;
        }
      } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_err_not_part_town"));
      }
    }
  }
View Full Code Here

     
      plugin.updateCache();
           

    } catch (NotRegisteredException e) {
        throw new TownyException(TownySettings.getLangString("msg_not_own_place"));
    }
   
    return true;
  }
View Full Code Here

         * @param coord
         * @throws TownyException
         */
        public void showTownStatusAtCoord(Player player, TownyWorld world, Coord coord) throws TownyException {
                if (!world.hasTownBlock(coord))
                        throw new TownyException(String.format(TownySettings.getLangString("msg_not_claimed"), coord));

                Town town = world.getTownBlock(coord).getTown();
                TownyMessaging.sendMessage(player, TownyFormatter.getStatus(town));
        }
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

         
          //Make sure we are allowed to set these permissions.
         
          if (split.contains("mobs")) {
            if (town.getWorld().isForceTownMobs())
                    throw new TownyException(TownySettings.getLangString("msg_world_mobs"));
            if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_MOBS.getNode())))
              throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
          }
         
          if (split.contains("fire")) {
            if (town.getWorld().isForceFire())
              throw new TownyException(TownySettings.getLangString("msg_world_fire"));
            if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_FIRE.getNode())))
              throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
          }
         
          if (split.contains("explosion")) {
            if (town.getWorld().isForceExpl())
              throw new TownyException(TownySettings.getLangString("msg_world_expl"));
            if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_EXPLOSION.getNode())))
              throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
          }
         
          if (split.contains("pvp")) {
            if (town.getWorld().isForcePVP())
              throw new TownyException(TownySettings.getLangString("msg_world_pvp"));
            if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOGGLE_PVP.getNode())))
              throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
          }
        }
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;
                        }

                        // TODO: Let admin's call a subfunction of this.
                        if (split[0].equalsIgnoreCase("board")) {
                                if (split.length < 2) {
                                        TownyMessaging.sendErrorMsg(player, "Eg: /town set board " + TownySettings.getLangString("town_help_9"));
                                        return;
                                } else {
                                        String line = split[1];
                                        for (int i = 2; i < split.length; i++)
                                                line += " " + split[i];
                                        town.setTownBoard(line);
                                        TownyMessaging.sendTownBoard(player, town);
                                }
                        } else if (split[0].equalsIgnoreCase("mayor")) {
                                if (split.length < 2) {
                                        TownyMessaging.sendErrorMsg(player, "Eg: /town set mayor Dumbo");
                                        return;
                                } else
                                        try {
                                                if (!resident.isMayor())
                                                        throw new TownyException(TownySettings.getLangString("msg_not_mayor"));
                                               
                                                String oldMayor = town.getMayor().getName();
                                                Resident newMayor = TownyUniverse.getDataSource().getResident(split[1]);
                                                town.setMayor(newMayor);
                                                plugin.deleteCache(oldMayor);
                                                plugin.deleteCache(newMayor.getName());
                                                TownyMessaging.sendTownMessage(town, TownySettings.getNewMayorMsg(newMayor.getName()));
                                        } catch (TownyException e) {
                                                TownyMessaging.sendErrorMsg(player, e.getMessage());
                                                return;
                                        }
                        } else if (split[0].equalsIgnoreCase("taxes")) {
                                if (split.length < 2) {
                                        TownyMessaging.sendErrorMsg(player, "Eg: /town set taxes 7");
                                        return;
                                } else {
                    try {
                        Double amount = Double.parseDouble(split[1]);
                        if (amount < 0) {
                            TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
                            return;
                        }
                        if(town.isTaxPercentage() && amount > 100)
                        {
                            TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_percentage"));
                            return;
                        }
                                                town.setTaxes(amount);
                                                TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_town_set_tax"), player.getName(), split[1]));
                                        } catch (NumberFormatException e) {
                                                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_num"));
                                                return;
                                        }
                                }
                        } else if (split[0].equalsIgnoreCase("plottax")) {
                                if (split.length < 2) {
                                  TownyMessaging.sendErrorMsg(player, "Eg: /town set plottax 10");
                                    return;
                                } else {
                            try {
                                Double amount = Double.parseDouble(split[1]);
                                if (amount < 0) {
                                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
                                    return;
                                }
                                                town.setPlotTax(amount);
                                                TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_town_set_plottax"), player.getName(), split[1]));
                                        } catch (NumberFormatException e) {
                                                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_num"));
                                                return;
                                        }
                                }
                        } else if (split[0].equalsIgnoreCase("shoptax")) {
                                if (split.length < 2) {
                                        TownyMessaging.sendErrorMsg(player, "Eg: /town set shoptax 10");
                                        return;
                                } else {
                            try {
                                Double amount = Double.parseDouble(split[1]);
                                if (amount < 0) {
                                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
                                    return;
                                }
                                                town.setCommercialPlotTax(amount);
                                                TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_town_set_alttax"), player.getName(), "shop", split[1]));
                                        } catch (NumberFormatException e) {
                                                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_num"));
                                                return;
                                        }
                                }
                        } else if (split[0].equalsIgnoreCase("embassytax")) {
                            if (split.length < 2) {
                                TownyMessaging.sendErrorMsg(player, "Eg: /town set embassytax 10");
                                return;
                          } else {
                          try {
                              Double amount = Double.parseDouble(split[1]);
                              if (amount < 0) {
                                  TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
                                  return;
                              }
                                          town.setEmbassyPlotTax(amount);
                                          TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_town_set_alttax"), player.getName(), "embassy", split[1]));
                                  } catch (NumberFormatException e) {
                                          TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_num"));
                                          return;
                                  }
                          }
                        } else if (split[0].equalsIgnoreCase("plotprice")) {
                                if (split.length < 2) {
                                        TownyMessaging.sendErrorMsg(player, "Eg: /town set plotprice 50");
                                        return;
                                } else {
                            try {
                                Double amount = Double.parseDouble(split[1]);
                                if (amount < 0) {
                                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
                                    return;
                                }
                                                town.setPlotPrice(amount);
                                                TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_town_set_plotprice"), player.getName(), split[1]));
                                        } catch (NumberFormatException e) {
                                                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_num"));
                                                return;
                                        }
                                }
                        } else if (split[0].equalsIgnoreCase("shopprice")) {
                                if (split.length < 2) {
                                        TownyMessaging.sendErrorMsg(player, "Eg: /town set shopprice 50");
                                        return;
                                } else {
                            try {
                                Double amount = Double.parseDouble(split[1]);
                                if (amount < 0) {
                                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
                                    return;
                                }
                                                town.setCommercialPlotPrice(amount);
                                                TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_town_set_altprice"), player.getName(), "shop", split[1]));
                                        } catch (NumberFormatException e) {
                                                TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_num"));
                                                return;
                                        }
                                }
                        } else if (split[0].equalsIgnoreCase("embassyprice")) {
                            if (split.length < 2) {
                                TownyMessaging.sendErrorMsg(player, "Eg: /town set embassyprice 50");
                                return;
                          } else {
                          try {
                              Double amount = Double.parseDouble(split[1]);
                              if (amount < 0) {
                                  TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_negative_money"));
                                  return;
                              }
                                          town.setEmbassyPlotPrice(amount);
                                          TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_town_set_altprice"), player.getName(), "embassy", split[1]));
                                  } catch (NumberFormatException e) {
                                          TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_error_must_be_num"));
                                          return;
                                  }
                          }
                        } else if (split[0].equalsIgnoreCase("name")) {
                                if (split.length < 2) {
                                        TownyMessaging.sendErrorMsg(player, "Eg: /town set name BillyBobTown");
                                        return;
                                } else
                                  if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_TOWN_RENAME.getNode()))) {
                                    TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_command_disable"));
                                    return;
                                  }
                                   
                                    //TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_town_rename_disabled"));
                                    if (TownySettings.isValidRegionName(split[1]))
                                        townRename(player, town, split[1]);
                                    else
                                        TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_invalid_name"));
                                   
                        } else if (split[0].equalsIgnoreCase("tag")) {
                          if (split.length < 2)
                                TownyMessaging.sendErrorMsg(player, "Eg: /town set tag PLTC");
                          else
                            if (split[1].equalsIgnoreCase("clear")) {
                              try {
                    town.setTag(" ");
                    TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_reset_town_tag"), player.getName()));
                  } catch (TownyException e) {
                    TownyMessaging.sendErrorMsg(player, e.getMessage());
                  }
                            } else
                                  try {
                                    town.setTag(plugin.getTownyUniverse().checkAndFilterName(split[1]));
                                    TownyMessaging.sendTownMessage(town, String.format(TownySettings.getLangString("msg_set_town_tag"), player.getName(), town.getTag()));
                                  } catch (TownyException e) {
                                    TownyMessaging.sendErrorMsg(player, e.getMessage());
                                  } catch (InvalidNameException e) {
                                    TownyMessaging.sendErrorMsg(player, e.getMessage());
                  }
                        } else if (split[0].equalsIgnoreCase("homeblock")) {
                                Coord coord = Coord.parseCoord(player);
                                TownBlock townBlock;
                                TownyWorld world;
                                try {
                                        if (plugin.getTownyUniverse().isWarTime())
                                                throw new TownyException(TownySettings.getLangString("msg_war_cannot_do"));
                                       
                    world = TownyUniverse.getDataSource().getWorld(player.getWorld().getName());
                                        if (world.getMinDistanceFromOtherTowns(coord, resident.getTown()) < TownySettings.getMinDistanceFromTownHomeblocks())
                                                throw new TownyException(TownySettings.getLangString("msg_too_close"));
                                       
                                        if (TownySettings.getMaxDistanceBetweenHomeblocks() > 0)
                                                if ((world.getMinDistanceFromOtherTowns(coord, resident.getTown()) > TownySettings.getMaxDistanceBetweenHomeblocks()) && world.hasTowns())
                                                        throw new TownyException(TownySettings.getLangString("msg_too_far"));
                                       
                    townBlock = TownyUniverse.getDataSource().getWorld(player.getWorld().getName()).getTownBlock(coord);
                    oldWorld = town.getWorld();
                                        town.setHomeBlock(townBlock);
                                        TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_set_town_home"), coord.toString()));
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.