use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class PlaceBlock method evaluatePlaceChest.
/**
* Evaluates placing a chest.
* Determines if the event will be considered as a plunder request.
* @throws TownyException when the chest is not allowed to be placed.
*/
private static void evaluatePlaceChest(Player player, Block block) throws TownyException {
if (!SiegeWarSettings.getWarSiegePlunderEnabled() || !TownyAPI.getInstance().isWilderness(block))
return;
final Translator translator = Translator.locale(Translation.getLocale(player));
if (!TownyEconomyHandler.isActive())
throw new TownyException(translator.of("msg_err_siege_war_cannot_plunder_without_economy"));
// If there are no sieges nearby, do normal block placement
Set<Siege> adjacentSieges = SiegeWarBlockUtil.getAllAdjacentSieges(block);
if (adjacentSieges.size() == 0)
return;
// Ensure there is only one adjacent siege
if (adjacentSieges.size() > 1)
throw new TownyException(translator.of("msg_err_siege_war_too_many_adjacent_towns"));
// Attempt plunder.
PlunderTown.processPlunderTownRequest(player, adjacentSieges.iterator().next().getTown());
}
use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class PlayerDeath method evaluateSiegePlayerDeath.
/**
* Evaluates a siege death event.
* <p>
* If the dead player is officially involved in a nearby siege,
* - The opposing team gains battle points
* - Their inventory items degrade a little (e.g. 20%)
* <p>
* The allegiance of the killer is not considered,
* in order to allows for a wider range of siege-kill-tactics.
* Examples:
* - Players without towns can contribute to battle points
* - Players from non-nation towns can contribute to battle points
* - Players from secretly-allied nations can contribute to battle points
* - Devices (cannons, traps, bombs etc.) can be used to gain battle points
*
* @param deadPlayer The player who died
* @param playerDeathEvent The player death event
*/
public static void evaluateSiegePlayerDeath(Player deadPlayer, PlayerDeathEvent playerDeathEvent) {
try {
World world = playerDeathEvent.getEntity().getWorld();
if (!TownyAPI.getInstance().isTownyWorld(world) || !TownyAPI.getInstance().getTownyWorld(world).isWarAllowed())
return;
TownyPermissionSource tps = TownyUniverse.getInstance().getPermissionSource();
Resident deadResident = TownyUniverse.getInstance().getResident(deadPlayer.getUniqueId());
if (deadResident == null || !deadResident.hasTown())
return;
/*
* Do an early permission test to avoid hitting the sieges list if
* it could never return a proper SiegeSide.
*/
if (!tps.testPermission(deadPlayer, SiegeWarPermissionNodes.SIEGEWAR_TOWN_SIEGE_BATTLE_POINTS.getNode()) && !tps.testPermission(deadPlayer, SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_BATTLE_POINTS.getNode()))
return;
Town deadResidentTown = deadResident.getTown();
// Declare local variables
Siege confirmedCandidateSiege = null;
SiegeSide confirmedCandidateSiegePlayerSide = SiegeSide.NOBODY;
double confirmedCandidateDistanceToPlayer = 0;
double candidateSiegeDistanceToPlayer;
SiegeSide candidateSiegePlayerSide;
// Find nearest eligible siege
for (Siege candidateSiege : SiegeController.getSieges()) {
// Skip if siege is not active
if (!candidateSiege.getStatus().isActive())
continue;
// Skip if player is not is siege-zone
if (!SiegeWarDistanceUtil.isInSiegeZone(deadPlayer, candidateSiege))
continue;
// Is player eligible ?
candidateSiegePlayerSide = SiegeWarAllegianceUtil.calculateCandidateSiegePlayerSide(deadPlayer, deadResidentTown, candidateSiege);
if (candidateSiegePlayerSide == SiegeSide.NOBODY)
continue;
// Confirm candidate siege if it is 1st viable one OR closer than confirmed candidate
candidateSiegeDistanceToPlayer = deadPlayer.getLocation().distance(candidateSiege.getFlagLocation());
if (confirmedCandidateSiege == null || candidateSiegeDistanceToPlayer < confirmedCandidateDistanceToPlayer) {
confirmedCandidateSiege = candidateSiege;
confirmedCandidateSiegePlayerSide = candidateSiegePlayerSide;
confirmedCandidateDistanceToPlayer = candidateSiegeDistanceToPlayer;
}
}
// apply siege point penalty for the nearest one, and keep inventory
if (confirmedCandidateSiege != null) {
// Award penalty points w/ notification if siege is in progress
if (confirmedCandidateSiege.getStatus() == SiegeStatus.IN_PROGRESS) {
if (SiegeWarSettings.getWarSiegeDeathSpawnFireworkEnabled()) {
if (isBannerMissing(confirmedCandidateSiege.getFlagLocation()))
replaceMissingBanner(confirmedCandidateSiege.getFlagLocation());
Color bannerColor = ((Banner) confirmedCandidateSiege.getFlagLocation().getBlock().getState()).getBaseColor().getColor();
CosmeticUtil.spawnFirework(deadPlayer.getLocation().add(0, 2, 0), Color.RED, bannerColor, true);
}
boolean residentIsAttacker = confirmedCandidateSiegePlayerSide == SiegeSide.ATTACKERS;
SiegeWarScoringUtil.awardPenaltyPoints(residentIsAttacker, deadPlayer, confirmedCandidateSiege);
}
// Keep and degrade inventory
degradeInventory(playerDeathEvent);
keepInventory(playerDeathEvent);
// Keep level
keepLevel(playerDeathEvent);
if (confirmedCandidateSiege.getBannerControlSessions().containsKey(deadPlayer)) {
// If the player that died had an ongoing session, remove it.
confirmedCandidateSiege.removeBannerControlSession(confirmedCandidateSiege.getBannerControlSessions().get(deadPlayer));
Translatable errorMessage = SiegeWarSettings.isTrapWarfareMitigationEnabled() ? Translatable.of("msg_siege_war_banner_control_session_failure_with_altitude") : Translatable.of("msg_siege_war_banner_control_session_failure");
Messaging.sendMsg(deadPlayer, errorMessage);
}
}
} catch (Exception e) {
try {
SiegeWar.severe("Error evaluating siege death for player " + deadPlayer.getName());
} catch (Exception e2) {
SiegeWar.severe("Error evaluating siege death (could not read player name)");
}
e.printStackTrace();
}
}
use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class PlunderTown method processPlunderTownRequest.
/**
* Process a plunder town request
*
* This method does some final checks and if they pass, the plunder is executed.
*
* @param player the player who placed the plunder chest
* @param townToBePlundered the town to be plundered
* @throws TownyException when a plunder is not allowed.
*/
public static void processPlunderTownRequest(Player player, Town townToBePlundered) throws TownyException {
TownyUniverse townyUniverse = TownyUniverse.getInstance();
final Translator translator = Translator.locale(Translation.getLocale(player));
if (!townyUniverse.getPermissionSource().testPermission(player, SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_PLUNDER.getNode()))
throw new TownyException(translator.of("msg_err_command_disable"));
Resident resident = townyUniverse.getResident(player.getUniqueId());
if (resident == null)
throw new TownyException(translator.of("msg_err_not_registered_1", player.getName()));
if (!resident.hasTown())
throw new TownyException(translator.of("msg_err_siege_war_action_not_a_town_member"));
Town townOfPlunderingResident = resident.getTown();
if (!townOfPlunderingResident.hasNation())
throw new TownyException(translator.of("msg_err_siege_war_action_not_a_nation_member"));
Siege siege = SiegeController.getSiege(townToBePlundered);
if (siege.isTownPlundered())
throw new TownyException(String.format(translator.of("msg_err_siege_war_town_already_plundered"), townToBePlundered.getName()));
Nation nationOfPlunderingResident = townOfPlunderingResident.getNation();
if (siege.getSiegeType() == SiegeType.REVOLT) {
if (siege.getStatus() == SiegeStatus.ATTACKER_WIN || siege.getStatus() == SiegeStatus.DEFENDER_SURRENDER) {
throw new TownyException(translator.of("msg_err_siege_war_plunder_not_possible_rebels_won"));
}
if (siege.getStatus() != SiegeStatus.DEFENDER_WIN && siege.getStatus() != SiegeStatus.ATTACKER_ABANDON) {
throw new TownyException(translator.of("msg_err_siege_war_cannot_plunder_without_victory"));
}
if (nationOfPlunderingResident != siege.getDefender())
throw new TownyException(translator.of("msg_err_siege_war_cannot_plunder_without_victory"));
plunderTown(siege, townToBePlundered, (Nation) siege.getDefender());
} else {
if (siege.getStatus() != SiegeStatus.ATTACKER_WIN && siege.getStatus() != SiegeStatus.DEFENDER_SURRENDER) {
throw new TownyException(translator.of("msg_err_siege_war_cannot_plunder_without_victory"));
}
if (nationOfPlunderingResident != siege.getAttacker())
throw new TownyException(translator.of("msg_err_siege_war_cannot_plunder_without_victory"));
plunderTown(siege, townToBePlundered, (Nation) siege.getAttacker());
}
}
use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class PlaceBlock method evaluateSiegeWarPlaceBlockRequest.
/**
* Evaluates a block placement request.
* If the block is a standing banner or chest, this method calls an appropriate private method.
*
* @param player The player placing the block
* @param block The block about to be placed
* @param event The event object related to the block placement
*/
public static void evaluateSiegeWarPlaceBlockRequest(Player player, Block block, TownyBuildEvent event) {
final Translator translator = Translator.locale(Translation.getLocale(player));
try {
// Ensure siege is enabled in this world
if (!TownyAPI.getInstance().getTownyWorld(block.getWorld()).isWarAllowed())
return;
// If the event is in a town and was cancelled by towny, SW might un-cancel the event via wall breaching
if (event.isCancelled() && SiegeWarSettings.isWallBreachingEnabled() && !TownyAPI.getInstance().isWilderness(block)) {
Town town = TownyAPI.getInstance().getTown(block.getLocation());
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.getWallBreachingBlockPlacementCost()) {
event.setMessage(translator.of("msg_err_not_enough_breach_points_for_action", SiegeWarSettings.getWallBreachingBlockPlacementCost(), 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 the material is ok to place
if (!SiegeWarSettings.getWallBreachingPlaceBlocksWhitelist().contains(block.getType())) {
event.setMessage(translator.of("msg_err_breaching_cannot_place_this_material"));
return;
}
// IF we get here, it is a wall breach!!
// Reduce breach points
siege.setWallBreachPoints(siege.getWallBreachPoints() - SiegeWarSettings.getWallBreachingBlockPlacementCost());
// 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;
}
// Enforce Anti-Trap warfare build block if below siege banner altitude.
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;
}
Material mat = block.getType();
// Standing Banner placement
if (Tag.BANNERS.isTagged(mat) && !mat.toString().contains("_W")) {
try {
if (evaluatePlaceStandingBanner(player, block))
event.setCancelled(false);
} catch (TownyException e1) {
Messaging.sendErrorMsg(player, e1.getMessage());
}
return;
}
// Chest placement
if (mat == Material.CHEST || mat == Material.TRAPPED_CHEST) {
try {
evaluatePlaceChest(player, block);
} catch (TownyException e) {
Messaging.sendErrorMsg(player, e.getMessage());
}
return;
}
// Check for forbidden siegezone block placement
if (SiegeWarSettings.getSiegeZoneWildernessForbiddenBlockMaterials().contains(mat) && TownyAPI.getInstance().isWilderness(block) && SiegeWarDistanceUtil.isLocationInActiveSiegeZone(block.getLocation())) {
throw new TownyException(translator.of("msg_war_siege_zone_block_placement_forbidden"));
}
} catch (TownyException e) {
event.setCancelled(true);
event.setMessage(e.getMessage());
}
}
use of com.gmail.goosius.siegewar.objects.Siege in project SiegeWar by TownyAdvanced.
the class SiegeWarSicknessUtil method punishWithFullWarSickness.
public static void punishWithFullWarSickness(Player player) {
final int effectDurationTicks = (int) (TimeTools.convertToTicks(TownySettings.getShortInterval() + 5));
if (SiegeWarSettings.getSicknessWarningTimeInTicks() / 20 >= 1) {
Messaging.sendMsg(player, Translatable.of("msg_you_will_get_sickness", SiegeWarSettings.getSicknessWarningTimeInTicks() / 20));
}
Towny.getPlugin().getServer().getScheduler().runTaskLater(Towny.getPlugin(), () -> {
Resident resident = TownyUniverse.getInstance().getResident(player.getUniqueId());
List<Siege> sieges = SiegeController.getActiveSiegesAt(player.getLocation());
boolean allowedInAnyOverlappingSiege = false;
for (Siege siege : sieges) {
if (isSiegeParticipant(player, resident, siege)) {
allowedInAnyOverlappingSiege = true;
break;
}
}
if (!allowedInAnyOverlappingSiege && SiegeWarDistanceUtil.isLocationInActiveSiegeZone(player.getLocation())) {
// still in siege zone
List<PotionEffect> potionEffects = new ArrayList<>();
potionEffects.add(new PotionEffect(PotionEffectType.CONFUSION, effectDurationTicks, 4));
potionEffects.add(new PotionEffect(PotionEffectType.POISON, effectDurationTicks, 4));
potionEffects.add(new PotionEffect(PotionEffectType.WEAKNESS, effectDurationTicks, 4));
potionEffects.add(new PotionEffect(PotionEffectType.SLOW, effectDurationTicks, 2));
potionEffects.add(new PotionEffect(PotionEffectType.SLOW_DIGGING, effectDurationTicks, 2));
player.addPotionEffects(potionEffects);
Messaging.sendMsg(player, Translatable.of("msg_you_received_war_sickness"));
}
}, SiegeWarSettings.getSicknessWarningTimeInTicks());
}
Aggregations