use of com.palmergames.bukkit.towny.object.Translator 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.palmergames.bukkit.towny.object.Translator 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.palmergames.bukkit.towny.object.Translator 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();
}
use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.
the class InvadeTown method processInvadeTownRequest.
/**
* Process an invade town request
*
* @param siege the siege of the town.
* @throws TownyException when the invasion wont be allowed.
*/
public static void processInvadeTownRequest(Player player, Nation residentsNation, Town nearbyTown, Siege siege) throws TownyException {
final Translator translator = Translator.locale(Translation.getLocale(player));
if (!SiegeWarSettings.getWarSiegeInvadeEnabled())
throw new TownyException(translator.of("msg_err_action_disable"));
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_INVADE.getNode()))
throw new TownyException(translator.of("msg_err_action_disable"));
if (residentsNation == null)
// Can't invade if nationless
throw new TownyException(translator.of("msg_err_action_disable"));
if (siege.getStatus().isActive())
throw new TownyException(translator.of("msg_err_cannot_invade_siege_still_in_progress"));
if (TownOccupationController.isTownOccupied(nearbyTown) && TownOccupationController.getTownOccupier(nearbyTown) == residentsNation)
throw new TownyException(translator.of("msg_err_cannot_invade_town_already_occupied"));
if (residentsNation != siege.getAttacker())
// Can't invade unless you are the attacker
throw new TownyException(translator.of("msg_err_action_disable"));
if (siege.getStatus() != SiegeStatus.ATTACKER_WIN && siege.getStatus() != SiegeStatus.DEFENDER_SURRENDER)
throw new TownyException(translator.of("msg_err_cannot_invade_without_victory"));
if (siege.isTownInvaded())
throw new TownyException(translator.of("msg_err_town_already_invaded"));
if (TownySettings.getNationRequiresProximity() > 0) {
Coord capitalCoord = residentsNation.getCapital().getHomeBlock().getCoord();
Coord townCoord = nearbyTown.getHomeBlock().getCoord();
if (!residentsNation.getCapital().getHomeBlock().getWorld().getName().equals(nearbyTown.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(String.format(translator.of("msg_err_town_not_close_enough_to_nation"), nearbyTown.getName()));
}
}
if (TownySettings.getMaxTownsPerNation() > 0) {
int effectiveNumTowns = SiegeWarNationUtil.getEffectiveNation(residentsNation).getNumTowns();
if (effectiveNumTowns >= TownySettings.getMaxTownsPerNation()) {
throw new TownyException(String.format(translator.of("msg_err_nation_over_town_limit"), TownySettings.getMaxTownsPerNation()));
}
}
invadeTown(residentsNation, nearbyTown, siege);
}
use of com.palmergames.bukkit.towny.object.Translator in project SiegeWar by TownyAdvanced.
the class PeacefullySubvertTown method processActionRequest.
/**
* Process a subvert town request
*
* @param player the player attempting the subvert.
* @param residentsNation the nation of the player (can be null)
* @param targetTown the target town. We know the player is not a resident.
*
* @throws TownyException if subvert is not allowed
*/
public static void processActionRequest(Player player, Nation residentsNation, Town targetTown) throws TownyException {
final Translator translator = Translator.locale(com.palmergames.bukkit.towny.object.Translation.getLocale(player));
if (!SiegeWarSettings.isPeacefulTownsSubvertEnabled())
throw new TownyException(translator.of("msg_err_action_disable"));
if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, SiegeWarPermissionNodes.SIEGEWAR_NATION_SIEGE_SUBVERTPEACEFULTOWN.getNode()))
throw new TownyException(translator.of("msg_err_action_disable"));
if (residentsNation == null)
// Can't subvert if nationless
throw new TownyException(translator.of("msg_err_action_disable"));
if (SiegeController.hasActiveSiege(targetTown)) {
throw new TownyException(translator.of("msg_err_cannot_change_occupation_of_besieged_town"));
}
if (targetTown.hasNation() && targetTown.getNation() == residentsNation)
throw new TownyException(translator.of("msg_err_cannot_subvert_towns_in_own_nation"));
if (TownOccupationController.isTownOccupied(targetTown) && TownOccupationController.getTownOccupier(targetTown) == residentsNation)
throw new TownyException(translator.of("msg_err_cannot_subvert_town_already_occupied"));
if (TownySettings.getNationRequiresProximity() > 0) {
Coord capitalCoord = residentsNation.getCapital().getHomeBlock().getCoord();
Coord townCoord = targetTown.getHomeBlock().getCoord();
if (!residentsNation.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(String.format(translator.of("msg_err_town_not_close_enough_to_nation"), targetTown.getName()));
}
}
if (TownySettings.getMaxTownsPerNation() > 0) {
int effectiveNumTowns = SiegeWarNationUtil.getEffectiveNation(residentsNation).getNumTowns();
if (effectiveNumTowns >= TownySettings.getMaxTownsPerNation()) {
throw new TownyException(String.format(translator.of("msg_err_nation_over_town_limit"), TownySettings.getMaxTownsPerNation()));
}
}
verifyThatNationHasEnoughTownyInfluenceToSubvertTown(residentsNation, targetTown);
// Subvert town now
subvertTown(residentsNation, targetTown);
}
Aggregations