use of com.gmail.goosius.siegewar.events.PreSiegeCampEvent in project SiegeWar by TownyAdvanced.
the class StartConquestSiege method processStartSiegeRequest.
/**
* Process a start conquest siege request.
*
* At this point we know that the resident has a nation and the town is not occupied
*
* This method does some final checks and if they pass, the siege is initiated.
*
* @param player the player
* @param townOfSiegeStarter town
* @param nationOfSiegeStarter nation which is attacking.
* @param townBlock the townblock where the attack is taking place.
* @param targetTown the town about to be attacked
* @param bannerBlock the banner block
*
* @throws TownyException when attack cannot be made.
*/
public static void processStartSiegeRequest(Player player, Town townOfSiegeStarter, Nation nationOfSiegeStarter, TownBlock townBlock, Town targetTown, Block bannerBlock) throws TownyException {
final Translator translator = Translator.locale(Translation.getLocale(player));
if (!SiegeWarSettings.getConquestSiegesEnabled())
throw new TownyException(translator.of("msg_err_action_disable"));
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, SiegeWarPermissionNodes.getPermissionNodeToStartSiege(SiegeType.CONQUEST)))
throw new TownyException(translator.of("msg_err_action_disable"));
if (targetTown.hasNation()) {
Nation nationOfDefendingTown = targetTown.getNation();
if (nationOfSiegeStarter == nationOfDefendingTown)
throw new TownyException(translator.of("msg_err_siege_war_cannot_attack_town_in_own_nation"));
if (!nationOfSiegeStarter.hasEnemy(nationOfDefendingTown))
throw new TownyException(translator.of("msg_err_siege_war_cannot_attack_non_enemy_nation"));
}
if (TownySettings.getNationRequiresProximity() > 0) {
Coord capitalCoord = nationOfSiegeStarter.getCapital().getHomeBlock().getCoord();
Coord townCoord = targetTown.getHomeBlock().getCoord();
if (!nationOfSiegeStarter.getCapital().getHomeBlock().getWorld().getName().equals(targetTown.getHomeBlock().getWorld().getName())) {
throw new TownyException(translator.of("msg_err_nation_homeblock_in_another_world"));
}
double distance;
distance = Math.sqrt(Math.pow(capitalCoord.getX() - townCoord.getX(), 2) + Math.pow(capitalCoord.getZ() - townCoord.getZ(), 2));
if (distance > TownySettings.getNationRequiresProximity()) {
throw new TownyException(translator.of("msg_err_siege_war_town_not_close_enough_to_nation"));
}
}
SiegeCamp camp = new SiegeCamp(player, bannerBlock, SiegeType.CONQUEST, targetTown, nationOfSiegeStarter, targetTown, townOfSiegeStarter, townBlock);
PreSiegeCampEvent event = new PreSiegeCampEvent(camp);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
throw new TownyException(event.getCancellationMsg());
if (SiegeWarSettings.areSiegeCampsEnabled())
// Launch a SiegeCamp, a (by default) 10 minute minigame. If successful the Siege will be initiated in ernest.
SiegeController.beginSiegeCamp(camp);
else
// SiegeCamps are disabled, just do the Siege.
camp.startSiege();
}
use of com.gmail.goosius.siegewar.events.PreSiegeCampEvent in project SiegeWar by TownyAdvanced.
the class StartLiberationSiege method processStartSiegeRequest.
/**
* Process a start liberation siege request.
* <p>
* At this point we know that
* - the resident has a nation
* - the town is occupied,
* - the player's nation is not the occupier.
* <p>
* This method does some final checks and if they pass, the siege is initiated.
*
* @param player the player
* @param townOfSiegeStarter town
* @param nationOfSiegeStarter nation which is attacking.
* @param townBlock the townblock where the attack is taking place.
* @param targetTown the town about to be attacked
* @param bannerBlock the banner block
* @throws TownyException when attack cannot be made.
*/
public static void processStartSiegeRequest(Player player, Town townOfSiegeStarter, Nation nationOfSiegeStarter, TownBlock townBlock, Town targetTown, Block bannerBlock) throws TownyException {
final Translator translator = Translator.locale(Translation.getLocale(player));
if (!SiegeWarSettings.getLiberationSiegesEnabled())
throw new TownyException(translator.of("msg_err_action_disable"));
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, SiegeWarPermissionNodes.getPermissionNodeToStartSiege(SiegeType.LIBERATION)))
throw new TownyException(translator.of("msg_err_action_disable"));
Nation occupierNation = TownOccupationController.getTownOccupier(targetTown);
if (!nationOfSiegeStarter.hasEnemy(occupierNation))
throw new TownyException(translator.of("msg_err_siege_war_cannot_attack_occupied_town_non_enemy_nation"));
Nation naturalNationOfTown = targetTown.getNationOrNull();
if (naturalNationOfTown != null && !naturalNationOfTown.hasMutualAlly(nationOfSiegeStarter))
throw new TownyException(translator.of("msg_err_siege_war_cannot_start_liberation_siege_at_unallied_town"));
if (TownySettings.getNationRequiresProximity() > 0) {
Coord capitalCoord = nationOfSiegeStarter.getCapital().getHomeBlock().getCoord();
Coord townCoord = targetTown.getHomeBlock().getCoord();
if (!nationOfSiegeStarter.getCapital().getHomeBlock().getWorld().getName().equals(targetTown.getHomeBlock().getWorld().getName())) {
throw new TownyException(translator.of("msg_err_nation_homeblock_in_another_world"));
}
double distance;
distance = Math.sqrt(Math.pow(capitalCoord.getX() - townCoord.getX(), 2) + Math.pow(capitalCoord.getZ() - townCoord.getZ(), 2));
if (distance > TownySettings.getNationRequiresProximity()) {
throw new TownyException(translator.of("msg_err_siege_war_town_not_close_enough_to_nation"));
}
}
SiegeCamp camp = new SiegeCamp(player, bannerBlock, SiegeType.LIBERATION, targetTown, nationOfSiegeStarter, occupierNation, townOfSiegeStarter, townBlock);
PreSiegeCampEvent event = new PreSiegeCampEvent(camp);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
throw new TownyException(event.getCancellationMsg());
if (SiegeWarSettings.areSiegeCampsEnabled())
// Launch a SiegeCamp, a (by default) 10 minute minigame. If successful the Siege will be initiated in ernest.
SiegeController.beginSiegeCamp(camp);
else
// SiegeCamps are disabled, just do the Siege.
camp.startSiege();
}
use of com.gmail.goosius.siegewar.events.PreSiegeCampEvent in project SiegeWar by TownyAdvanced.
the class StartRevoltSiege method processStartSiegeRequest.
/**
* Process a start revolt siege request.
*
* At this point we know that
* - the player has a town
* - the target town is the resident's town,
*
* This method does some final checks and if they pass, the siege is initiated.
*
* @param player the player
* @param townOfSiegeStarter town
* @param nationOfSiegeStarter nation which is attacking.
* @param townBlock the townblock where the attack is taking place.
* @param targetTown the town about to be attacked
* @param bannerBlock the banner block
* @throws TownyException when attack cannot be made.
*/
public static void processStartSiegeRequest(Player player, Town townOfSiegeStarter, Nation nationOfSiegeStarter, TownBlock townBlock, Town targetTown, Block bannerBlock) throws TownyException {
final Translator translator = Translator.locale(Translation.getLocale(player));
if (!SiegeWarSettings.getRevoltSiegesEnabled())
throw new TownyException(translator.of("msg_err_action_disable"));
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, SiegeWarPermissionNodes.getPermissionNodeToStartSiege(SiegeType.REVOLT)))
throw new TownyException(translator.of("msg_err_action_disable"));
if (!TownOccupationController.isTownOccupied(targetTown))
throw new TownyException(translator.of("msg_err_cannot_start_revolt_siege_as_town_is_unoccupied"));
long immunity = TownMetaDataController.getRevoltImmunityEndTime(targetTown);
if (immunity == -1L)
throw new TownyException(translator.of("msg_err_siege_war_revolt_immunity_permanent"));
if (System.currentTimeMillis() < immunity)
throw new TownyException(translator.of("msg_err_siege_war_revolt_immunity_active"));
Nation occupierNation = TownOccupationController.getTownOccupier(targetTown);
SiegeCamp camp = new SiegeCamp(player, bannerBlock, SiegeType.REVOLT, targetTown, targetTown, occupierNation, townOfSiegeStarter, townBlock);
PreSiegeCampEvent event = new PreSiegeCampEvent(camp);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
throw new TownyException(event.getCancellationMsg());
if (SiegeWarSettings.areSiegeCampsEnabled())
// Launch a SiegeCamp, a (by default) 10 minute minigame. If successful the Siege will be initiated in ernest.
SiegeController.beginSiegeCamp(camp);
else
// SiegeCamps are disabled, just do the Siege.
camp.startSiege();
}
use of com.gmail.goosius.siegewar.events.PreSiegeCampEvent in project SiegeWar by TownyAdvanced.
the class StartSuppressionSiege method processStartSiegeRequest.
/**
* Process a start suppression siege request.
*
* At this point we know that the resident has a nation,
* and the nation is occupying the town.
*
* This method does some final checks and if they pass, the siege is initiated.
*
* @param player the player
* @param townOfSiegeStarter town
* @param nationOfSiegeStarter nation which is attacking.
* @param townBlock the townblock where the attack is taking place.
* @param targetTown the town about to be attacked
* @param bannerBlock the banner block
*
* @throws TownyException when attack cannot be made.
*/
public static void processStartSiegeRequest(Player player, Town townOfSiegeStarter, Nation nationOfSiegeStarter, TownBlock townBlock, Town targetTown, Block bannerBlock) throws TownyException {
final Translator translator = Translator.locale(Translation.getLocale(player));
if (!SiegeWarSettings.getSuppressionSiegesEnabled())
throw new TownyException(translator.of("msg_err_action_disable"));
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, SiegeWarPermissionNodes.getPermissionNodeToStartSiege(SiegeType.SUPPRESSION)))
throw new TownyException(translator.of("msg_err_action_disable"));
if (targetTown.hasNation()) {
Nation nationOfDefendingTown = targetTown.getNation();
if (nationOfSiegeStarter == nationOfDefendingTown)
throw new TownyException(translator.of("msg_err_siege_war_cannot_attack_town_in_own_nation"));
if (!nationOfSiegeStarter.hasEnemy(nationOfDefendingTown))
throw new TownyException(translator.of("msg_err_siege_war_cannot_attack_non_enemy_nation"));
}
if (TownySettings.getNationRequiresProximity() > 0) {
Coord capitalCoord = nationOfSiegeStarter.getCapital().getHomeBlock().getCoord();
Coord townCoord = targetTown.getHomeBlock().getCoord();
if (!nationOfSiegeStarter.getCapital().getHomeBlock().getWorld().getName().equals(targetTown.getHomeBlock().getWorld().getName())) {
throw new TownyException(translator.of("msg_err_nation_homeblock_in_another_world"));
}
double distance;
distance = Math.sqrt(Math.pow(capitalCoord.getX() - townCoord.getX(), 2) + Math.pow(capitalCoord.getZ() - townCoord.getZ(), 2));
if (distance > TownySettings.getNationRequiresProximity()) {
throw new TownyException(translator.of("msg_err_siege_war_town_not_close_enough_to_nation"));
}
}
SiegeCamp camp = new SiegeCamp(player, bannerBlock, SiegeType.SUPPRESSION, targetTown, nationOfSiegeStarter, targetTown, townOfSiegeStarter, townBlock);
PreSiegeCampEvent event = new PreSiegeCampEvent(camp);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled())
throw new TownyException(event.getCancellationMsg());
if (SiegeWarSettings.areSiegeCampsEnabled())
// Launch a SiegeCamp, a (by default) 10 minute minigame. If successful the Siege will be initiated in ernest.
SiegeController.beginSiegeCamp(camp);
else
// SiegeCamps are disabled, just do the Siege.
camp.startSiege();
}
Aggregations