Package com.palmergames.bukkit.towny.object

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


                  // Temp placeholder.
                  player.sendMessage("Nothing for sale right now.");
                }
            } else {
                Resident resident;
                Town town;
                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


        }
       
        public Town newTown(TownyUniverse universe, TownyWorld world, String name, Resident resident, Coord key, Location spawn) throws TownyException {
                world.newTownBlock(key);
                TownyUniverse.getDataSource().newTown(name);
                Town town = TownyUniverse.getDataSource().getTown(name);
                town.addResident(resident);
                town.setMayor(resident);
                TownBlock townBlock = world.getTownBlock(key);
                townBlock.setTown(town);
                town.setHomeBlock(townBlock);
                town.setSpawn(spawn);
                //world.addTown(town);
               
                if (world.isUsingPlotManagementRevert()) {
                  PlotBlockData plotChunk = TownyRegenAPI.getPlotChunk(townBlock);
                if (plotChunk != null) {
                  TownyRegenAPI.deletePlotChunk(plotChunk); // just claimed so stop regeneration.
                } else {
                  plotChunk = new PlotBlockData(townBlock); // Not regenerating so create a new snapshot.
                  plotChunk.initialize();
                }
                TownyRegenAPI.addPlotChunkSnapshot(plotChunk); // Save a snapshot.
                plotChunk = null;
                }
                TownyMessaging.sendDebugMsg("Creating new Town account: " + "town-"+name);
                if(TownySettings.isUsingEconomy())
                {
                        town.setBalance(0);
                }
               
                TownyUniverse.getDataSource().saveResident(resident);
                TownyUniverse.getDataSource().saveTown(town);
                TownyUniverse.getDataSource().saveWorld(world);
View Full Code Here

                }
        }
       
        public void townLeave(Player player) {
                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());
                       
                       
                } catch (TownyException x) {
                        TownyMessaging.sendErrorMsg(player, x.getMessage());
                        return;
                }
               
                if (resident.isMayor()) {
                        TownyMessaging.sendErrorMsg(player, TownySettings.getMayorAbondonMsg());
                        return;
                }
               
                try {
                        town.removeResident(resident);
                } catch (EmptyTownException et) {
                  TownyUniverse.getDataSource().removeTown(et.getTown());

                } catch (NotRegisteredException x) {
                        TownyMessaging.sendErrorMsg(player, x.getMessage());
View Full Code Here

       
        public static void townSpawn(Player player, String[] split) {
          try {
                boolean isTownyAdmin = TownyUniverse.getPermissionSource().isTownyAdmin(player);
                Resident resident = TownyUniverse.getDataSource().getResident(player.getName());
                Town town;
                String notAffordMSG;
                TownSpawnLevel townSpawnPermission;
               
                // Set target town and affiliated messages.
                if (split.length == 0) {
                  town = resident.getTown();
                    notAffordMSG = TownySettings.getLangString("msg_err_cant_afford_tp");
              } else {
                // split.length > 1
                town = TownyUniverse.getDataSource().getTown(split[0]);
                  notAffordMSG = String.format(TownySettings.getLangString("msg_err_cant_afford_tp_town"), town.getName());
              }
               
                // Determine conditions
                if (isTownyAdmin) {
                  townSpawnPermission = TownSpawnLevel.ADMIN;
                } else if (split.length == 0) {
                  townSpawnPermission = TownSpawnLevel.TOWN_RESIDENT;
                } else {
                  // split.length > 1
                  if (!resident.hasTown()) {
                    townSpawnPermission = TownSpawnLevel.UNAFFILIATED;
                  } else if (resident.getTown() == town) {
                    townSpawnPermission = TownSpawnLevel.TOWN_RESIDENT;
                  } else if (resident.hasNation() && town.hasNation()) {
                    Nation playerNation = resident.getTown().getNation();
                    Nation targetNation = town.getNation();
                   
                    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
                boolean UsingESS = plugin.isEssentials();
               
                if (UsingESS && !isTownyAdmin) {
                        try {
                            User user = plugin.getEssentials().getUser(player);
                           
                            if (!user.isJailed()) {
                             
                                Teleport teleport = user.getTeleport();
                                if (!chunk.isLoaded()) chunk.load();
                                // Cause an essentials exception if in cooldown.
                                teleport.cooldown(true);
                                teleport.teleport(town.getSpawn(),null);
                            }
                        } catch (Exception e) {
                            TownyMessaging.sendErrorMsg(player, "Error: " + e.getMessage());
                            // cooldown?
                            return;
                        }
                }
               
                // Show message if we are using iConomy and are charging for spawn travel.
                if (travelCost > 0 && TownySettings.isUsingEconomy() && resident.payTo(travelCost, town, String.format("Town Spawn (%s)", townSpawnPermission))) {
                  TownyMessaging.sendMsg(player, String.format(TownySettings.getLangString("msg_cost_spawn"),
                        TownyEconomyObject.getFormattedBalance(travelCost))); // + TownyEconomyObject.getEconomyCurrency()));
                }
               
               
                // If an Admin or Essentials teleport isn't being used, use our own.
                if(isTownyAdmin) {
                  if (player.getVehicle() != null)
                    player.getVehicle().eject();
                  if (!chunk.isLoaded()) chunk.load();
                    player.teleport(town.getSpawn());
                    return;
                }
               
                if (!UsingESS) {
                    if (plugin.getTownyUniverse().isTeleportWarmupRunning()) {
                      // Use teleport warmup
                        player.sendMessage(String.format(TownySettings.getLangString("msg_town_spawn_warmup"),
                                TownySettings.getTeleportWarmupTime()));
                        plugin.getTownyUniverse().requestTeleport(player, town, travelCost);
                    } else {
                      // Don't use teleport warmup
                      if (player.getVehicle() != null)
                        player.getVehicle().eject();
                      if (!chunk.isLoaded()) chunk.load();
                        player.teleport(town.getSpawn());
                    }
                }
            } catch (TownyException e) {
                TownyMessaging.sendErrorMsg(player, e.getMessage());
            } catch (EconomyException e) {
View Full Code Here

       
        public void townDelete(Player player, String[] split) {
                if (split.length == 0)
                        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());
                                return;
View Full Code Here

         * @param names
         */

        public static void townKick(Player player, String[] names) {
                Resident resident;
                Town town;
                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

         * @param names
         */

        public void townAssistantsAdd(Player player, String[] names) {
                Resident resident;
                Town town;
                try {
                        resident = TownyUniverse.getDataSource().getResident(player.getName());
                        town = resident.getTown();
                        if (!resident.isMayor())
                                throw new TownyException(TownySettings.getLangString("msg_not_mayor"));
View Full Code Here

         * @param names
         */

        public void townAssistantsRemove(Player player, String[] names) {
                Resident resident;
                Town town;
                try {
                        resident = TownyUniverse.getDataSource().getResident(player.getName());
                        town = resident.getTown();
                        if (!resident.isMayor())
                                throw new TownyException(TownySettings.getLangString("msg_not_mayor"));
View Full Code Here

         * @param args
         */
        public static void parseTownJoin(CommandSender sender, String[] args) {
          try {
            Resident resident;
            Town town;
            String residentName, townName, contextualResidentName;
            boolean console = false;
           
            if (sender instanceof Player) {
              // Player
              if (args.length < 1)
                throw new Exception(String.format("Usage: /town join [town]"));
             
              Player player = (Player)sender;
              residentName = player.getName();
              townName = args[0];
              contextualResidentName = "You";
            } else {
              // Console
              if (args.length < 2)
                throw new Exception(String.format("Usage: town join [resident] [town]"));
             
              residentName = args[0];
              townName = args[1];
              contextualResidentName = residentName;
            }
           
            resident = TownyUniverse.getDataSource().getResident(residentName);
            town = TownyUniverse.getDataSource().getTown(townName);
           
            // Check if resident is currently in a town.
            if (resident.hasTown())
              throw new Exception(String.format(TownySettings.getLangString("msg_err_already_res"), contextualResidentName));
           
            if (!console) {
              // Check if town is town is free to join.
              if (!town.isOpen())
                throw new Exception(String.format(TownySettings.getLangString("msg_err_not_open"), town.getFormattedName()));
            }
           
            townJoin(town, resident);
         
          } catch (Exception e) {
View Full Code Here

            name = ((Player)sender).getName();
          } else {
            name = "Console";
          }
                Resident resident;
                Town town;
                try {
                  if (name.equalsIgnoreCase("Console")) {
                    town = specifiedTown;
                  } else {
                        resident = TownyUniverse.getDataSource().getResident(name);
                        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());
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.