use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class SiegeWarBattleSessionUtil method endBattleSession.
public static void endBattleSession() {
BattleSession battleSession = BattleSession.getBattleSession();
battleSession.setActive(false);
battleResults.clear();
/*
* Gather the results of all battles
* End any active battles
*/
for (Siege siege : SiegeController.getSieges()) endBattleSessionForSiege(siege);
Bukkit.getPluginManager().callEvent(new BattleSessionEndedEvent());
// Send message
sendBattleSessionEndedMessage(battleResults);
// Remove Battle Session Boss-Bars
BossBarUtil.removeBattleSessionBossBars();
}
use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class SiegeWarBlockUtil method isBlockNearAnActiveSiegeBanner.
/**
* Determine if the block is an active siege banner, 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 siege zones within 'in progress' sieges,
* and determine if the target block or block above it is a siege banner.
*
* 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 isBlockNearAnActiveSiegeBanner(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 siege zones
Location locationOfBlock = block.getLocation();
Location locationOfBlockAbove = block.getRelative(BlockFace.UP).getLocation();
Location locationOfSiegeBanner;
for (Siege siege : SiegeController.getSieges()) {
if (!siege.getStatus().isActive()) {
continue;
}
locationOfSiegeBanner = siege.getFlagLocation();
if (locationOfBlock.equals(locationOfSiegeBanner) || locationOfBlockAbove.equals(locationOfSiegeBanner)) {
return true;
}
}
}
// No active siege banner found near given block
return false;
}
use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class DestroyBlock method evaluateSiegeWarDestroyBlockRequest.
/**
* Evaluates a block destroy request.
*
* @param event The event object
* @throws TownyException if something is misconfigured
*/
public static void evaluateSiegeWarDestroyBlockRequest(TownyDestroyEvent event) throws TownyException {
// Ensure siege is enabled in this world
Block block = event.getBlock();
if (!TownyAPI.getInstance().getTownyWorld(block.getWorld()).isWarAllowed())
return;
final Translator translator = Translator.locale(Translation.getLocale(event.getPlayer()));
// If the event has already been cancelled by Towny...
if (event.isCancelled()) {
if (!SiegeWarSettings.isWallBreachingEnabled())
// Without wall breaching, SW doesn't un-cancel events
return;
Town town = TownyAPI.getInstance().getTown(block.getLocation());
if (town == null)
// SW doesn't un-cancel wilderness events
return;
if (!SiegeController.hasActiveSiege(town))
// SW doesn't un-cancel events in unsieged towns
return;
// Ensure player has permission
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(event.getPlayer(), SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_USE_BREACH_POINTS.getNode())) {
event.setMessage(translator.of("msg_err_action_disable"));
return;
}
// No wall breaching outside battle sessions
if (!BattleSession.getBattleSession().isActive()) {
event.setMessage(translator.of("msg_err_cannot_breach_without_battle_session"));
return;
}
// Ensure player is on the town-hostile siege side
Resident resident = TownyAPI.getInstance().getResident(event.getPlayer());
if (resident == null)
return;
Siege siege = SiegeController.getSiege(town);
if (!SiegeWarAllegianceUtil.isPlayerOnTownHostileSide(event.getPlayer(), resident, siege))
return;
// Ensure there are enough breach points
if (siege.getWallBreachPoints() < SiegeWarSettings.getWallBreachingBlockDestructionCost()) {
event.setMessage(translator.of("msg_err_not_enough_breach_points_for_action", SiegeWarSettings.getWallBreachingBlockDestructionCost(), siege.getFormattedBreachPoints()));
return;
}
// Ensure height is ok
if (!SiegeWarWallBreachUtil.validateBreachHeight(block, town, siege)) {
event.setMessage(translator.of("msg_err_cannot_breach_at_this_height", SiegeWarSettings.getWallBreachingHomeblockBreachHeightLimitMin(), SiegeWarSettings.getWallBreachingHomeblockBreachHeightLimitMax()));
return;
}
// Ensure material is ok
if (!SiegeWarWallBreachUtil.validateDestroyMaterial(block, event.getLocation())) {
event.setMessage(translator.of("msg_err_cannot_destroy_at_this_height", SiegeWarSettings.getWallBreachingHomeblockBreachHeightLimitMin(), SiegeWarSettings.getWallBreachingHomeblockBreachHeightLimitMax()));
return;
}
// IF we get here, it is a wall breach!!
// Reduce breach points
siege.setWallBreachPoints(siege.getWallBreachPoints() - SiegeWarSettings.getWallBreachingBlockDestructionCost());
// Un-cancel the event
event.setCancelled(false);
// Send message to player
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.RED + translator.of("msg_wall_breach_successful")));
return;
}
// Trap warfare block protection
if (SiegeWarSettings.isTrapWarfareMitigationEnabled() && SiegeWarDistanceUtil.isLocationInActiveTimedPointZoneAndBelowSiegeBannerAltitude(event.getBlock().getLocation())) {
event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent(ChatColor.DARK_RED + translator.of("msg_err_cannot_alter_blocks_below_banner_in_timed_point_zone")));
event.setCancelled(true);
return;
}
// Prevent destruction of siege-banner or support block
if (SiegeWarBlockUtil.isBlockNearAnActiveSiegeBanner(event.getBlock()) || SiegeWarBlockUtil.isBlockNearAnActiveSiegeCampBanner(event.getBlock())) {
event.setMessage(translator.of("msg_err_siege_war_cannot_destroy_siege_banner"));
event.setCancelled(true);
return;
}
}
use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class PlaceBlock method evaluatePlaceWhiteBannerNearTown.
/**
* Evaluates placing a white banner near a town
*
* Effects depend on the nature of the siege (if any) and the allegiances of the banner placer
*
* @param player the player placing the banner
* @param residentsTown the town of the player placing the banner
* @param residentsNation the nation of the player placing the banner (can be null)
* @param nearbyTown the nearby town
*/
private static void evaluatePlaceWhiteBannerNearTown(Player player, Town residentsTown, Nation residentsNation, Town nearbyTown) throws TownyException {
final Translator translator = Translator.locale(Translation.getLocale(player));
// Ensure that there is a siege
if (!SiegeController.hasSiege(nearbyTown))
throw new TownyException(translator.of("msg_err_town_cannot_end_siege_as_no_siege"));
// Get siege
Siege siege = SiegeController.getSiege(nearbyTown);
if (siege.getStatus() != SiegeStatus.IN_PROGRESS)
throw new TownyException(translator.of("msg_err_town_cannot_end_siege_as_finished"));
/*
* Check what type of action this qualifies as.
* Depending on the scenario, it may be 'abandonAttack' or 'surrenderDefence'
*/
switch(siege.getSiegeType()) {
case CONQUEST:
if (residentsNation != null && residentsNation == siege.getAttacker()) {
AbandonAttack.processAbandonAttackRequest(player, siege);
} else if (residentsTown == nearbyTown) {
SurrenderDefence.processSurrenderDefenceRequest(player, siege);
} else {
throw new TownyException(translator.of("msg_err_action_disable"));
}
break;
case LIBERATION:
if (residentsNation != null && residentsNation == siege.getAttacker()) {
AbandonAttack.processAbandonAttackRequest(player, siege);
} else if (residentsNation != null && TownOccupationController.isTownOccupied(nearbyTown) && TownOccupationController.getTownOccupier(nearbyTown) == residentsNation) {
SurrenderDefence.processSurrenderDefenceRequest(player, siege);
} else {
throw new TownyException(translator.of("msg_err_action_disable"));
}
break;
case REVOLT:
if (residentsTown == nearbyTown) {
AbandonAttack.processAbandonAttackRequest(player, siege);
} else if (residentsNation != null && TownOccupationController.isTownOccupied(nearbyTown) && TownOccupationController.getTownOccupier(nearbyTown) == residentsNation) {
SurrenderDefence.processSurrenderDefenceRequest(player, siege);
} else {
throw new TownyException(translator.of("msg_err_action_disable"));
}
break;
case SUPPRESSION:
if (residentsNation != null && TownOccupationController.isTownOccupied(nearbyTown) && TownOccupationController.getTownOccupier(nearbyTown) == residentsNation) {
AbandonAttack.processAbandonAttackRequest(player, siege);
} else if (residentsTown == nearbyTown) {
SurrenderDefence.processSurrenderDefenceRequest(player, siege);
} else {
throw new TownyException(translator.of("msg_err_action_disable"));
}
break;
}
}
use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class SiegeWarSicknessUtil method punishNonSiegeParticipantsInSiegeZone.
public static void punishNonSiegeParticipantsInSiegeZone() {
for (Player player : Bukkit.getOnlinePlayers()) {
Location location = player.getLocation();
// Players immune to war nausea won't be punished
if (player.hasPermission(SiegeWarPermissionNodes.SIEGEWAR_IMMUNE_TO_WAR_NAUSEA.getNode()))
continue;
List<Siege> sieges = SiegeController.getActiveSiegesAt(location);
// not in a siege zone
if (sieges.isEmpty())
continue;
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
if (resident == null)
continue;
boolean allowedInAnyOverlappingSiege = false;
for (Siege siege : sieges) {
if (isSiegeParticipant(player, resident, siege)) {
allowedInAnyOverlappingSiege = true;
break;
}
}
if (!allowedInAnyOverlappingSiege) {
if (isInOwnClaims(resident)) {
punishWithSpecialWarSickness(player);
} else {
punishWithFullWarSickness(player);
}
}
}
}
Aggregations