Package com.palmergames.bukkit.towny.object

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


                  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"));
                        }
View Full Code Here


      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
    if (!landOwnerNation.hasEnemy(attackingNation)) {
      landOwnerNation.addEnemy(attackingNation);
      plugin.getTownyUniverse();
      TownyUniverse.getDataSource().saveNation(landOwnerNation);
    }
   
    // Update Cache
View Full Code Here

     
      TownyUniverse universe = plugin.getTownyUniverse();
      try {
        Resident resident = TownyUniverse.getDataSource().getResident(cell.getNameOfFlagOwner());
        Town town = resident.getTown();
        Nation nation = town.getNation();
       
        TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName());
        WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ());
        universe.removeWarZone(worldCoord);
       
        TownBlock townBlock = worldCoord.getTownBlock();
        TownyUniverse.getDataSource().removeTownBlock(townBlock);
       
        try {
          List<WorldCoord> selection = new ArrayList<WorldCoord>();
          selection.add(worldCoord);
          TownCommand.checkIfSelectionIsValid(town, selection, false, 0, false);
          new TownClaim(plugin, null, town, selection, true, false).start();
         
          //TownCommand.townClaim(town, worldCoord);
          //TownyUniverse.getDataSource().saveTown(town);
          //TownyUniverse.getDataSource().saveWorld(world);
         
          //TODO
          //PlotCommand.plotClaim(resident, worldCoord);
          //TownyUniverse.getDataSource().saveResident(resident);
          //TownyUniverse.getDataSource().saveWorld(world);
        } catch (TownyException te) {
          // Couldn't claim it.
        }
       
        plugin.updateCache(worldCoord);
       
        TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_won"),
            resident.getFormattedName(),
            (nation.hasTag() ? nation.getTag() : nation.getFormattedName()),
            cell.getCellString()));
      } catch (NotRegisteredException e) {
        e.printStackTrace();
      }
    } else if (event.getEventName().equals("CellAttackCanceled")) {
View Full Code Here

        line = kvFile.get("allies");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Nation friend = getNation(token);
            if (friend != null)
              nation.setAliegeance("ally", friend);
          }
        }

        line = kvFile.get("enemies");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Nation enemy = getNation(token);
            if (enemy != null)
              nation.setAliegeance("enemy", enemy);
          }
        }
View Full Code Here

    return new ArrayList<Nation>(universe.getNationsMap().values());
  }

  @Override
  public Nation getNation(String name) throws NotRegisteredException {
    Nation nation = universe.getNationsMap().get(name.toLowerCase());
    if (nation == null)
      throw new NotRegisteredException(String.format("The nation '%s' is not registered.", name));
    return nation;
  }
View Full Code Here

    }

    if (universe.getNationsMap().containsKey(filteredName.toLowerCase()))
      throw new AlreadyRegisteredException("The nation " + filteredName + " is already in use.");

    universe.getNationsMap().put(filteredName.toLowerCase(), new Nation(filteredName));

    universe.setChangedNotify(NEW_NATION);
  }
View Full Code Here

    List<Resident> toSave = new ArrayList<Resident>(town.getResidents());
    TownyWorld world = town.getWorld();

    try {
      if (town.hasNation()) {
        Nation nation = town.getNation();
        nation.removeTown(town);

        saveNation(nation);
      }
      town.clear();
    } catch (EmptyNationException e) {
View Full Code Here

    universe.getTownsMap().put(filteredName.toLowerCase(), town);

    //Check if this is a nation capitol
    if (town.isCapital()) {
      Nation nation = town.getNation();
      nation.setCapital(town);
      saveNation(nation);
    }

    Town oldTown = new Town(oldName);
View Full Code Here

    //Tidy up old files
    deleteNation(nation);

    universe.getNationsMap().remove(oldName.toLowerCase());
    nation.setName(filteredName);
    Nation oldNation = new Nation(oldName);

    if (plugin.isEcoActive())
      try {
        nation.pay(nation.getHoldingBalance(), "Rename Nation - Empty account of new nation name.");
        oldNation.payTo(oldNation.getHoldingBalance(), nation, "Rename Nation - Transfer to new account");
      } catch (EconomyException e) {
      }

    for (Town town : toSave) {
      saveTown(town);
View Full Code Here

         */
       
        //TODO: Proceduralize and make parse function for /towny prices [town]
        public List<String> getTownyPrices(Town town) {
                List<String> output = new ArrayList<String>();
                Nation nation = null;
               
                if (town != null)
                        if (town.hasNation())
                                try {
                                        nation = town.getNation();
                                } catch (NotRegisteredException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                }

               
                output.add(ChatTools.formatTitle("Prices"));
                output.add(Colors.Yellow + "[New] "
                                + Colors.Green + "Town: " + Colors.LightGreen + TownyFormatter.formatMoney(TownySettings.getNewTownPrice())
                                + Colors.Gray + " | "
                                + Colors.Green + "Nation: " + Colors.LightGreen + TownyFormatter.formatMoney(TownySettings.getNewNationPrice()));
                output.add(Colors.Yellow + "[Upkeep] "
                                + Colors.Green + "Town: " + Colors.LightGreen + TownyFormatter.formatMoney(TownySettings.getTownUpkeepCost(town))
                                + Colors.Gray + " | "
                                + Colors.Green + "Nation: " + Colors.LightGreen + TownyFormatter.formatMoney(TownySettings.getNationUpkeepCost(nation)));
                output.add(Colors.Gray + "Town upkeep is based on " + Colors.LightGreen + " the " + (TownySettings.isUpkeepByPlot() ? " number of plots" : " town level (num residents)."));
               
                if (town != null) {
                        output.add(Colors.Yellow + "Town [" + TownyFormatter.getFormattedName(town)+"]");
                        output.add(Colors.Rose + "    [Price] "
                                        + Colors.Green + "Plot: " + Colors.LightGreen + Double.toString(town.getPlotPrice())
                                        + Colors.Gray + " | "
                                        + Colors.Green + "Outpost: " + Colors.LightGreen + TownyFormatter.formatMoney(TownySettings.getOutpostCost()));
                        output.add(Colors.Rose + "    [Upkeep] "
                                        + Colors.Green + "Resident: " + Colors.LightGreen + Double.toString(town.getTaxes())
                                        + Colors.Gray + " | "
                                        + Colors.Green + "Plot: " + Colors.LightGreen + Double.toString(town.getPlotTax()));
                       
                       
                        if (nation != null) {
                                output.add(Colors.Yellow + "Nation [" + TownyFormatter.getFormattedName(nation)+"]");
                                output.add(Colors.Rose + "    [Upkeep] "
                                        + Colors.Green + "Town: " + Colors.LightGreen + Double.toString(nation.getTaxes())
                                        + Colors.Gray + " | "
                                        + Colors.Green + "Neutrality: " + Colors.LightGreen + TownyFormatter.formatMoney(TownySettings.getNationNeutralityCost()));
                        }
                }
                return output;
View Full Code Here

TOP

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

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.