Search in sources :

Example 1 with SiegeCamp

use of com.gmail.goosius.siegewar.objects.SiegeCamp 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();
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Coord(com.palmergames.bukkit.towny.object.Coord) Translator(com.palmergames.bukkit.towny.object.Translator) PreSiegeCampEvent(com.gmail.goosius.siegewar.events.PreSiegeCampEvent) SiegeCamp(com.gmail.goosius.siegewar.objects.SiegeCamp) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 2 with SiegeCamp

use of com.gmail.goosius.siegewar.objects.SiegeCamp 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();
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Coord(com.palmergames.bukkit.towny.object.Coord) Translator(com.palmergames.bukkit.towny.object.Translator) PreSiegeCampEvent(com.gmail.goosius.siegewar.events.PreSiegeCampEvent) SiegeCamp(com.gmail.goosius.siegewar.objects.SiegeCamp) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 3 with SiegeCamp

use of com.gmail.goosius.siegewar.objects.SiegeCamp 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();
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Translator(com.palmergames.bukkit.towny.object.Translator) PreSiegeCampEvent(com.gmail.goosius.siegewar.events.PreSiegeCampEvent) SiegeCamp(com.gmail.goosius.siegewar.objects.SiegeCamp) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 4 with SiegeCamp

use of com.gmail.goosius.siegewar.objects.SiegeCamp 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();
}
Also used : Nation(com.palmergames.bukkit.towny.object.Nation) Coord(com.palmergames.bukkit.towny.object.Coord) Translator(com.palmergames.bukkit.towny.object.Translator) PreSiegeCampEvent(com.gmail.goosius.siegewar.events.PreSiegeCampEvent) SiegeCamp(com.gmail.goosius.siegewar.objects.SiegeCamp) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 5 with SiegeCamp

use of com.gmail.goosius.siegewar.objects.SiegeCamp in project SiegeWar by TownyAdvanced.

the class SiegeWarBlockUtil method isBlockNearAnActiveSiegeCampBanner.

/**
 * 	Determine if the block is a siege banner during a SiegeCamp session, or the support block.
 *
 * 	First look at the material of both the target block and the block above it.
 * 	Return false if neither is a standing banner.
 *
 * 	Then look at all SiegeCamps and determine if it is the block.
 *
 * 	Note that we don't try to look at the nearby townblocks to find nearby siege zones,
 * 	....because mayor may have unclaimed townblocks after the siege started.
 *
 * @param block the block to be considered
 * @return true if the block is near an active siege banner
 */
public static boolean isBlockNearAnActiveSiegeCampBanner(Block block) {
    // If either the target block or block above it is a standing coloured banner, continue, else return false
    if (isStandingColouredBanner(block) || isStandingColouredBanner(block.getRelative(BlockFace.UP))) {
        // Look through all siegecamps
        Location locationOfBlock = block.getLocation();
        Location locationOfBlockAbove = block.getRelative(BlockFace.UP).getLocation();
        Location locationOfSiegeBanner;
        for (SiegeCamp siegeCamp : SiegeController.getSiegeCamps()) {
            locationOfSiegeBanner = siegeCamp.getBannerBlock().getLocation();
            if (locationOfBlock.equals(locationOfSiegeBanner) || locationOfBlockAbove.equals(locationOfSiegeBanner)) {
                return true;
            }
        }
    }
    // No siegecamp banner found near given block
    return false;
}
Also used : SiegeCamp(com.gmail.goosius.siegewar.objects.SiegeCamp) Location(org.bukkit.Location)

Aggregations

SiegeCamp (com.gmail.goosius.siegewar.objects.SiegeCamp)5 PreSiegeCampEvent (com.gmail.goosius.siegewar.events.PreSiegeCampEvent)4 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)4 Nation (com.palmergames.bukkit.towny.object.Nation)4 Translator (com.palmergames.bukkit.towny.object.Translator)4 Coord (com.palmergames.bukkit.towny.object.Coord)3 Location (org.bukkit.Location)1