Package com.palmergames.bukkit.towny.object

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


    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


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

        line = kvFile.get("friends");
        if (line != null) {
          String[] tokens = line.split(",");
          for (String token : tokens) {
            Resident friend = getResident(token);
            if (friend != null)
              resident.addFriend(friend);
          }
        }
View Full Code Here

        line = kvFile.get("residents");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Resident resident = getResident(token);
            if (resident != null)
              town.addResident(resident);
          }
        }

        line = kvFile.get("mayor");
        if (line != null)
          town.setMayor(getResident(line));

        line = kvFile.get("assistants");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Resident assistant = getResident(token);
            if (assistant != null)
              town.addAssistant(assistant);
          }
        }
View Full Code Here

        line = kvFile.get("assistants");
        if (line != null) {
          tokens = line.split(",");
          for (String token : tokens) {
            Resident assistant = getResident(token);
            if (assistant != null)
              nation.addAssistant(assistant);
          }
        }
View Full Code Here

  @Override
  public List<Resident> getResidents(Player player, String[] names) {
      List<Resident> invited = new ArrayList<Resident>();
      for (String name : names)
          try {
              Resident target = getResident(name);
              invited.add(target);
          } catch (TownyException x) {
              TownyMessaging.sendErrorMsg(player, x.getMessage());
          }
      return invited;
View Full Code Here

    return new ArrayList<Resident>(universe.getResidentMap().values());
  }
 
  @Override
  public Resident getResident(String name) throws NotRegisteredException {
    Resident resident = null;
    try {
      resident = universe.getResidentMap().get(universe.checkAndFilterName(name).toLowerCase());
    } catch (InvalidNameException e) {
    }
    if (resident == null)
View Full Code Here

    universe.setChangedNotify(REMOVE_RESIDENT);
  }

  @Override
  public void removeTownBlock(TownBlock townBlock) {
    Resident resident = null;
    Town town = null;
    try {
      resident = townBlock.getResident();
    } catch (NotRegisteredException e) {
    }
View Full Code Here

    }

    if (universe.getResidentMap().containsKey(filteredName.toLowerCase()))
      throw new AlreadyRegisteredException("A resident with the name " + filteredName + " is already in use.");

    universe.getResidentMap().put(filteredName.toLowerCase(), new Resident(filteredName));

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

    if (split.length < 2) {
      TownyMessaging.sendErrorMsg(player, "Eg: /nation ally [add/remove] [name]");
      return;
    }

    Resident resident;
    Nation nation;
    try {
      resident = TownyUniverse.getDataSource().getResident(player.getName());
      nation = resident.getTown().getNation();
      if (!resident.isKing())
        if (!nation.hasAssistant(resident))
          throw new TownyException(TownySettings.getLangString("msg_not_king_ass"));
    } catch (TownyException x) {
      TownyMessaging.sendErrorMsg(player, x.getMessage());
      return;
View Full Code Here

TOP

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

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.