Package com.palmergames.bukkit.towny.object

Examples of com.palmergames.bukkit.towny.object.Town


  public void nationDelete(Player player, String[] split) {
    if (split.length == 0)
      try {
        Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
        Town town = resident.getTown();
        Nation nation = town.getNation();

        if (!resident.isKing())
          throw new TownyException(TownySettings.getLangString("msg_not_king"));
        if (plugin.isPermissions() && (!TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_NATION_DELETE.getNode())))
          throw new TownyException(TownySettings.getLangString("msg_err_command_disable"));
View Full Code Here


      } else if (split[0].equalsIgnoreCase("capital")) {
        if (split.length < 2)
          TownyMessaging.sendErrorMsg(player, "Eg: /nation set capital {town name}");
        else
          try {
            Town newCapital = TownyUniverse.getDataSource().getTown(split[1]);
            nation.setCapital(newCapital);
            plugin.updateCache();
            TownyMessaging.sendNationMessage(nation, TownySettings.getNewKingMsg(newCapital.getMayor().getName(), nation.getName()));
          } catch (TownyException e) {
            TownyMessaging.sendErrorMsg(player, e.getMessage());
          }
      } else if (split[0].equalsIgnoreCase("taxes")) {
        if (split.length < 2)
View Full Code Here

                        if (split.length > 1 && split[1].equalsIgnoreCase("big"))
                                TownyAsciiMap.generateAndSend(plugin, player, 18);
                        else
                                showMap(player);
                else if (split[0].equalsIgnoreCase("prices")){
                        Town town = null;
                        if (split.length > 1){
                                try {
                                        town = TownyUniverse.getDataSource().getTown(split[1]);
                                } catch (NotRegisteredException x) {
                                        sendErrorMsg(player, x.getMessage());
View Full Code Here

    if (attackerPlayer != null && plugin.getTownyUniverse().isWarTime())
      try {
        if (attackerResident == null)
          throw new NotRegisteredException();

        Town town = attackerResident.getTown();
        if (TownySettings.getWarPointsForKill() > 0)
          plugin.getTownyUniverse().getWarEvent().townScored(town, TownySettings.getWarPointsForKill());
      } catch (NotRegisteredException e) {
      }
  }
View Full Code Here

          TownyMessaging.sendMsg(defenderPlayer, attackerResident.getName() + " robbed you of " + TownyEconomyObject.getFormattedBalance(price) + ".");
        }

        // Resident doesn't have enough funds.
        if (townPrice > 0) {
          Town town = defenderResident.getTown();
          if (!town.canPayFromHoldings(townPrice)) {
            // Town doesn't have enough funds.
            townPrice = town.getHoldingBalance();
            try {
              plugin.getTownyUniverse().getWarEvent().remove(attackerResident.getTown(), town);
            } catch (NotRegisteredException e) {
              plugin.getTownyUniverse().getWarEvent().remove(town);
            }
          } else
            TownyMessaging.sendTownMessage(town, defenderResident.getName() + "'s wallet couldn't satisfy " + attackerResident.getName() + ". " + townPrice + " taken from town bank.");
          town.payTo(townPrice, attackerResident, String.format("Death Payment (War) (%s couldn't pay)", defenderResident.getName()));
        }
      } catch (NotRegisteredException e) {
      } catch (EconomyException e) {
        TownyMessaging.sendErrorMsg(attackerPlayer, "Could not take wartime death funds.");
        TownyMessaging.sendErrorMsg(defenderPlayer, "Could not take wartime death funds.");
View Full Code Here

        line = kvFile.get("towns");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Town town = getTown(token);
              if (town != null)
                nation.addTown(town);
            }
          }
        }
View Full Code Here

        line = kvFile.get("towns");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            if (!token.isEmpty()){
              Town town = getTown(token);
              if (town != null) {
                town.setWorld(world);
                //world.addTown(town); not needed as it's handled in the Town object
              }
            }
          }
        }
View Full Code Here

                return warringTowns.containsAll(nation.getTowns());
        }
       
        public void remove(WorldCoord worldCoord) {
                try {
                        Town town = worldCoord.getTownBlock().getTown();
                        TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeLoseTownBlockMsg(worldCoord, town.getName()));
                        warZone.remove(worldCoord);
                } catch (NotRegisteredException e) {
                  TownyMessaging.sendGlobalMessage(TownySettings.getWarTimeLoseTownBlockMsg(worldCoord));
                        warZone.remove(worldCoord);
                }
View Full Code Here

                int n = 0;
                for (KeyValue<Town,Integer> kv : kvTable.getKeyValues()) {
                        n++;
                        if (maxListing != -1 && n > maxListing)
                                break;
                        Town town = (Town)kv.key;
                        output.add(String.format(
                                        Colors.Blue + "%40s "+Colors.Gold+"|"+Colors.LightGray+" %4d",
                                        TownyFormatter.getFormattedName(town),
                                        (Integer)kv.value));
                }
View Full Code Here

                        //player.sendMessage(ChatTools.formatCommand("", "/town set", "public [on/off]", ""));
                        //player.sendMessage(ChatTools.formatCommand("", "/town set", "explosion [on/off]", ""));
                        //player.sendMessage(ChatTools.formatCommand("", "/town set", "fire [on/off]", ""));
                } else {
                        Resident resident;
                        Town town;
                        TownyWorld oldWorld = null;
                       
                        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()));
                                } catch (TownyException e) {
                                        TownyMessaging.sendErrorMsg(player, e.getMessage());
                                        return;
                                }
                        } else if (split[0].equalsIgnoreCase("spawn"))
                                try {
                                        town.setSpawn(player.getLocation());
                                        TownyMessaging.sendMsg(player, TownySettings.getLangString("msg_set_town_spawn"));
                                } catch (TownyException e) {
                                        TownyMessaging.sendErrorMsg(player, e.getMessage());
                                        return;
                                }
                        else if (split[0].equalsIgnoreCase("perm")) {
                          //Make sure we are allowed to set these permissions.
                          try {
                            toggleTest(player,town,StringMgmt.join(split, " "));
                          } catch (Exception e) {
                                TownyMessaging.sendErrorMsg(player, e.getMessage());
                                return;
                            }
                                String[] newSplit = StringMgmt.remFirstArg(split);
                                setTownBlockOwnerPermissions(player, town, newSplit);
                                plugin.updateCache();
                        } else {
                                TownyMessaging.sendErrorMsg(player, String.format(TownySettings.getLangString("msg_err_invalid_property"), "town"));
                                return;
                        }

            TownyUniverse.getDataSource().saveTown(town);
           
            // If the town (homeblock) has moved worlds we need to update the world files.
            if (oldWorld != null) {
              TownyUniverse.getDataSource().saveWorld(town.getWorld());
              TownyUniverse.getDataSource().saveWorld(oldWorld);
            }
                }
        }
View Full Code Here

TOP

Related Classes of com.palmergames.bukkit.towny.object.Town

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.