Package com.palmergames.bukkit.towny.object

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


  public static boolean callAttackCellEvent(Towny plugin, Player player, Block block, WorldCoord worldCoord) throws TownyException {
    int topY = block.getWorld().getHighestBlockYAt(block.getX(), block.getZ()) - 1;
    if (block.getY() < topY)
      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
    universe.addWarZone(worldCoord);
    plugin.updateCache(worldCoord);
   
    TownyMessaging.sendGlobalMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_under_attack"), landOwnerTown.getFormattedName(), worldCoord.toString(), attackingResident.getFormattedName()));
    return true;
  }
View Full Code Here


    } else if (event.getEventName().equals("CellDefended")) {
      CellDefendedEvent cellDefendedEvent = (CellDefendedEvent)event;
      Player player = cellDefendedEvent.getPlayer();
      CellUnderAttack cell = cellDefendedEvent.getCell().getAttackData();
     
      TownyUniverse universe = plugin.getTownyUniverse();
      try {
        TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName());
        WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ());
        universe.removeWarZone(worldCoord);
       
        plugin.updateCache(worldCoord);
      } catch (NotRegisteredException e) {
        e.printStackTrace();
      }
     
      String playerName;
      if (player == null) {
        playerName = "Greater Forces";
      } else {
        playerName = player.getName();
        try {
          playerName = TownyUniverse.getDataSource().getResident(player.getName()).getFormattedName();
        } catch (TownyException e) {
        }
      }
     
      plugin.getServer().broadcastMessage(String.format(TownySettings.getLangString("msg_enemy_war_area_defended"),
          playerName,
          cell.getCellString()));
    } else if (event.getEventName().equals("CellWon")) {
      CellWonEvent cellWonEvent = (CellWonEvent)event;
      CellUnderAttack cell = cellWonEvent.getCellAttackData();
     
      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")) {
      System.out.println("CellAttackCanceled");
      CellAttackCanceledEvent cancelCellAttackerEvent = (CellAttackCanceledEvent)event;
      CellUnderAttack cell = cancelCellAttackerEvent.getCell();
     
      TownyUniverse universe = plugin.getTownyUniverse();
      try {
        TownyWorld world = TownyUniverse.getDataSource().getWorld(cell.getWorldName());
        WorldCoord worldCoord = new WorldCoord(world, cell.getX(), cell.getZ());
        universe.removeWarZone(worldCoord);
        plugin.updateCache(worldCoord);
      } catch (NotRegisteredException e) {
        e.printStackTrace();
      }
      System.out.println(cell.getCellString());
View Full Code Here

   *
   * @param player
   */

  public void newNation(Player player, String name, String capitalName) {
    TownyUniverse universe = plugin.getTownyUniverse();
    try {
      if (!TownyUniverse.getPermissionSource().isTownyAdmin(player) && ((TownySettings.isNationCreationAdminOnly() && !plugin.isPermissions())
        || (plugin.isPermissions() && !TownyUniverse.getPermissionSource().hasPermission(player, PermissionNodes.TOWNY_NATION_NEW.getNode()))))
        throw new TownyException(TownySettings.getNotPermToNewNationLine());

View Full Code Here

  public void onEnable() {

    System.out.println("====================      Towny      ========================");

    version = this.getDescription().getVersion();
    townyUniverse = new TownyUniverse(this);

    if (load()) {
      // Setup bukkit command interfaces
      getCommand("townyadmin").setExecutor(new TownyAdminCommand(this));
      getCommand("townyworld").setExecutor(new TownyWorldCommand(this));
View Full Code Here

    }

    if (attacker != null) {
      //plugin.sendMsg("Attacker not null");

      TownyUniverse universe = plugin.getTownyUniverse();
      try {
        TownyWorld world = TownyUniverse.getDataSource().getWorld(defender.getWorld().getName());

        // Wartime
        if (universe.isWarTime()) {
          event.setCancelled(false);
          throw new Exception();
        }

        Player a = null;
View Full Code Here

    //plugin.sendDebugMsg("world is pvp");
    return false;
  }

  public boolean preventFriendlyFire(Player a, Player b) {
    TownyUniverse universe = plugin.getTownyUniverse();
    if (!TownySettings.getFriendlyFire() && universe.isAlly(a.getName(), b.getName())) {
      try {
        TownyWorld world = TownyUniverse.getDataSource().getWorld(b.getWorld().getName());
        TownBlock townBlock = new WorldCoord(world, Coord.parseCoord(b)).getTownBlock();
        if (!townBlock.getType().equals(TownBlockType.ARENA))
          return true;
View Full Code Here

         *
         * @param player
         */

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

TOP

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

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.