Skip to content

Commit

Permalink
Added issue #894 - config enable/disable outpost teleportation during…
Browse files Browse the repository at this point in the history
… battle sessions & siege (#902)

* added outpost spawn prevention configurability when a nation has an active offensive siege during a battle session

* fixed imports

* removed redundant exception

* fixed mismatched root/confignodes key

* Update src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java

added nullcheck

Co-authored-by: LlmDl <LlmDlio@gmail.com>

* prevented re-cancelling townspawnevent

---------

Co-authored-by: LlmDl <LlmDlio@gmail.com>
  • Loading branch information
tlm9201 and LlmDl authored Apr 8, 2024
1 parent 7ce5822 commit 7ed7ece
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gmail.goosius.siegewar.SiegeController;
import com.gmail.goosius.siegewar.SiegeWar;
import com.gmail.goosius.siegewar.enums.SiegeWarPermissionNodes;
import com.gmail.goosius.siegewar.objects.BattleSession;
import com.gmail.goosius.siegewar.utils.PermissionUtil;
import com.gmail.goosius.siegewar.TownOccupationController;
import com.gmail.goosius.siegewar.metadata.TownMetaDataController;
Expand All @@ -24,10 +25,13 @@
import com.palmergames.bukkit.towny.event.town.TownRuinedEvent;
import com.palmergames.bukkit.towny.event.town.TownPreSetHomeBlockEvent;
import com.palmergames.bukkit.towny.event.town.toggle.TownToggleNeutralEvent;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.TownBlock;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.Translatable;
import com.palmergames.bukkit.towny.object.Translation;
import com.palmergames.bukkit.towny.object.Translator;
import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.util.TimeMgmt;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand Down Expand Up @@ -268,22 +272,41 @@ public void onTownRankGivenToPlayer(TownAddResidentRankEvent event) {

/**
* If this is a peaceful town, UN-CANCEL the town spawn event
*
* If the town's nation has an active offensive siege and a battle session is active, CANCEL town spawn event to outposts
*
* Lowest priority so that more important features like the siegezone-tp-block can can take precedence
*
* @param event town spawn event
*/
@EventHandler(priority = EventPriority.LOWEST)
public void on(TownSpawnEvent event) {
if(SiegeWarSettings.getWarSiegeEnabled()
&& SiegeWarSettings.getWarCommonPeacefulTownsEnabled()
if(SiegeWarSettings.getWarSiegeEnabled()) {
Town toTown = event.getToTown();

if (SiegeWarSettings.getWarCommonPeacefulTownsEnabled()
&& SiegeWarSettings.isPeacefulTownPublicSpawnEnabled()) {
if (event.isCancelled()
&& SiegeWarTownPeacefulnessUtil.isTownPeaceful(event.getToTown())
&& event.getToTown().isPublic()) {
event.setCancelled(false); //UN-Cancel the event
if (event.isCancelled()
&& SiegeWarTownPeacefulnessUtil.isTownPeaceful(toTown)
&& toTown.isPublic()) {
event.setCancelled(false); //UN-Cancel the event
return; //Avoid re-cancelling event
}
}

Nation nation = toTown.getNationOrNull();
TownBlock tb = WorldCoord.parseWorldCoord(event.getTo()).getTownBlockOrNull();
if (nation == null || tb == null)
return;
//If enabled in config, prevent teleportation to outposts during offensive siege while battle session is active.
if (!SiegeController.getActiveOffensiveSieges(nation).isEmpty()
&& tb.isOutpost()
&& SiegeWarSettings.getWarSiegeOutpostTeleportationDisabled() && BattleSession.getBattleSession().isActive()) {
Translator translator = Translator.locale(event.getPlayer());

event.setCancelMessage(translator.of("siegewar_plugin_prefix") + translator.of("msg_err_cannot_spawn_outpost_during_battle_session"));
event.setCancelled(true); //Stop the teleport

}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public enum ConfigNodes {
"",
"# If this setting is true, then during Battle Sessions, only town residents are permitted to spawn into Siege-Zones OR besieged towns.",
"# This setting is recommended to protect players from accidentally spawning into a PVP-active-area while unprepared."),
WAR_SIEGE_OUTPOST_TELEPORTATION_DISABLED(
"war.siege.switches.outpost_teleportation_disabled",
"false",
"",
"# If true, then during Battle Sessions, teleportation to outposts for towns engaged in a siege is disabled."),
WAR_SIEGE_BESIEGED_TOWN_RECRUITMENT_DISABLED(
"war.siege.switches.besieged_town_recruitment_disabled",
"true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public static boolean getWarSiegeNonResidentSpawnIntoSiegeZonesOrBesiegedTownsDi
return Settings.getBoolean(ConfigNodes.WAR_SIEGE_NON_RESIDENT_SPAWN_INTO_SIEGE_ZONES_OR_BESIEGED_TOWNS_DISABLED);
}

public static boolean getWarSiegeOutpostTeleportationDisabled() {
return Settings.getBoolean(ConfigNodes.WAR_SIEGE_OUTPOST_TELEPORTATION_DISABLED);
}

public static int getWarSiegeMaxActiveSiegeAttacksPerNation() {
return Settings.getInt(ConfigNodes.WAR_SIEGE_MAX_ACTIVE_SIEGE_ATTACKS_PER_NATION);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ msg_err_cannot_spawn_battle_commander_offline: "&cYou cannot spawn to the siege
msg_err_cannot_spawn_battle_commander_dead: "&cYou cannot spawn to the siege because your team's battle commander is dead."
msg_err_cannot_spawn_battle_commander_not_in_siegezone: "&cYou cannot spawn to the siege because your team's battle commander is not in the Siege-Zone."
msg_err_cannot_spawn_not_in_homeblock: "&cYou must be in your town homeblock to spawn to the siege."
msg_err_cannot_spawn_outpost_during_battle_session: "&cYou cannot spawn to an outpost while your nation has an offensive siege during a battle session."


#Added in 2.8.0
msg_swa_remove_siege: '&bSiege of %s removed via admin commands.'
Expand Down

0 comments on commit 7ed7ece

Please sign in to comment.