diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownyEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownyEventListener.java index 94cbe341b..e83b59a2f 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownyEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownyEventListener.java @@ -10,6 +10,7 @@ import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.settings.SiegeWarSettings; import com.gmail.goosius.siegewar.tasks.SiegeWarTimerTaskController; +import com.gmail.goosius.siegewar.utils.SiegeWarBattleSessionUtil; import com.gmail.goosius.siegewar.utils.SiegeWarBlockProtectionUtil; import com.gmail.goosius.siegewar.utils.SiegeWarBlockUtil; import com.gmail.goosius.siegewar.utils.SiegeWarDistanceUtil; @@ -472,7 +473,8 @@ public void onTownyKeepInventoryEvent(PlayerKeepsInventoryEvent event) { Siege siege = SiegeWarAPI.getActiveSiegeAtLocation(event.getLocation()); if (!SiegeSide.isDefender(siege, event.getPlayer())) return; - if (siege.getSiegeBalance() > SiegeWarSettings.getDefendersDropInventoryWhenLosingThreshold()) + if (SiegeWarBattleSessionUtil.getSiegeBalanceIfSessionEndedNow(siege) + < SiegeWarSettings.getDefendersDropInventoryWhenLosingThreshold()) return; event.setCancelled(true); @@ -487,7 +489,7 @@ public void onTownyKeepInventoryEvent(PlayerKeepsInventoryEvent event) { // But we don't want defenders that are losing too greatly to keep their inventories. if (SiegeWarSettings.isDefendersDropInventoryWhenLosingEnabled() && SiegeSide.isDefender(siege, event.getPlayer()) - && siege.getSiegeBalance() <= SiegeWarSettings.getDefendersDropInventoryWhenLosingThreshold()) + && SiegeWarBattleSessionUtil.getSiegeBalanceIfSessionEndedNow(siege) >= SiegeWarSettings.getDefendersDropInventoryWhenLosingThreshold()) return; SiegeWarInventoryUtil.degradeInventory(event.getPlayer()); diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java index aa8db362e..e51c25562 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -973,9 +973,9 @@ public enum ConfigNodes { "# ie: They defenders are losing by a great number."), KEEP_INVENTORY_ON_SIEGEZONE_DEATH_DISABLE_FOR_DEFENDERS_THRESHOLD( "keep_inventory_on_siegezone_death.disable_for_defenders.threshold", - "-500", + "500", "", - "# The threshold required to cause defenders to lose their inventory. If the Siege point balance is equal to or lower than this number", + "# The threshold required to cause defenders to lose their inventory. If the Siege point balance is equal to or greater than this number", "# and disable_for_defenders is enabled, defenders will not keep their inventories."), SPECIAL_VICTORY_EFFECTS( diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java index d0e7557ed..9909baa1f 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java @@ -189,6 +189,15 @@ private static void unjailPlayers(Nation attacker, Town defender) { Messaging.sendGlobalMessage(Translatable.of("msg_attackers_have_triggered_a_jail_break_freeing", StringMgmt.join(freedNames, ", "))); } + public static int getSiegeBalanceIfSessionEndedNow(Siege siege) { + int siegeBalanceAdjustment = calculateSiegeBalanceAdjustment(siege); + int futureBalance = siege.getSiegeBalance() + siegeBalanceAdjustment; + if(SiegeWarSettings.getSiegeBalanceCapValue() != -1) { + futureBalance = Math.min(futureBalance, SiegeWarSettings.getSiegeBalanceCapValue()); + } + return futureBalance; + } + public static void evaluateBattleSessions() { BattleSession battleSession = BattleSession.getBattleSession();