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