From d3389bc0a2f476f15cff0fdc03a88abbcb4b1e07 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Tue, 13 Apr 2021 12:37:20 +0100 Subject: [PATCH 01/39] Post siege nation immunity - Added configs --- .../siegewar/settings/ConfigNodes.java | 82 +++++++++---------- .../siegewar/settings/SiegeWarSettings.java | 2 +- 2 files changed, 40 insertions(+), 44 deletions(-) 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 25e1fc40d..7e37a4772 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -702,70 +702,66 @@ public enum ConfigNodes { "# The banner xyz text is an alternative to beacon markers for siege banners (but they can also be used together).", "# If enabled, besieged towns will show the XYZ of the siege banner on their town screens."), - ALL_NATION_SIEGES( - "all_nation_sieges", + POST_WAR_NATION_IMMUNITY( + "post_war_nation_immunity", "", "############################################################", "# +------------------------------------------------------------+ #", - "# | All-Nation-Sieges | #", + "# | Post-War Nation Immunity | #", "# +------------------------------------------------------------+ #", "#######################################################################", ""), - ALL_NATION_SIEGES_ENABLED( - "all_nation_sieges.enabled", + POST_WAR_NATION_IMMUNITY_ENABLED( + "post_war_nation_immunity.enabled", "true", "", - "# If this setting is true, then all-nation-sieges are enabled.", + "# If this setting is true, then post-war nation immunity is enabled.", "# ", - "# Summary: ", - "# * When a nation home town is attacked, the nation fights as one team:", - "# - All other nation towns become immune to siege attack.", - "# - The immunity lasts for a few days after the siege ends.", - "# - During the siege, some war restrictions apply to all towns.", + "# This feature ensures that nations cannot be forced to fight continuously without a break.", "# ", - "# Benefits to Nations:", - "# * The nation cannot be forced to fight more than one siege at a time", - "# (however it can choose to fight more, by attacking/occupying/revolting).", - "# * The bigger a nation is, the riskier it is to attack one of its towns", - "# (bigger warchest)", - "# * After each home defence siege, the entire nation team gets a multi-day break from sieging", - "# (default 4.5 days for a full 3 day siege).", + "# This effect is achieved as follows:", + "# 1. The max number of consecutive home-town-defence sieges is limited.", + "# 2. After each period of continuous fighting, every town in the nation gets siege immunity.", + "# 3. To mitigate exploits, nations suffer some mild negative effects during sieges - cannot claim/unclaim/recruit.", + "# 4. To mitigate annoyance-sieges, the cost to attack a nation town grows depending on the size of the defending nation."), + POST_WAR_NATION_IMMUNITY_MAX_HOMETOWN_DEFENCE_SIEGES( + "post_war_nation_immunity.max_hometown_defence_sieges", + "3", + "", + "# This setting determines the max number of hometown defence sieges which a nation must fight.", "# ", - "# Costs to Nation:", - "# * During a home-defence siege, the nation cannot recruit new towns", - "# * During a home-defence siege, all home towns receive a mild version of the usual siege restrictions.", + "# EXAMPLE:", + "# If this value is 3, and the nation already has 3 hometowns under attack", + "# then no more attacks on its hometowns are allowed until after the current sieges end.", "# ", - "# Benefits to Server:", - "# * The server can better protect player health, as players are no longer forced to fight 24/7.", - "# * The server can carefully control (via the below 'siege_immunity_modifier' setting), the exact amount of siege aggression which they would like on the server.", + "# If this value is set to very high (e.g. 999999),", + "# it allows unlimited consecutive attacks on a nation,", + "# along with the possibility that the nation could be forced to fight continuously for weeks/months etc."), + POST_WAR_NATION_IMMUNITY_SIEGE_IMMUNITY_DURATION_MODIFIER( + "post_war_nation_immunity.siege_immunity_duration_modifier", + "0.75", + "", + "# This setting determines how much siege immunity each nation town receives after each siege/war period,", "# ", - "# LIST OF WAR RESTRICTIONS: ", - "# - (Nation) Cannot add new towns", - "# - (Town) Cannot claim/unclaim.", - "# - (Town) Cannot add new residents.", - "# - (Town) PVP forced on (except for peaceful towns, where PVP remains off)"), - ALL_NATION_SIEGES_SIEGE_IMMUNITY_MODIFIER( - "all_nation_sieges.siege_immunity_modifier", - "0.5", - "", - "# If all-nation-sieges are enabled,", - "# this setting determines how much siege-immunity each non-besieged home nation town will receieve.", - "# The value represents a fraction of the besieged town siege immunity.", "# EXAMPLE:", - "# If the besieged town gets 9 days of siege immunity,", - "# and this value is 0.5", - "# then each non-besieged town will receive 4.5 days of siege immunity."), - ALL_NATION_SIEGES_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST( - "all_nation_sieges.home_town_contribution_to_attack_cost", + "# If this value is 0.75, and a nation fights continuously in home defence for 4 days,", + "# then at the end of the fighting, all nation hometowns will receive siege immunity of 3 days."), + POST_WAR_NATION_IMMUNITY_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST( + "post_war_nation_immunity.home_town_contribution_to_attack_cost", "0.1", "", "# If this setting is higher than 0,", - "# then the larger a nation is, the higher the cost to attack it.", + "# then the larger a nation is, the higher the cost to attack one of its towns.", + "# ", + "# This setting is important to mitigate 'annoyance sieges', ", + "# where small nations cheaply attack larger nations at small towns,", + "# with no intention of fighting, but just to disrupt the larger nations.", + "# ", "# EXAMPLE:", "# If this setting is 0.1,", "# and a nation home town is attacked,", "# then for every home town in that nation (including the attacked one),", - "# the attack-cost(a.k.a warchest) requirement is increased by 10% of the amount it would take to attack that town."); + "# the attack-cost(i.e. warchest) requirement is increased by 10% of the amount it would take to attack that town."); private final String Root; private final String Default; diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java index e7df79104..f9e45d76a 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java @@ -398,7 +398,7 @@ public static boolean isTrapWarfareMitigationEnabled() { } public static boolean isAllNationSiegesEnabled() { - return Settings.getBoolean(ConfigNodes.ALL_NATION_SIEGES_ENABLED); + return Settings.getBoolean(ConfigNodes.POST_WAR_NATION_IMMUNITY_ENABLED); } public static double getAllNationSiegesSiegeImmunityModifier() { From 9a82d4af3406c9f39f425c0fc88b11b441c3c15f Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Tue, 13 Apr 2021 13:05:51 +0100 Subject: [PATCH 02/39] post siege nation immunnity - cleanups --- .../com/gmail/goosius/siegewar/settings/ConfigNodes.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 7e37a4772..b009f5604 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -723,7 +723,7 @@ public enum ConfigNodes { "# 1. The max number of consecutive home-town-defence sieges is limited.", "# 2. After each period of continuous fighting, every town in the nation gets siege immunity.", "# 3. To mitigate exploits, nations suffer some mild negative effects during sieges - cannot claim/unclaim/recruit.", - "# 4. To mitigate annoyance-sieges, the cost to attack a nation town grows depending on the size of the defending nation."), + "# 4. To mitigate annoyance-sieges, the cost to attack a nation town increases as the defending nation increases in size."), POST_WAR_NATION_IMMUNITY_MAX_HOMETOWN_DEFENCE_SIEGES( "post_war_nation_immunity.max_hometown_defence_sieges", "3", @@ -754,8 +754,9 @@ public enum ConfigNodes { "# then the larger a nation is, the higher the cost to attack one of its towns.", "# ", "# This setting is important to mitigate 'annoyance sieges', ", - "# where small nations cheaply attack larger nations at small towns,", - "# with no intention of fighting, but just to disrupt the larger nations.", + "# because large nations are disproportionately affected by the mild under-siege costs.", + "# Thus without mitigation, small nations could attack larger ones,", + "# with no intention of fighting, but just to cheaply disrupt them.", "# ", "# EXAMPLE:", "# If this setting is 0.1,", From 1ab0ab853827b6b2a209754dc54a4b126235a9b6 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Fri, 16 Apr 2021 12:48:24 +0100 Subject: [PATCH 03/39] post-war-nation-immunity - Cleanups & removed pvp switch from nation towns --- .../goosius/siegewar/SiegeController.java | 4 +-- .../SiegeWarNationEventListener.java | 4 +-- .../listeners/SiegeWarTownEventListener.java | 8 ++--- .../siegewar/playeractions/PlaceBlock.java | 2 +- .../siegewar/settings/ConfigNodes.java | 32 ++++++++++--------- .../siegewar/settings/SiegeWarSettings.java | 14 +++++--- .../siegewar/utils/SiegeWarMoneyUtil.java | 2 +- .../utils/SiegeWarSiegeCompletionUtil.java | 2 +- .../siegewar/utils/SiegeWarTimeUtil.java | 2 +- .../siegewar/utils/SiegeWarTownUtil.java | 21 ------------ 10 files changed, 38 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index d1bd008ef..dbf635da0 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -256,7 +256,7 @@ else if (refundSideIfSiegeIsActive == SiegeSide.DEFENDERS) siegedTowns.remove(siege.getTown()); siegedTownNames.remove(siege.getTown().getName()); - SiegeWarTownUtil.setTownPvpFlags(town, false); + SiegeWarTownUtil.setPvpFlag(town, false); CosmeticUtil.removeFakeBeacons(siege); //Save town @@ -469,7 +469,7 @@ public static void startSiege(Block bannerBlock, SiegeController.putTownInSiegeMap(targetTown, siege); //Set town to true, potentially set the town's nation's towns as well. - SiegeWarTownUtil.setTownPvpFlags(targetTown, true); + SiegeWarTownUtil.setPvpFlag(targetTown, true); //Send global message; try { diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java index 9fcdf72c3..b470beada 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java @@ -295,7 +295,7 @@ public void onTownTriesToLeaveNation(NationPreTownLeaveEvent event) { @EventHandler public void on(NationTownLeaveEvent event) { if (SiegeWarSettings.getWarSiegeEnabled() - && SiegeWarSettings.isAllNationSiegesEnabled() + && SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.hasActiveSiege(event.getTown())) { for(Town nationTown: event.getNation().getTowns()) { @@ -311,7 +311,7 @@ public void on(NationTownLeaveEvent event) { @EventHandler public void on(NationPreAddTownEvent event) { if (SiegeWarSettings.getWarSiegeEnabled() - && SiegeWarSettings.isAllNationSiegesEnabled() + && SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.isAnyHomeTownASiegeDefender(event.getNation())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_cannot_recruit")); diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java index 5cb0b423a..9852956f6 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java @@ -84,7 +84,7 @@ public void onTownAddResident(TownPreAddResidentEvent event) { return; } - if (SiegeWarSettings.isAllNationSiegesEnabled() + if (SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.isAnyHomeTownASiegeDefender(event.getTown())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_recruit")); @@ -132,7 +132,7 @@ public void onTownTogglePVP(TownTogglePVPEvent event) { } //Is the town affected by an all-nation-siege - if(SiegeWarSettings.isAllNationSiegesEnabled() + if(SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.isAnyHomeTownASiegeDefender(event.getTown())) { event.setCancellationMsg(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_toggle_pvp")); event.setCancelled(true); @@ -225,7 +225,7 @@ public void onTownClaim(TownPreClaimEvent event) { } //If the town is affected by an all-nation-siege, they cannot claim any land - if (SiegeWarSettings.isAllNationSiegesEnabled() + if (SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.isAnyHomeTownASiegeDefender(event.getTown())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_claim")); @@ -279,7 +279,7 @@ public void onTownUnclaim(TownPreUnclaimCmdEvent event) { } //Town affected by all-nation-siege - if (SiegeWarSettings.isAllNationSiegesEnabled() + if (SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.isAnyHomeTownASiegeDefender(event.getTown())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_unclaim")); diff --git a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java index 201f6758f..fbc6712ae 100644 --- a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java +++ b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java @@ -261,7 +261,7 @@ private static synchronized void evaluateStartNewSiegeAttempt(Player player, if(SiegeWarBlockUtil.isSupportBlockUnstable(bannerBlock)) throw new TownyException(Translation.of("msg_err_siege_war_banner_support_block_not_stable")); - if (SiegeWarSettings.isAllNationSiegesEnabled() + if (SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.isAnyHomeTownASiegeDefender(nearbyTown)) { throw new TownyException(Translation.of("msg_err_cannot_start_siege_because_towns_home_nation_has_besieged_town")); } 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 b009f5604..d11cb5bdc 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -717,31 +717,33 @@ public enum ConfigNodes { "", "# If this setting is true, then post-war nation immunity is enabled.", "# ", - "# This feature ensures that nations cannot be forced to fight continuously without a break.", + "# This feature ensures that non-aggressive nations cannot be forced to fight continuously,", + "# by granting siege-immunity to all of their towns, after any period of continuous fighting.", "# ", "# This effect is achieved as follows:", "# 1. The max number of consecutive home-town-defence sieges is limited.", - "# 2. After each period of continuous fighting, every town in the nation gets siege immunity.", - "# 3. To mitigate exploits, nations suffer some mild negative effects during sieges - cannot claim/unclaim/recruit.", - "# 4. To mitigate annoyance-sieges, the cost to attack a nation town increases as the defending nation increases in size."), - POST_WAR_NATION_IMMUNITY_MAX_HOMETOWN_DEFENCE_SIEGES( - "post_war_nation_immunity.max_hometown_defence_sieges", + "# 2. After each period of continuous fighting (a.k.a war), every town in the nation gets siege immunity.", + "# 3. To mitigate exploits, nations suffer some mild negative effects during hometown defence sieges - cannot claim/unclaim/recruit.", + "# 4. To mitigate annoyance-sieges, the cost to attack a hometown increases as the defending nation increases in size."), + POST_WAR_NATION_IMMUNITY_MAX_HOME_DEFENCE_SIEGES( + "post_war_nation_immunity.max_home_defence_sieges", "3", "", - "# This setting determines the max number of hometown defence sieges which a nation must fight.", + "# This setting determines the max number of home defence sieges which a nation must fight.", "# ", "# EXAMPLE:", "# If this value is 3, and the nation already has 3 hometowns under attack", - "# then no more attacks on its hometowns are allowed until after the current sieges end.", + "# then no more attacks on its hometowns are allowed until after all the current sieges end.", "# ", "# If this value is set to very high (e.g. 999999),", - "# it allows unlimited consecutive attacks on a nation,", - "# along with the possibility that the nation could be forced to fight continuously for weeks/months etc."), - POST_WAR_NATION_IMMUNITY_SIEGE_IMMUNITY_DURATION_MODIFIER( - "post_war_nation_immunity.siege_immunity_duration_modifier", + "# the restriction is effectively disabled, ", + "# allowing all hometowns to be attacked at once,", + "# along with the possibility that nations could be forced to fight continuously i.e. no rest days."), + POST_WAR_NATION_IMMUNITY_DURATION_MODIFIER( + "post_war_nation_immunity.duration_modifier", "0.75", "", - "# This setting determines how much siege immunity each nation town receives after each siege/war period,", + "# This setting determines the duration ofsiege immunity which each nation town receives after a war period,", "# ", "# EXAMPLE:", "# If this value is 0.75, and a nation fights continuously in home defence for 4 days,", @@ -754,7 +756,7 @@ public enum ConfigNodes { "# then the larger a nation is, the higher the cost to attack one of its towns.", "# ", "# This setting is important to mitigate 'annoyance sieges', ", - "# because large nations are disproportionately affected by the mild under-siege costs.", + "# because large nations are disproportionately affected by the mild nation-under-siege costs.", "# Thus without mitigation, small nations could attack larger ones,", "# with no intention of fighting, but just to cheaply disrupt them.", "# ", @@ -762,7 +764,7 @@ public enum ConfigNodes { "# If this setting is 0.1,", "# and a nation home town is attacked,", "# then for every home town in that nation (including the attacked one),", - "# the attack-cost(i.e. warchest) requirement is increased by 10% of the amount it would take to attack that town."); + "# the attack-cost (i.e. warchest) requirement is increased by 10% of the amount it would take to attack that town."); private final String Root; private final String Default; diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java index f9e45d76a..808914425 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java @@ -397,15 +397,19 @@ public static boolean isTrapWarfareMitigationEnabled() { return Settings.getBoolean(ConfigNodes.WAR_SIEGE_SWITCHES_TRAP_WARFARE_MITIGATION_ENABLED); } - public static boolean isAllNationSiegesEnabled() { + public static boolean isPostWarNationImmunityEnabled() { return Settings.getBoolean(ConfigNodes.POST_WAR_NATION_IMMUNITY_ENABLED); } - public static double getAllNationSiegesSiegeImmunityModifier() { - return Settings.getDouble(ConfigNodes.ALL_NATION_SIEGES_SIEGE_IMMUNITY_MODIFIER); + public static double getPostWarNationImmunityMaxHomeDefenceSieges() { + return Settings.getInt(ConfigNodes.POST_WAR_NATION_IMMUNITY_MAX_HOME_DEFENCE_SIEGES); } - public static double getAllNationSiegesHomeTownContributionToAttackCost() { - return Settings.getDouble(ConfigNodes.ALL_NATION_SIEGES_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST); + public static double getPostWarNationImmunityDurationModifier() { + return Settings.getDouble(ConfigNodes.POST_WAR_NATION_IMMUNITY_DURATION_MODIFIER); + } + + public static double getPostWarNationImmunityHomeTownContributionToAttackCost() { + return Settings.getDouble(ConfigNodes.POST_WAR_NATION_IMMUNITY_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST); } } diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java index 1a5585950..60ea36eb3 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java @@ -206,7 +206,7 @@ public static double calculateSiegeCost(Town town) { * town.getTownBlocks().size(); //Increase cost due to nation size - if(SiegeWarSettings.isAllNationSiegesEnabled() + if(SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeWarSettings.getAllNationSiegesHomeTownContributionToAttackCost() > 0 && town.hasNation()) { try { diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java index 4b5f3dbe6..aa0b3612c 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java @@ -30,7 +30,7 @@ public static void setCommonSiegeCompletionValues(Siege siege, siege.clearBannerControlSessions(); siege.setActualEndTime(System.currentTimeMillis()); SiegeWarTimeUtil.activateSiegeImmunityTimers(siege.getTown(), siege); - SiegeWarTownUtil.setTownPvpFlags(siege.getTown(), false); + SiegeWarTownUtil.setPvpFlag(siege.getTown(), false); CosmeticUtil.removeFakeBeacons(siege); /* * The siege is now historical rather than active. diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java index a0968ecad..269e994b7 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java @@ -32,7 +32,7 @@ public static void activateSiegeImmunityTimers(Town town, Siege siege) { TownMetaDataController.setSiegeImmunityEndTime(town, System.currentTimeMillis() + immunityDurationMillis); //Set siege immunity for nation home towns - if(SiegeWarSettings.isAllNationSiegesEnabled() && town.hasNation()) { + if(SiegeWarSettings.isPostWarNationImmunityEnabled() && town.hasNation()) { double homeTownSiegeImmunityDurationDouble = (double)immunityDurationMillis * SiegeWarSettings.getAllNationSiegesSiegeImmunityModifier(); long homeTownSiegeImmunityDurationLong = (long)(homeTownSiegeImmunityDurationDouble + 0.5); long homeTownSiegeImmunityEndTime = System.currentTimeMillis() + homeTownSiegeImmunityDurationLong; diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index 4c55302f1..37b95093b 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -26,27 +26,6 @@ public static void disableTownPVP(Town town) { town.save(); } - /** - * Wrapper method to set pvp flags in a town to the desired - * setting, as well as the nation if All-Nation-Sieges are enabled - * and the town has a nation. - * - * @param town The town to set the flags for. - * @param desiredSetting The value to set pvp and explosions to. - */ - public static void setTownPvpFlags(Town town, boolean desiredSetting) { - - if(SiegeWarSettings.isAllNationSiegesEnabled() && town.hasNation()) { - for(Town nationTown: TownyAPI.getInstance().getTownNationOrNull(town).getTowns()) { - //Only non-peaceful towns are affected by the PVP change - if(!nationTown.isNeutral()) - setPvpFlag(nationTown, desiredSetting); - } - } else { - setPvpFlag(town, desiredSetting); - } - } - /** * Sets pvp flags in a town to the desired setting. * From 846e1828dfccf994bd95b22896d7b4473d8d7891 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Fri, 16 Apr 2021 12:53:45 +0100 Subject: [PATCH 04/39] postwarnationimmunity Cleanup --- .../com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index 37b95093b..f161dadea 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -27,10 +27,10 @@ public static void disableTownPVP(Town town) { } /** - * Sets pvp flags in a town to the desired setting. + * Sets pvp flag in a town to the desired setting. * - * @param town The town to set the flags for. - * @param desiredSetting The value to set pvp and explosions to. + * @param town The town to set the flag for. + * @param desiredSetting The value to set pvp to. */ public static void setPvpFlag(Town town, boolean desiredSetting) { From 8b2afd28f2481a4e723c86a67e791b4ff1d3337e Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Fri, 16 Apr 2021 12:54:12 +0100 Subject: [PATCH 05/39] Removed unused import --- .../java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index f161dadea..19c1b7df4 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -1,7 +1,6 @@ package com.gmail.goosius.siegewar.utils; import com.gmail.goosius.siegewar.settings.SiegeWarSettings; -import com.palmergames.bukkit.towny.TownyAPI; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlockType; From 3749f8d4cdde16ff3b486fad5843a103e60e7d7a Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Fri, 16 Apr 2021 13:12:51 +0100 Subject: [PATCH 06/39] postwarnationimmunity - Added metadata fields --- .../siegewar/metadata/MetaDataUtil.java | 24 +++++++------ .../metadata/NationMetaDataController.java | 36 +++++++++++++++++++ 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/metadata/MetaDataUtil.java b/src/main/java/com/gmail/goosius/siegewar/metadata/MetaDataUtil.java index 883370ed5..eb8aa805f 100644 --- a/src/main/java/com/gmail/goosius/siegewar/metadata/MetaDataUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/metadata/MetaDataUtil.java @@ -1,6 +1,8 @@ package com.gmail.goosius.siegewar.metadata; +import com.palmergames.bukkit.towny.object.Government; import com.palmergames.bukkit.towny.object.Town; +import com.palmergames.bukkit.towny.object.TownyObject; import com.palmergames.bukkit.towny.object.metadata.BooleanDataField; import com.palmergames.bukkit.towny.object.metadata.CustomDataField; import com.palmergames.bukkit.towny.object.metadata.DecimalDataField; @@ -30,15 +32,15 @@ static boolean getBoolean(Town town, BooleanDataField bdf) { return false; } - static long getLong(Town town, LongDataField ldf) { - CustomDataField cdf = town.getMetadata(ldf.getKey()); + static long getLong(TownyObject townyObject, LongDataField ldf) { + CustomDataField cdf = townyObject.getMetadata(ldf.getKey()); if (cdf instanceof LongDataField) return ((LongDataField) cdf).getValue(); return 0l; } - static int getInt(Town town, IntegerDataField idf) { - CustomDataField cdf = town.getMetadata(idf.getKey()); + static int getInt(TownyObject townyObject, IntegerDataField idf) { + CustomDataField cdf = townyObject.getMetadata(idf.getKey()); if (cdf instanceof IntegerDataField) return ((IntegerDataField) cdf).getValue(); return 0; @@ -69,21 +71,21 @@ static void setBoolean(Town town, BooleanDataField bdf, boolean bool) { } } - static void setLong(Town town, LongDataField ldf, long num) { - CustomDataField cdf = town.getMetadata(ldf.getKey()); + static void setLong(TownyObject townyObject, LongDataField ldf, long num) { + CustomDataField cdf = townyObject.getMetadata(ldf.getKey()); if (cdf instanceof LongDataField) { LongDataField value = (LongDataField) cdf; value.setValue(num); - town.save(); + townyObject.save(); } } - - static void setInt(Town town, IntegerDataField idf, int num) { - CustomDataField cdf = town.getMetadata(idf.getKey()); + + static void setInt(TownyObject townyObject, IntegerDataField idf, int num) { + CustomDataField cdf = townyObject.getMetadata(idf.getKey()); if (cdf instanceof IntegerDataField) { IntegerDataField value = (IntegerDataField) cdf; value.setValue(num); - town.save(); + townyObject.save(); } } diff --git a/src/main/java/com/gmail/goosius/siegewar/metadata/NationMetaDataController.java b/src/main/java/com/gmail/goosius/siegewar/metadata/NationMetaDataController.java index 72b598802..7d83ea8bc 100644 --- a/src/main/java/com/gmail/goosius/siegewar/metadata/NationMetaDataController.java +++ b/src/main/java/com/gmail/goosius/siegewar/metadata/NationMetaDataController.java @@ -2,8 +2,11 @@ import com.gmail.goosius.siegewar.SiegeWar; import com.palmergames.bukkit.towny.object.Nation; +import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.metadata.CustomDataField; import com.palmergames.bukkit.towny.object.metadata.IntegerDataField; +import com.palmergames.bukkit.towny.object.metadata.LongDataField; +import com.palmergames.bukkit.towny.object.metadata.StringDataField; public class NationMetaDataController { @SuppressWarnings("unused") @@ -15,6 +18,9 @@ public class NationMetaDataController { townsGained = "siegewar_totaltownsgained", townsLost = "siegewar_totaltownslost"; + private static final LongDataField currentWarStartTime = new LongDataField("siegewar_currentWarStartTime"); + private static final IntegerDataField currentWarNumHomeDefenceSieges = new IntegerDataField("siegewar_currentWarNumHomeDefenceSieges"); + public NationMetaDataController(SiegeWar plugin) { this.plugin = plugin; } @@ -75,4 +81,34 @@ public static void setTotalTownsGained(Nation nation, int num) { public static void setTotalTownsLost(Nation nation, int num) { setIdf(nation, townsLost, num); } + + public static long getCurrentWarStartTime(Nation nation) { + LongDataField ldf = (LongDataField) currentWarStartTime.clone(); + if (nation.hasMeta(ldf.getKey())) + return MetaDataUtil.getLong(nation, ldf); + return 0l; + } + + public static void setCurrentWarStartTime(Nation nation, long num) { + LongDataField ldf = (LongDataField) currentWarStartTime.clone(); + if (nation.hasMeta(ldf.getKey())) + MetaDataUtil.setLong(nation, ldf, num); + else + nation.addMetaData(new LongDataField(currentWarStartTime.getKey(), num)); + } + + public static int getCurrentWarNumHomeDefenceSieges(Nation nation) { + IntegerDataField idf = (IntegerDataField) currentWarNumHomeDefenceSieges.clone(); + if (nation.hasMeta(idf.getKey())) + return MetaDataUtil.getInt(nation, idf); + return 0; + } + + public static void setCurrentWarNumHomeDefenceSieges(Nation nation, int num) { + IntegerDataField idf = (IntegerDataField) currentWarNumHomeDefenceSieges.clone(); + if (nation.hasMeta(idf.getKey())) + MetaDataUtil.setInt(nation, idf, num); + else + nation.addMetaData(new IntegerDataField(currentWarNumHomeDefenceSieges.getKey(), num)); + } } From e2f1f1e561bcff285d11ad70aee1c8f7fc0267c4 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Fri, 16 Apr 2021 17:47:03 +0100 Subject: [PATCH 07/39] Post war nation immunity Refactor to a more dynamic and stable approach --- .../goosius/siegewar/SiegeController.java | 19 ++++- .../metadata/NationMetaDataController.java | 33 +++----- .../metadata/SiegeMetaDataController.java | 43 ++++++++++- .../gmail/goosius/siegewar/objects/Siege.java | 19 +++++ .../utils/SiegeWarSiegeCompletionUtil.java | 4 +- .../siegewar/utils/SiegeWarTimeUtil.java | 34 -------- .../siegewar/utils/SiegeWarTownUtil.java | 77 ++++++++++++++++++- 7 files changed, 167 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index dbf635da0..dd233a2cc 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -35,7 +35,6 @@ import com.gmail.goosius.siegewar.metadata.SiegeMetaDataController; import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.utils.SiegeWarMoneyUtil; -import com.gmail.goosius.siegewar.utils.SiegeWarTimeUtil; import com.gmail.goosius.siegewar.utils.SiegeWarTownUtil; import com.palmergames.bukkit.towny.TownyAPI; import com.palmergames.bukkit.towny.TownyUniverse; @@ -91,6 +90,7 @@ public static void saveSiege(Siege siege) { SiegeMetaDataController.setEndTime(town, siege.getScheduledEndTime()); SiegeMetaDataController.setActualEndTime(town, siege.getActualEndTime()); SiegeMetaDataController.setAttackerSiegeContributors(town, siege.getAttackerSiegeContributors()); + SiegeMetaDataController.setHomeDefenceSiegeContributors(town, siege.getHomeDefenceSiegeContributors()); town.save(); } @@ -228,6 +228,9 @@ public static boolean loadSiege(Siege siege) { siege.setActualEndTime(SiegeMetaDataController.getActualEndTime(town)); siege.setAttackerSiegeContributors(SiegeMetaDataController.getAttackerSiegeContributors(town)); + + siege.setHomeDefenceSiegeContributors(SiegeMetaDataController.getHomeDefenceSiegeContributors(town)); + return true; } @@ -236,7 +239,7 @@ public static void removeSiege(Siege siege, SiegeSide refundSideIfSiegeIsActive) //If siege is active, initiate siege immunity for town, and return war chest if(siege.getStatus().isActive()) { siege.setActualEndTime(System.currentTimeMillis()); - SiegeWarTimeUtil.activateSiegeImmunityTimers(siege.getTown(), siege); + SiegeWarTownUtil.grantSiegeImmunityAfterEndedSiege(siege.getTown(), siege); //Return warchest only if siege is not revolt if(siege.getSiegeType() != SiegeType.REVOLT) { @@ -468,7 +471,7 @@ public static void startSiege(Block bannerBlock, SiegeController.setSiege(targetTown, true); SiegeController.putTownInSiegeMap(targetTown, siege); - //Set town to true, potentially set the town's nation's towns as well. + //Set pvp to true in the besieged town SiegeWarTownUtil.setPvpFlag(targetTown, true); //Send global message; @@ -579,4 +582,14 @@ private static void sendGlobalSiegeStartMessage(Siege siege) throws NotRegistere break; } } + + public static boolean doesNationHaveAnyHomeDefenceContributionsInActiveSieges(Nation nation) { + for(Siege siege: townSiegeMap.values()) { + if(siege.getStatus().isActive() + && siege.getHomeDefenceSiegeContributors().containsKey(nation.getUUID().toString())) { + return true; + } + } + return false; + } } diff --git a/src/main/java/com/gmail/goosius/siegewar/metadata/NationMetaDataController.java b/src/main/java/com/gmail/goosius/siegewar/metadata/NationMetaDataController.java index 7d83ea8bc..fda38b579 100644 --- a/src/main/java/com/gmail/goosius/siegewar/metadata/NationMetaDataController.java +++ b/src/main/java/com/gmail/goosius/siegewar/metadata/NationMetaDataController.java @@ -2,11 +2,9 @@ import com.gmail.goosius.siegewar.SiegeWar; import com.palmergames.bukkit.towny.object.Nation; -import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.metadata.CustomDataField; import com.palmergames.bukkit.towny.object.metadata.IntegerDataField; import com.palmergames.bukkit.towny.object.metadata.LongDataField; -import com.palmergames.bukkit.towny.object.metadata.StringDataField; public class NationMetaDataController { @SuppressWarnings("unused") @@ -18,8 +16,7 @@ public class NationMetaDataController { townsGained = "siegewar_totaltownsgained", townsLost = "siegewar_totaltownslost"; - private static final LongDataField currentWarStartTime = new LongDataField("siegewar_currentWarStartTime"); - private static final IntegerDataField currentWarNumHomeDefenceSieges = new IntegerDataField("siegewar_currentWarNumHomeDefenceSieges"); + private static final LongDataField pendingSiegeImmunityMillis = new LongDataField("siegewar_pendingSiegeImmunityMillis"); public NationMetaDataController(SiegeWar plugin) { this.plugin = plugin; @@ -82,33 +79,25 @@ public static void setTotalTownsLost(Nation nation, int num) { setIdf(nation, townsLost, num); } - public static long getCurrentWarStartTime(Nation nation) { - LongDataField ldf = (LongDataField) currentWarStartTime.clone(); + public static long getPendingSiegeImmunityMillis(Nation nation) { + LongDataField ldf = (LongDataField) pendingSiegeImmunityMillis.clone(); if (nation.hasMeta(ldf.getKey())) return MetaDataUtil.getLong(nation, ldf); - return 0l; + return 0L; } - public static void setCurrentWarStartTime(Nation nation, long num) { - LongDataField ldf = (LongDataField) currentWarStartTime.clone(); + public static void setPendingSiegeImmunityMillis(Nation nation, long num) { + LongDataField ldf = (LongDataField) pendingSiegeImmunityMillis.clone(); if (nation.hasMeta(ldf.getKey())) MetaDataUtil.setLong(nation, ldf, num); else - nation.addMetaData(new LongDataField(currentWarStartTime.getKey(), num)); + nation.addMetaData(new LongDataField(pendingSiegeImmunityMillis.getKey(), num)); } - public static int getCurrentWarNumHomeDefenceSieges(Nation nation) { - IntegerDataField idf = (IntegerDataField) currentWarNumHomeDefenceSieges.clone(); - if (nation.hasMeta(idf.getKey())) - return MetaDataUtil.getInt(nation, idf); - return 0; + public static void removePendingSiegeImmunityMillis(Nation nation) { + LongDataField ldf = (LongDataField) pendingSiegeImmunityMillis.clone(); + if (nation.hasMeta(ldf.getKey())) + nation.removeMetaData(ldf); } - public static void setCurrentWarNumHomeDefenceSieges(Nation nation, int num) { - IntegerDataField idf = (IntegerDataField) currentWarNumHomeDefenceSieges.clone(); - if (nation.hasMeta(idf.getKey())) - MetaDataUtil.setInt(nation, idf, num); - else - nation.addMetaData(new IntegerDataField(currentWarNumHomeDefenceSieges.getKey(), num)); - } } diff --git a/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java b/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java index d3f6d2169..f81db6196 100644 --- a/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java +++ b/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java @@ -49,7 +49,8 @@ public class SiegeMetaDataController { private static LongDataField endTime = new LongDataField("siegewar_endTime", 0l); private static LongDataField actualEndTime = new LongDataField("siegewar_actualEndTime", 0l); private static StringDataField attackerSiegeContributors = new StringDataField("siegewar_attackerSiegeContributors", ""); - + private static StringDataField homeDefenceSiegeContributors = new StringDataField("siegewar_homeDefenceSiegeContributors", ""); + public SiegeMetaDataController(SiegeWar plugin) { this.plugin = plugin; } @@ -360,6 +361,27 @@ public static Map getAttackerSiegeContributors(Town town) { } } + public static Map getHomeDefenceSiegeContributors(Town town) { + StringDataField sdf = (StringDataField) homeDefenceSiegeContributors .clone(); + + String dataAsString = null; + if (town.hasMeta(sdf.getKey())) + dataAsString = MetaDataUtil.getString(town, sdf); + + if(dataAsString == null || dataAsString.length() == 0) { + return new HashMap<>(); + } else { + Map residentContributionsMap = new HashMap<>(); + String[] residentContributionDataEntries = dataAsString.split(","); + String[] residentContributionDataPair; + for(String residentContributionDataEntry: residentContributionDataEntries) { + residentContributionDataPair = residentContributionDataEntry.split(":"); + residentContributionsMap.put(residentContributionDataPair[0], Integer.parseInt(residentContributionDataPair[1])); + } + return residentContributionsMap; + } + } + public static void setAttackerSiegeContributors(Town town, Map contributorsMap) { StringBuilder mapAsStringBuilder = new StringBuilder(); boolean firstEntry = true; @@ -378,4 +400,23 @@ public static void setAttackerSiegeContributors(Town town, Map c else town.addMetaData(new StringDataField("siegewar_attackerSiegeContributors", mapAsStringBuilder.toString())); } + + public static void setHomeDefenceSiegeContributors(Town town, Map contributorsMap) { + StringBuilder mapAsStringBuilder = new StringBuilder(); + boolean firstEntry = true; + for(Map.Entry contributorEntry: contributorsMap.entrySet()) { + if(firstEntry) { + firstEntry = false; + } else { + mapAsStringBuilder.append(","); + } + mapAsStringBuilder.append(contributorEntry.getKey()).append(":").append(contributorEntry.getValue()); + } + + StringDataField sdf = (StringDataField) homeDefenceSiegeContributors .clone(); + if (town.hasMeta(sdf.getKey())) + MetaDataUtil.setString(town, sdf, mapAsStringBuilder.toString()); + else + town.addMetaData(new StringDataField(homeDefenceSiegeContributors.getKey(), mapAsStringBuilder.toString())); + } } diff --git a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java index f07bfce27..4cf32d7ef 100644 --- a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java +++ b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java @@ -62,6 +62,7 @@ public class Siege { private int defenderBattlePoints; private Set attackerBattleContributors; //UUID's of attackers who contributed during the current battle private Map attackerSiegeContributors; //UUID:numContributions map of attackers who contributed during current siege + private Map homeDefenceContributors; //UUID:numContributions map of nations who contributed as home defenders during current siege public Siege(Town town) { this.town = town; @@ -82,6 +83,7 @@ public Siege(Town town) { defenderBattlePoints = 0; attackerBattleContributors = new HashSet<>(); attackerSiegeContributors = new HashMap<>(); + homeDefenceContributors = new HashMap<>(); } public Town getTown() { @@ -400,6 +402,7 @@ public void setAttackerBattleContributors(Set attackerBattleContributors public void clearAttackerBattleContributors() { attackerBattleContributors.clear(); } + public Map getAttackerSiegeContributors() { return attackerSiegeContributors; } @@ -408,6 +411,14 @@ public void setAttackerSiegeContributors(Map attackerSiegeContr this.attackerSiegeContributors = attackerSiegeContributors; } + public Map getHomeDefenceSiegeContributors() { + return homeDefenceContributors; + } + + public void setHomeDefenceSiegeContributors(Map homeDefenceContributions) { + this.homeDefenceContributors = homeDefenceContributions; + } + public void registerAttackerBattleContributorsFromBannerControl() { for(Resident resident: bannerControllingResidents) { attackerBattleContributors.add(resident.getUUID().toString()); @@ -445,4 +456,12 @@ public void setSiegeType(SiegeType siegeType) { throw new RuntimeException("SiegeType cannot be null"); this.siegeType = siegeType; } + + public int getTotalBattles() { + int result = 0; + for(int numBattlesFromContributor: homeDefenceContributors.values()) { + result += numBattlesFromContributor; + } + return result; + } } \ No newline at end of file diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java index aa0b3612c..3252f83d8 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java @@ -29,7 +29,8 @@ public static void setCommonSiegeCompletionValues(Siege siege, siege.clearBannerControllingResidents(); siege.clearBannerControlSessions(); siege.setActualEndTime(System.currentTimeMillis()); - SiegeWarTimeUtil.activateSiegeImmunityTimers(siege.getTown(), siege); + SiegeWarTownUtil.grantSiegeImmunityAfterEndedSiege(siege.getTown(), siege); + SiegeWarTownUtil.setPvpFlag(siege.getTown(), false); CosmeticUtil.removeFakeBeacons(siege); /* @@ -42,6 +43,7 @@ public static void setCommonSiegeCompletionValues(Siege siege, */ siege.setAttacker(siege.getAttackingNationIfPossibleElseTown()); siege.setDefender(siege.getDefendingNationIfPossibleElseTown()); + //Save to db SiegeController.saveSiege(siege); } diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java index 269e994b7..72309fed7 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java @@ -1,9 +1,7 @@ package com.gmail.goosius.siegewar.utils; import com.gmail.goosius.siegewar.metadata.TownMetaDataController; -import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.settings.SiegeWarSettings; -import com.palmergames.bukkit.towny.TownyAPI; import com.palmergames.bukkit.towny.object.Town; /** @@ -13,38 +11,6 @@ */ public class SiegeWarTimeUtil { - /** - * Activate the siege immunity timers after a siege ends - * - The besieged town always gets it - * - Home nation towns might also get it (if all-nation-sieges are enabled) - * - * If a town siege immunity timer is active, the town cannot be attacked. - * Note however that siege immunity does not prevent the mayor starting a revolt siege. - * - * @param town the town under siege - * @param siege the siege which was previously active - */ - public static void activateSiegeImmunityTimers(Town town, Siege siege) { - //Set siege immunity for town - double siegeDuration = siege.getActualEndTime() - siege.getStartTime(); - double immunityDurationMillisDouble = siegeDuration * SiegeWarSettings.getWarSiegeSiegeImmunityTimeModifier(); - long immunityDurationMillis = (long)(immunityDurationMillisDouble + 0.5); - TownMetaDataController.setSiegeImmunityEndTime(town, System.currentTimeMillis() + immunityDurationMillis); - - //Set siege immunity for nation home towns - if(SiegeWarSettings.isPostWarNationImmunityEnabled() && town.hasNation()) { - double homeTownSiegeImmunityDurationDouble = (double)immunityDurationMillis * SiegeWarSettings.getAllNationSiegesSiegeImmunityModifier(); - long homeTownSiegeImmunityDurationLong = (long)(homeTownSiegeImmunityDurationDouble + 0.5); - long homeTownSiegeImmunityEndTime = System.currentTimeMillis() + homeTownSiegeImmunityDurationLong; - - for(Town nationTown: TownyAPI.getInstance().getTownNationOrNull(town).getTowns()) { - if(TownMetaDataController.getSiegeImmunityEndTime(nationTown) < homeTownSiegeImmunityEndTime) { - TownMetaDataController.setSiegeImmunityEndTime(nationTown, homeTownSiegeImmunityEndTime); - } - } - } - } - /** * Activate the revolt immunity timer for a town * diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index 19c1b7df4..f9ce38f95 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -1,10 +1,19 @@ package com.gmail.goosius.siegewar.utils; +import com.gmail.goosius.siegewar.SiegeController; +import com.gmail.goosius.siegewar.enums.SiegeType; +import com.gmail.goosius.siegewar.metadata.NationMetaDataController; +import com.gmail.goosius.siegewar.metadata.TownMetaDataController; +import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.settings.SiegeWarSettings; +import com.palmergames.bukkit.towny.TownyUniverse; +import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownBlock; import com.palmergames.bukkit.towny.object.TownBlockType; +import java.util.Map; + /** * Util class containing methods related to town flags/permssions. */ @@ -37,5 +46,71 @@ public static void setPvpFlag(Town town, boolean desiredSetting) { town.getPermissions().pvp = desiredSetting; town.save(); } - } + } + + /** + * The siege ended. + * + * 1. Grant siege immunity to the town which was besieged. + * 2. If the town was the defender, + * grant siege immunity to any nations who were the home nation of the town during the siege + * + * @param town the town which was besieged + * @param siege the siege + */ + public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { + //Grant siege immunity to town + double siegeDurationMillis = siege.getActualEndTime() - siege.getStartTime(); + double immunityDurationMillisDouble = siegeDurationMillis * SiegeWarSettings.getWarSiegeSiegeImmunityTimeModifier(); + long immunityDurationMillis = (long)(immunityDurationMillisDouble + 0.5); + TownMetaDataController.setSiegeImmunityEndTime(town, System.currentTimeMillis() + immunityDurationMillis); + town.save(); + + /* + * If the town was the defender, + * Grant siege immunity to any nations who were the home nation of the town during the siege + */ + if(SiegeWarSettings.isPostWarNationImmunityEnabled() + && (siege.getSiegeType() == SiegeType.CONQUEST || siege.getSiegeType() == SiegeType.SUPPRESSION)) { + int totalBattles = siege.getTotalBattles(); + double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getPostWarNationImmunityDurationModifier(); + int numBattlesFoughtByNation; + double siegeImmunityRewardInMillis; + for(Map.Entry nationEntry: siege.getHomeDefenceSiegeContributors().entrySet()) { + if(!nationEntry.getKey().equals("TOWN") && !nationEntry.getKey().equals("NOBODY")) { + Nation nation = TownyUniverse.getInstance().getNation(nationEntry.getKey()); + if(nation != null) { + numBattlesFoughtByNation = nationEntry.getValue(); + siegeImmunityRewardInMillis = immunityRewardDurationPerBattleInMillis * numBattlesFoughtByNation; + grantSiegeImmunityToNation(nation, siegeImmunityRewardInMillis); + } + } + } + } + } + + private static void grantSiegeImmunityToNation(Nation nation, double siegeImmunityMillis) { + /* + * If the nation has contributions in active sieges, make the immunity pending. + * (i.e. wait until those sieges end until it is granted) + * + * Otherwise, grant the immunity immediately. + */ + if(SiegeController.doesNationHaveAnyHomeDefenceContributionsInActiveSieges(nation)) { + long pendingSiegeImmunityMillis = NationMetaDataController.getPendingSiegeImmunityMillis(nation); + pendingSiegeImmunityMillis += siegeImmunityMillis; + NationMetaDataController.setPendingSiegeImmunityMillis(nation, pendingSiegeImmunityMillis); + nation.save(); + } else { + long pendingSiegeImmunityMillis = NationMetaDataController.getPendingSiegeImmunityMillis(nation); + long totalSiegeImmunityMillis = pendingSiegeImmunityMillis + (long)siegeImmunityMillis; + + for(Town nationTown: nation.getTowns()) { + if(TownMetaDataController.getSiegeImmunityEndTime(nationTown) < siegeImmunityMillis) { + TownMetaDataController.setSiegeImmunityEndTime(nationTown, totalSiegeImmunityMillis); + nationTown.save(); + } + } + } + } } \ No newline at end of file From 2b67a4e315cc198e62d18d0a0e06aca025d5ab13 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Fri, 16 Apr 2021 19:59:10 +0100 Subject: [PATCH 08/39] Cleanup --- .../goosius/siegewar/SiegeController.java | 6 +-- .../metadata/SiegeMetaDataController.java | 26 ++++----- .../gmail/goosius/siegewar/objects/Siege.java | 53 +++++++++++++++---- .../utils/SiegeWarBattleSessionUtil.java | 19 +++++-- .../siegewar/utils/SiegeWarTownUtil.java | 11 ++-- 5 files changed, 81 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index dd233a2cc..c8adadf16 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -90,7 +90,7 @@ public static void saveSiege(Siege siege) { SiegeMetaDataController.setEndTime(town, siege.getScheduledEndTime()); SiegeMetaDataController.setActualEndTime(town, siege.getActualEndTime()); SiegeMetaDataController.setAttackerSiegeContributors(town, siege.getAttackerSiegeContributors()); - SiegeMetaDataController.setHomeDefenceSiegeContributors(town, siege.getHomeDefenceSiegeContributors()); + SiegeMetaDataController.setTownDefenceHomeNations(town, siege.getTownDefenceHomeNations()); town.save(); } @@ -229,7 +229,7 @@ public static boolean loadSiege(Siege siege) { siege.setAttackerSiegeContributors(SiegeMetaDataController.getAttackerSiegeContributors(town)); - siege.setHomeDefenceSiegeContributors(SiegeMetaDataController.getHomeDefenceSiegeContributors(town)); + siege.setTownDefenceHomeNations(SiegeMetaDataController.getTownDefenceHomeNations(town)); return true; } @@ -586,7 +586,7 @@ private static void sendGlobalSiegeStartMessage(Siege siege) throws NotRegistere public static boolean doesNationHaveAnyHomeDefenceContributionsInActiveSieges(Nation nation) { for(Siege siege: townSiegeMap.values()) { if(siege.getStatus().isActive() - && siege.getHomeDefenceSiegeContributors().containsKey(nation.getUUID().toString())) { + && siege.getTownDefenceHomeNations().containsKey(nation.getUUID().toString())) { return true; } } diff --git a/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java b/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java index f81db6196..0f2809419 100644 --- a/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java +++ b/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java @@ -49,7 +49,7 @@ public class SiegeMetaDataController { private static LongDataField endTime = new LongDataField("siegewar_endTime", 0l); private static LongDataField actualEndTime = new LongDataField("siegewar_actualEndTime", 0l); private static StringDataField attackerSiegeContributors = new StringDataField("siegewar_attackerSiegeContributors", ""); - private static StringDataField homeDefenceSiegeContributors = new StringDataField("siegewar_homeDefenceSiegeContributors", ""); + private static StringDataField townDefenceHomeNations = new StringDataField("siegewar_townDefenceHomeNations", ""); public SiegeMetaDataController(SiegeWar plugin) { this.plugin = plugin; @@ -361,8 +361,8 @@ public static Map getAttackerSiegeContributors(Town town) { } } - public static Map getHomeDefenceSiegeContributors(Town town) { - StringDataField sdf = (StringDataField) homeDefenceSiegeContributors .clone(); + public static Map getTownDefenceHomeNations(Town town) { + StringDataField sdf = (StringDataField) townDefenceHomeNations.clone(); String dataAsString = null; if (town.hasMeta(sdf.getKey())) @@ -371,14 +371,14 @@ public static Map getHomeDefenceSiegeContributors(Town town) { if(dataAsString == null || dataAsString.length() == 0) { return new HashMap<>(); } else { - Map residentContributionsMap = new HashMap<>(); - String[] residentContributionDataEntries = dataAsString.split(","); - String[] residentContributionDataPair; - for(String residentContributionDataEntry: residentContributionDataEntries) { - residentContributionDataPair = residentContributionDataEntry.split(":"); - residentContributionsMap.put(residentContributionDataPair[0], Integer.parseInt(residentContributionDataPair[1])); + Map contributionsMap = new HashMap<>(); + String[] contributionDataEntries = dataAsString.split(","); + String[] contributionDataPair; + for(String contributionDataEntry: contributionDataEntries) { + contributionDataPair = contributionDataEntry.split(":"); + contributionsMap.put(contributionDataPair[0], Integer.parseInt(contributionDataPair[1])); } - return residentContributionsMap; + return contributionsMap; } } @@ -401,7 +401,7 @@ public static void setAttackerSiegeContributors(Town town, Map c town.addMetaData(new StringDataField("siegewar_attackerSiegeContributors", mapAsStringBuilder.toString())); } - public static void setHomeDefenceSiegeContributors(Town town, Map contributorsMap) { + public static void setTownDefenceHomeNations(Town town, Map contributorsMap) { StringBuilder mapAsStringBuilder = new StringBuilder(); boolean firstEntry = true; for(Map.Entry contributorEntry: contributorsMap.entrySet()) { @@ -413,10 +413,10 @@ public static void setHomeDefenceSiegeContributors(Town town, Map attackerBattleContributors; //UUID's of attackers who contributed during the current battle private Map attackerSiegeContributors; //UUID:numContributions map of attackers who contributed during current siege - private Map homeDefenceContributors; //UUID:numContributions map of nations who contributed as home defenders during current siege + private Map townDefenceHomeNations; //UUID:numBattleSessions map of nations who served as the home nation of the town during the siege public Siege(Town town) { this.town = town; @@ -83,7 +83,7 @@ public Siege(Town town) { defenderBattlePoints = 0; attackerBattleContributors = new HashSet<>(); attackerSiegeContributors = new HashMap<>(); - homeDefenceContributors = new HashMap<>(); + townDefenceHomeNations = new HashMap<>(); } public Town getTown() { @@ -411,12 +411,12 @@ public void setAttackerSiegeContributors(Map attackerSiegeContr this.attackerSiegeContributors = attackerSiegeContributors; } - public Map getHomeDefenceSiegeContributors() { - return homeDefenceContributors; + public Map getTownDefenceHomeNations() { + return townDefenceHomeNations; } - public void setHomeDefenceSiegeContributors(Map homeDefenceContributions) { - this.homeDefenceContributors = homeDefenceContributions; + public void setTownDefenceHomeNations(Map townDefenceHomeNations) { + this.townDefenceHomeNations = townDefenceHomeNations; } public void registerAttackerBattleContributorsFromBannerControl() { @@ -457,10 +457,45 @@ public void setSiegeType(SiegeType siegeType) { this.siegeType = siegeType; } - public int getTotalBattles() { + /** + * Record who was the home nation of the town during a town defence battle session + * + * @throws NotRegisteredException + */ + public void recordTownDefenceHomeNation() throws NotRegisteredException { + //Identify key + String contributorKey; + if(town.hasNation()) + contributorKey = town.getNation().getUUID().toString(); + else + contributorKey = "NO_HOME_NATION"; + + //Record battle session contribution + if(townDefenceHomeNations.containsKey(contributorKey)) { + int numBattleSessions = townDefenceHomeNations.get(contributorKey); + numBattleSessions++; + townDefenceHomeNations.put(contributorKey, numBattleSessions); + } else { + townDefenceHomeNations.put(contributorKey, 1); + } + } + + /** + * Returns true if this siege is a "town defence" + * + * A town defence is a siege where the town itself is being attacked, + * rather than a siege where the town occupier is being attacked + * + * @return true if the siege is a town defence + */ + public boolean isTownDefence() { + return siegeType == SiegeType.CONQUEST || siegeType == SiegeType.SUPPRESSION; + } + + public int getTotalTownDefenceBattles() { int result = 0; - for(int numBattlesFromContributor: homeDefenceContributors.values()) { - result += numBattlesFromContributor; + for(int homeNationContribution: townDefenceHomeNations.values()) { + result += homeNationContribution; } return result; } 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 942dbf9cd..857881224 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java @@ -40,12 +40,25 @@ public static void evaluateBattleSessions() { //Schedule next session scheduleNextBattleSession(); - //Gather the results of all active battles, then end them + /* + * Gather the results of all battles + * End any active battles + */ Map battleResults = new HashMap<>(); for (Siege siege : SiegeController.getSieges()) { try { - if (siege.getStatus() == SiegeStatus.IN_PROGRESS - && (siege.getAttackerBattlePoints() > 0 || siege.getDefenderBattlePoints() > 0)) { + if (siege.getStatus() == SiegeStatus.IN_PROGRESS) { + //Record home nation if this is a town defence siege + if(siege.isTownDefence()) + siege.recordTownDefenceHomeNation(); + + //Continue to next siege if there were no battle points + if(siege.getAttackerBattlePoints() == 0 || siege.getDefenderBattlePoints() == 0) { + if(siege.isTownDefence()) + SiegeController.saveSiege(siege); + continue; + } + //Calculate result int battlePointsOfWinner; if (siege.getAttackerBattlePoints() > siege.getDefenderBattlePoints()) { diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index f9ce38f95..221661950 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -67,17 +67,16 @@ public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { town.save(); /* - * If the town was the defender, + * If this was a town defence siege, * Grant siege immunity to any nations who were the home nation of the town during the siege */ - if(SiegeWarSettings.isPostWarNationImmunityEnabled() - && (siege.getSiegeType() == SiegeType.CONQUEST || siege.getSiegeType() == SiegeType.SUPPRESSION)) { - int totalBattles = siege.getTotalBattles(); + if(SiegeWarSettings.isPostWarNationImmunityEnabled() && siege.isTownDefence()) { + int totalBattles = siege.getTotalTownDefenceBattles(); double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getPostWarNationImmunityDurationModifier(); int numBattlesFoughtByNation; double siegeImmunityRewardInMillis; - for(Map.Entry nationEntry: siege.getHomeDefenceSiegeContributors().entrySet()) { - if(!nationEntry.getKey().equals("TOWN") && !nationEntry.getKey().equals("NOBODY")) { + for(Map.Entry nationEntry: siege.getTownDefenceHomeNations().entrySet()) { + if(!nationEntry.getKey().equals("NO_HOME_NATION")) { Nation nation = TownyUniverse.getInstance().getNation(nationEntry.getKey()); if(nation != null) { numBattlesFoughtByNation = nationEntry.getValue(); From 3d8b65b999f1a9ce1052c93cce51ea3df9405cd9 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Mon, 19 Apr 2021 21:43:22 +0100 Subject: [PATCH 09/39] Cleanup --- .../com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java index 60ea36eb3..45b466f19 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java @@ -207,14 +207,14 @@ public static double calculateSiegeCost(Town town) { //Increase cost due to nation size if(SiegeWarSettings.isPostWarNationImmunityEnabled() - && SiegeWarSettings.getAllNationSiegesHomeTownContributionToAttackCost() > 0 + && SiegeWarSettings.getPostWarNationImmunityHomeTownContributionToAttackCost() > 0 && town.hasNation()) { try { Nation nation = town.getNation(); for (Town nationHomeTown : nation.getTowns()) { cost += SiegeWarSettings.getWarSiegeAttackerCostUpFrontPerPlot() * nationHomeTown.getTownBlocks().size() - * SiegeWarSettings.getAllNationSiegesHomeTownContributionToAttackCost(); + * SiegeWarSettings.getPostWarNationImmunityHomeTownContributionToAttackCost(); } } catch (NotRegisteredException ignored) {} } From 03e7b9c97e6569ccaf792821b625d96523627a6c Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Mon, 19 Apr 2021 22:26:23 +0100 Subject: [PATCH 10/39] Added missing validation --- .../goosius/siegewar/SiegeController.java | 19 +++++++++++++++++++ .../siegewar/playeractions/PlaceBlock.java | 17 ++++++++++++----- src/main/resources/english.yml | 6 +++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index c8adadf16..bd282803c 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -410,6 +410,25 @@ public static boolean isAnyHomeTownASiegeDefender(Town town) { return false; } + /** + * This method returns the number of active home-town defences sieges, + * which the nation is involved in. + * + * @param nation the nation to check + * @return the number of home defences sieges + */ + public static int getNumActiveHomeDefenceSieges(Nation nation) { + int result = 0; + for(Siege siege: SiegeController.getSieges()) { + if((siege.getSiegeType() == SiegeType.CONQUEST || siege.getSiegeType() == SiegeType.SUPPRESSION) + && siege.getStatus().isActive() + && siege.getDefendingNationIfPossibleElseTown() == nation) { + result++; + } + } + return result; + } + /** * This method returns true * - One (or more) of the nation's home towns is a siege defender diff --git a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java index fbc6712ae..79c620a43 100644 --- a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java +++ b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java @@ -261,11 +261,6 @@ private static synchronized void evaluateStartNewSiegeAttempt(Player player, if(SiegeWarBlockUtil.isSupportBlockUnstable(bannerBlock)) throw new TownyException(Translation.of("msg_err_siege_war_banner_support_block_not_stable")); - if (SiegeWarSettings.isPostWarNationImmunityEnabled() - && SiegeController.isAnyHomeTownASiegeDefender(nearbyTown)) { - throw new TownyException(Translation.of("msg_err_cannot_start_siege_because_towns_home_nation_has_besieged_town")); - } - if (residentsTown == nearbyTown) { //Revolt siege StartRevoltSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); @@ -286,6 +281,12 @@ private static synchronized void evaluateStartNewSiegeAttempt(Player player, Nation occupierOfNearbyTown = TownOccupationController.getTownOccupier(nearbyTown); if (residentsNation == occupierOfNearbyTown) { //Suppression siege + if (SiegeWarSettings.isPostWarNationImmunityEnabled() + && nearbyTown.hasNation() + && SiegeController.getNumActiveHomeDefenceSieges(nearbyTown.getNation()) > SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges()) { + throw new TownyException(Translation.of("msg_err_target_nation_has_too_many_home_defences")); + } + StartSuppressionSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); } else { //Liberation siege @@ -293,6 +294,12 @@ private static synchronized void evaluateStartNewSiegeAttempt(Player player, } } else { //Conquest siege + if (SiegeWarSettings.isPostWarNationImmunityEnabled() + && nearbyTown.hasNation() + && SiegeController.getNumActiveHomeDefenceSieges(nearbyTown.getNation()) > SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges()) { + throw new TownyException(Translation.of("msg_err_target_nation_has_too_many_home_defences")); + } + StartConquestSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); } } diff --git a/src/main/resources/english.yml b/src/main/resources/english.yml index 466003b79..d3b30b6ab 100644 --- a/src/main/resources/english.yml +++ b/src/main/resources/english.yml @@ -428,4 +428,8 @@ msg_err_peaceful_town_cannot_move_homeblock: "&cPeaceful towns cannot move their # Homeblock move restrictions msg_err_besieged_town_cannot_move_homeblock: "&cBesieged towns cannot move their homeblocks." -msg_err_occupied_town_cannot_move_homeblock: "&cOccupied towns cannot move their homeblocks." \ No newline at end of file +msg_err_occupied_town_cannot_move_homeblock: "&cOccupied towns cannot move their homeblocks." + + + +msg_err_target_nation_has_too_many_home_defences: 'blyurg' \ No newline at end of file From 689b7ecfe644558b8081463db32fe76c64153947 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Tue, 20 Apr 2021 14:30:34 +0100 Subject: [PATCH 11/39] Cleanup --- .../listeners/SiegeWarTownEventListener.java | 8 -------- .../goosius/siegewar/playeractions/PlaceBlock.java | 4 ++-- src/main/resources/english.yml | 11 +++++------ src/main/resources/french.yml | 13 ++++++++----- 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java index 9852956f6..d61061da0 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java @@ -130,14 +130,6 @@ public void onTownTogglePVP(TownTogglePVPEvent event) { event.setCancelled(true); return; } - - //Is the town affected by an all-nation-siege - if(SiegeWarSettings.isPostWarNationImmunityEnabled() - && SiegeController.isAnyHomeTownASiegeDefender(event.getTown())) { - event.setCancellationMsg(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_toggle_pvp")); - event.setCancelled(true); - return; - } } } } diff --git a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java index 79c620a43..bf255fb26 100644 --- a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java +++ b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java @@ -284,7 +284,7 @@ private static synchronized void evaluateStartNewSiegeAttempt(Player player, if (SiegeWarSettings.isPostWarNationImmunityEnabled() && nearbyTown.hasNation() && SiegeController.getNumActiveHomeDefenceSieges(nearbyTown.getNation()) > SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges()) { - throw new TownyException(Translation.of("msg_err_target_nation_has_too_many_home_defences")); + throw new TownyException(Translation.of("msg_err_cannot_start_siege_target_nation_has_too_many_home_defences", SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges())); } StartSuppressionSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); @@ -297,7 +297,7 @@ private static synchronized void evaluateStartNewSiegeAttempt(Player player, if (SiegeWarSettings.isPostWarNationImmunityEnabled() && nearbyTown.hasNation() && SiegeController.getNumActiveHomeDefenceSieges(nearbyTown.getNation()) > SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges()) { - throw new TownyException(Translation.of("msg_err_target_nation_has_too_many_home_defences")); + throw new TownyException(Translation.of("msg_err_cannot_start_siege_target_nation_has_too_many_home_defences", SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges())); } StartConquestSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); diff --git a/src/main/resources/english.yml b/src/main/resources/english.yml index d3b30b6ab..8a8c29f9b 100644 --- a/src/main/resources/english.yml +++ b/src/main/resources/english.yml @@ -1,5 +1,5 @@ name: SiegeWar -version: 0.18 +version: 0.19 language: english author: Goosius website: 'http://townyadvanced.github.io/' @@ -411,13 +411,11 @@ status_nation_plunder_stats: '&2Town Plunder History - Gains/Losses: &a%d&2/&a%d #Siege effects msg_err_siege_war_cannot_spawn_into_siegezone_or_besieged_town: '&cOnly town residents can spawn into a besieged town or siege zone.' -#All-Nation-Sieges +#Post-War Nation Immunity msg_err_siege_affected_home_nation_cannot_recruit: "&cThe nation cannot add new towns, because one of its home towns is under siege attack." -msg_err_siege_affected_home_nation_town_cannot_toggle_pvp: "&cCannot toggle PVP, because one of your nation's home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_recruit: "&cThe town cannot add new residents, because one of its nation's home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_claim: "&cCannot claim land, because one of your nation's home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_unclaim: "&cCannot unclaim land, because one of your nation's home towns is under siege attack." -msg_err_cannot_start_siege_because_towns_home_nation_has_besieged_town: "&cCannot start siege on this nation town, because one of its nation's home towns is already under siege attack." # Added in 0.17 @@ -430,6 +428,7 @@ msg_err_peaceful_town_cannot_move_homeblock: "&cPeaceful towns cannot move their msg_err_besieged_town_cannot_move_homeblock: "&cBesieged towns cannot move their homeblocks." msg_err_occupied_town_cannot_move_homeblock: "&cOccupied towns cannot move their homeblocks." +# Added in 0.19 - -msg_err_target_nation_has_too_many_home_defences: 'blyurg' \ No newline at end of file +#Post-War Nation Immunity +msg_err_cannot_start_siege_target_nation_has_too_many_home_defences: "You cannot start a siege on this nation, because it is already fighting %d home defence sieges." \ No newline at end of file diff --git a/src/main/resources/french.yml b/src/main/resources/french.yml index 6dc628a1d..fa9400490 100644 --- a/src/main/resources/french.yml +++ b/src/main/resources/french.yml @@ -1,5 +1,5 @@ name: SiegeWar -version: 0.18 +version: 0.19 language: french author: PainOchoco website: "http://townyadvanced.github.io/" @@ -422,13 +422,11 @@ status_nation_plunder_stats: '&2Town Plunder History - Gains/Losses: &a%d&2/&a%d #Siege effects msg_err_siege_war_cannot_spawn_into_siegezone_or_besieged_town: '&cOnly town residents can spawn into a besieged town or siege zone.' -#All-Nation-Sieges +#Post-War Nation Immunity msg_err_siege_affected_home_nation_cannot_recruit: "&cThe nation cannot add new towns, because one of its home towns is under siege attack." -msg_err_siege_affected_home_nation_town_cannot_toggle_pvp: "&cCannot toggle PVP, because one of your nation's home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_recruit: "&cThe town cannot add new residents, because one of its nation's home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_claim: "&cCannot claim land, because one of your nation's home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_unclaim: "&cCannot unclaim land, because one of your nation's home towns is under siege attack." -msg_err_cannot_start_siege_because_towns_home_nation_has_besieged_town: "&cCannot start siege on this nation town, because one of its nation's home towns is already under siege attack." # Added in 0.17 @@ -439,4 +437,9 @@ msg_err_peaceful_town_cannot_move_homeblock: "&cPeaceful towns cannot move their # Homeblock move restrictions msg_err_besieged_town_cannot_move_homeblock: "&cBesieged towns cannot move their homeblocks." -msg_err_occupied_town_cannot_move_homeblock: "&cOccupied towns cannot move their homeblocks." \ No newline at end of file +msg_err_occupied_town_cannot_move_homeblock: "&cOccupied towns cannot move their homeblocks." + +# Added in 0.19 + +#Post-War Nation Immunity +msg_err_cannot_start_siege_target_nation_has_too_many_home_defences: "You cannot start a siege on this nation, because it is already fighting %d home defence sieges." \ No newline at end of file From 4e5b3d8205d313bdfa1b9f814ea92161b33e1890 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Tue, 20 Apr 2021 14:41:06 +0100 Subject: [PATCH 12/39] Blurb update --- .../goosius/siegewar/settings/ConfigNodes.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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 d11cb5bdc..6d88e7ea0 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -721,11 +721,16 @@ public enum ConfigNodes { "# by granting siege-immunity to all of their towns, after any period of continuous fighting.", "# ", "# This effect is achieved as follows:", - "# 1. The max number of consecutive home-town-defence sieges is limited.", - "# 2. After each period of continuous fighting (a.k.a war), every town in the nation gets siege immunity.", - "# 3. To mitigate exploits, nations suffer some mild negative effects during hometown defence sieges - cannot claim/unclaim/recruit.", - "# 4. To mitigate annoyance-sieges, the cost to attack a hometown increases as the defending nation increases in size."), - POST_WAR_NATION_IMMUNITY_MAX_HOME_DEFENCE_SIEGES( + "# 1. The max number of consecutive hometown-defence sieges is limited.", + "# 2. After each period of continuous fighting (a.k.a war), each town in the nation gets some siege immunity.", + "# 3. To mitigate exploits, nations suffer some mild negative effects during hometown-defence sieges - cannot claim/unclaim/recruit.", + "# 4. To mitigate annoyance-sieges, the cost to attack a nation hometown increases as the defending nation increases in size.", + "# ", + "# NOTE: ", + "# If a town switches home nation during a siege", + "# then when the siege ends, the post-war siege immunity is distributed", + "# between all the home nations which the town had during the course of the siege"), + POST_WAR_NATION_IMMUNITY_MAX_HOME_DEFENCE_SIEGES( "post_war_nation_immunity.max_home_defence_sieges", "3", "", From 463a6d9b78795328ef99c8d566b265dd3fe8d236 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Tue, 20 Apr 2021 15:35:55 +0100 Subject: [PATCH 13/39] Blurb update --- .../goosius/siegewar/settings/ConfigNodes.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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 6d88e7ea0..0c9f822a9 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -717,20 +717,20 @@ public enum ConfigNodes { "", "# If this setting is true, then post-war nation immunity is enabled.", "# ", - "# This feature ensures that non-aggressive nations cannot be forced to fight continuously,", - "# by granting siege-immunity to all of their towns, after any period of continuous fighting.", + "# This feature gives each nation regular breaks from war,", + "# by granting siege-immunity to all its hometowns, after any period of continuous hometown-defence.", "# ", - "# This effect is achieved as follows:", - "# 1. The max number of consecutive hometown-defence sieges is limited.", - "# 2. After each period of continuous fighting (a.k.a war), each town in the nation gets some siege immunity.", - "# 3. To mitigate exploits, nations suffer some mild negative effects during hometown-defence sieges - cannot claim/unclaim/recruit.", - "# 4. To mitigate annoyance-sieges, the cost to attack a nation hometown increases as the defending nation increases in size.", + "# Effects on Each Nation:", + "# 1. The number of simultaneous attacks on the nation's hometowns is limited to a certain number (configurable - see next setting).", + "# 2. After the nation exits any period of continuous hometown-defence, each hometown gets some siege immunity.", + "# 3. To mitigate exploits, the nation suffers some mild negative effects while fighting in hometown-defence: cannot claim/unclaim/recruit.", + "# 4. To mitigate annoyance-sieges, the cost to attack any hometown increases as the nation increases in size.", "# ", "# NOTE: ", "# If a town switches home nation during a siege", "# then when the siege ends, the post-war siege immunity is distributed", "# between all the home nations which the town had during the course of the siege"), - POST_WAR_NATION_IMMUNITY_MAX_HOME_DEFENCE_SIEGES( + POST_WAR_NATION_IMMUNITY_MAX_HOME_DEFENCE_SIEGES( "post_war_nation_immunity.max_home_defence_sieges", "3", "", From d863ef58434e9a62be2a740d2912babbbc26039d Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Tue, 20 Apr 2021 16:04:33 +0100 Subject: [PATCH 14/39] cleanu[ --- .../siegewar/settings/ConfigNodes.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) 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 0c9f822a9..d118a46d5 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -718,18 +718,23 @@ public enum ConfigNodes { "# If this setting is true, then post-war nation immunity is enabled.", "# ", "# This feature gives each nation regular breaks from war,", - "# by granting siege-immunity to all its hometowns, after any period of continuous hometown-defence.", + "# by granting siege-immunity to all its towns after a home-defence war.", + "# (A home-defence war is when one or more of the nation's towns are under non-revolt sieges)", "# ", "# Effects on Each Nation:", - "# 1. The number of simultaneous attacks on the nation's hometowns is limited to a certain number (configurable - see next setting).", - "# 2. After the nation exits any period of continuous hometown-defence, each hometown gets some siege immunity.", - "# 3. To mitigate exploits, the nation suffers some mild negative effects while fighting in hometown-defence: cannot claim/unclaim/recruit.", - "# 4. To mitigate annoyance-sieges, the cost to attack any hometown increases as the nation increases in size.", + "# 1. The number of simultaneous attacks on the nation's towns is limited (configurable - see next setting).", + "# 2. After the nation exits a home-defence war, each town gets some siege immunity.", + "# 3. To mitigate exploits, the nation suffers some mild negative effects while fighting a home-defensive war: cannot claim/unclaim/recruit.", + "# 4. To mitigate annoyance-sieges, the cost to attack the nation's towns increases as the nation increases in size.", "# ", - "# NOTE: ", + "# NOTE 1: ", + "# This feature only applies to the 'home' towns of each nation (not occupied foreign towns).", + "# Thus if a nation has chosen to occupy any foreign towns, it is not guaranteed any breaks from war - because this feature does not restrict revolts.", + "# ", + "# NOTE 2: ", "# If a town switches home nation during a siege", - "# then when the siege ends, the post-war siege immunity is distributed", - "# between all the home nations which the town had during the course of the siege"), + "# then when the home-defence war ends, the post-war immunity from that town,", + "# is distributed between all the home nations which the town had during the course of the siege."), POST_WAR_NATION_IMMUNITY_MAX_HOME_DEFENCE_SIEGES( "post_war_nation_immunity.max_home_defence_sieges", "3", From f75d00af96a5a3220a80d7324e24b7d385622fad Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Tue, 20 Apr 2021 19:02:44 +0100 Subject: [PATCH 15/39] Cleanups --- .../goosius/siegewar/SiegeController.java | 55 +++++++++---------- .../SiegeWarNationEventListener.java | 3 +- .../listeners/SiegeWarTownEventListener.java | 6 +- .../siegewar/settings/ConfigNodes.java | 6 +- 4 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index bd282803c..1f29a3bdb 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -394,60 +394,59 @@ public static Map getActiveDefensiveSieges(Nation nation) { } /** - * This method returns true - * - The given town is in a nation, and - * - One (or more) of the nation's home towns is a siege defender - * * @param town the town to check - * @return true if one (or more) of the nation's home towns is a siege defender + * @return true if the town has a nation & that nation is fighting a home-defence war + * + * Note: A home defence war is when one of the nation's towns is in an active non-revolt siege. */ - public static boolean isAnyHomeTownASiegeDefender(Town town) { + public static boolean isTownsNationFightingAHomeDefenceWar(Town town) { try { if(town.hasNation()) { - return isAnyHomeTownASiegeDefender(town.getNation()); + return isNationFightingAHomeDefenceWar(town.getNation()); } } catch (NotRegisteredException ignored) {} return false; } /** - * This method returns the number of active home-town defences sieges, - * which the nation is involved in. - * * @param nation the nation to check - * @return the number of home defences sieges + * @return true if the given nation is fighting a home-defence war + * + * Note: A home defence war is when one of the nation's towns is in an active non-revolt siege. */ - public static int getNumActiveHomeDefenceSieges(Nation nation) { - int result = 0; + public static boolean isNationFightingAHomeDefenceWar(Nation nation) { for(Siege siege: SiegeController.getSieges()) { - if((siege.getSiegeType() == SiegeType.CONQUEST || siege.getSiegeType() == SiegeType.SUPPRESSION) - && siege.getStatus().isActive() - && siege.getDefendingNationIfPossibleElseTown() == nation) { - result++; - } + try { + if(siege.getStatus().isActive() + && siege.getSiegeType() != SiegeType.REVOLT + && siege.getTown().hasNation() + && siege.getTown().getNation() == nation) { + return true; + } + } catch (NotRegisteredException ignored) {} } - return result; + return false; } /** - * This method returns true - * - One (or more) of the nation's home towns is a siege defender - * * @param nation the nation to check - * @return true if one (or more) of the nation's home towns is a siege defender + * @return the number of home defences sieges which the nation is involved in + * + * NOTE: A home-defence siege occurs when a nation town is in an active non-revolt siege. */ - public static boolean isAnyHomeTownASiegeDefender(Nation nation) { + public static int getNumActiveHomeDefenceSieges(Nation nation) { + int result = 0; for(Siege siege: SiegeController.getSieges()) { try { if(siege.getStatus().isActive() - && siege.getDefender() instanceof Town - && ((Town)siege.getDefender()).hasNation() + && siege.getSiegeType() != SiegeType.REVOLT + && siege.getTown().hasNation() && siege.getTown().getNation() == nation) { - return true; + result++; } } catch (NotRegisteredException ignored) {} } - return false; + return result; } /** diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java index b470beada..501ed6b64 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java @@ -312,10 +312,9 @@ public void on(NationTownLeaveEvent event) { public void on(NationPreAddTownEvent event) { if (SiegeWarSettings.getWarSiegeEnabled() && SiegeWarSettings.isPostWarNationImmunityEnabled() - && SiegeController.isAnyHomeTownASiegeDefender(event.getNation())) { + && SiegeController.isNationFightingAHomeDefenceWar(event.getNation())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_cannot_recruit")); - return; } } } diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java index d61061da0..488859c5b 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java @@ -85,7 +85,7 @@ public void onTownAddResident(TownPreAddResidentEvent event) { } if (SiegeWarSettings.isPostWarNationImmunityEnabled() - && SiegeController.isAnyHomeTownASiegeDefender(event.getTown())) { + && SiegeController.isTownsNationFightingAHomeDefenceWar(event.getTown())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_recruit")); return; @@ -218,7 +218,7 @@ public void onTownClaim(TownPreClaimEvent event) { //If the town is affected by an all-nation-siege, they cannot claim any land if (SiegeWarSettings.isPostWarNationImmunityEnabled() - && SiegeController.isAnyHomeTownASiegeDefender(event.getTown())) { + && SiegeController.isTownsNationFightingAHomeDefenceWar(event.getTown())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_claim")); return; @@ -272,7 +272,7 @@ public void onTownUnclaim(TownPreUnclaimCmdEvent event) { //Town affected by all-nation-siege if (SiegeWarSettings.isPostWarNationImmunityEnabled() - && SiegeController.isAnyHomeTownASiegeDefender(event.getTown())) { + && SiegeController.isTownsNationFightingAHomeDefenceWar(event.getTown())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_unclaim")); return; 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 d118a46d5..21161964d 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -722,9 +722,9 @@ public enum ConfigNodes { "# (A home-defence war is when one or more of the nation's towns are under non-revolt sieges)", "# ", "# Effects on Each Nation:", - "# 1. The number of simultaneous attacks on the nation's towns is limited (configurable - see next setting).", - "# 2. After the nation exits a home-defence war, each town gets some siege immunity.", - "# 3. To mitigate exploits, the nation suffers some mild negative effects while fighting a home-defensive war: cannot claim/unclaim/recruit.", + "# 1. The number of simultaneous attacks on the nation's towns is limited.", + "# 2. After a home-defence war ends, each of the nation's town gets some siege immunity.", + "# 3. To mitigate exploits, the nation suffers some mild negative effects while fighting a home-defence war: cannot claim/unclaim/recruit.", "# 4. To mitigate annoyance-sieges, the cost to attack the nation's towns increases as the nation increases in size.", "# ", "# NOTE 1: ", From 37339665a27c4aa7f6e41a522ccb60aa0b5c5a1e Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Tue, 20 Apr 2021 19:15:00 +0100 Subject: [PATCH 16/39] Cleanup --- .../goosius/siegewar/SiegeController.java | 7 ++++--- .../siegewar/playeractions/PlaceBlock.java | 19 ++++++------------- src/main/resources/english.yml | 2 +- src/main/resources/french.yml | 2 +- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index 1f29a3bdb..5f589df97 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -397,7 +397,8 @@ public static Map getActiveDefensiveSieges(Nation nation) { * @param town the town to check * @return true if the town has a nation & that nation is fighting a home-defence war * - * Note: A home defence war is when one of the nation's towns is in an active non-revolt siege. + * Note: A home defence war is when one of the nation's towns is under siege attack. + * (In other words, it has an active siege of any type except Revolt.) */ public static boolean isTownsNationFightingAHomeDefenceWar(Town town) { try { @@ -412,7 +413,7 @@ public static boolean isTownsNationFightingAHomeDefenceWar(Town town) { * @param nation the nation to check * @return true if the given nation is fighting a home-defence war * - * Note: A home defence war is when one of the nation's towns is in an active non-revolt siege. + * Note: A home defence war is when one of the nation's towns is is under siege attack. */ public static boolean isNationFightingAHomeDefenceWar(Nation nation) { for(Siege siege: SiegeController.getSieges()) { @@ -432,7 +433,7 @@ public static boolean isNationFightingAHomeDefenceWar(Nation nation) { * @param nation the nation to check * @return the number of home defences sieges which the nation is involved in * - * NOTE: A home-defence siege occurs when a nation town is in an active non-revolt siege. + * NOTE: A home-defence siege occurs when a nation town is under siege attack. */ public static int getNumActiveHomeDefenceSieges(Nation nation) { int result = 0; diff --git a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java index bf255fb26..fe497266f 100644 --- a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java +++ b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java @@ -277,29 +277,22 @@ private static synchronized void evaluateStartNewSiegeAttempt(Player player, if(SiegeController.getActiveOffensiveSieges(residentsNation).size() >= SiegeWarSettings.getWarSiegeMaxActiveSiegeAttacksPerNation()) throw new TownyException(Translation.of("msg_err_siege_war_nation_has_too_many_active_siege_attacks")); + if (SiegeWarSettings.isPostWarNationImmunityEnabled() + && nearbyTown.hasNation() + && SiegeController.getNumActiveHomeDefenceSieges(nearbyTown.getNation()) > SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges()) { + throw new TownyException(Translation.of("msg_err_cannot_attack_nation_too_many_towns_under_attack", SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges())); + } + if (TownOccupationController.isTownOccupied(nearbyTown)) { Nation occupierOfNearbyTown = TownOccupationController.getTownOccupier(nearbyTown); if (residentsNation == occupierOfNearbyTown) { //Suppression siege - if (SiegeWarSettings.isPostWarNationImmunityEnabled() - && nearbyTown.hasNation() - && SiegeController.getNumActiveHomeDefenceSieges(nearbyTown.getNation()) > SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges()) { - throw new TownyException(Translation.of("msg_err_cannot_start_siege_target_nation_has_too_many_home_defences", SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges())); - } - StartSuppressionSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); } else { //Liberation siege StartLiberationSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); } } else { - //Conquest siege - if (SiegeWarSettings.isPostWarNationImmunityEnabled() - && nearbyTown.hasNation() - && SiegeController.getNumActiveHomeDefenceSieges(nearbyTown.getNation()) > SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges()) { - throw new TownyException(Translation.of("msg_err_cannot_start_siege_target_nation_has_too_many_home_defences", SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges())); - } - StartConquestSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); } } diff --git a/src/main/resources/english.yml b/src/main/resources/english.yml index 8a8c29f9b..cfba2c050 100644 --- a/src/main/resources/english.yml +++ b/src/main/resources/english.yml @@ -431,4 +431,4 @@ msg_err_occupied_town_cannot_move_homeblock: "&cOccupied towns cannot move their # Added in 0.19 #Post-War Nation Immunity -msg_err_cannot_start_siege_target_nation_has_too_many_home_defences: "You cannot start a siege on this nation, because it is already fighting %d home defence sieges." \ No newline at end of file +msg_err_cannot_attack_nation_too_many_towns_under_attack: "You cannot attack this town, because too many of its home nation's towns are already under attack." \ No newline at end of file diff --git a/src/main/resources/french.yml b/src/main/resources/french.yml index fa9400490..caa6bb43f 100644 --- a/src/main/resources/french.yml +++ b/src/main/resources/french.yml @@ -442,4 +442,4 @@ msg_err_occupied_town_cannot_move_homeblock: "&cOccupied towns cannot move their # Added in 0.19 #Post-War Nation Immunity -msg_err_cannot_start_siege_target_nation_has_too_many_home_defences: "You cannot start a siege on this nation, because it is already fighting %d home defence sieges." \ No newline at end of file +msg_err_cannot_attack_nation_too_many_towns_under_attack: "You cannot start a siege on this nation, because too many of its home towns are already under attack." \ No newline at end of file From b47694e88efaf62030fcbb5f3bd139b23748cbd2 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 21 Apr 2021 18:43:36 +0100 Subject: [PATCH 17/39] post war nation imm - removed the num attacks restriction --- .../siegewar/playeractions/PlaceBlock.java | 6 --- .../siegewar/settings/ConfigNodes.java | 40 +++++-------------- .../siegewar/settings/SiegeWarSettings.java | 4 -- src/main/resources/english.yml | 5 --- src/main/resources/french.yml | 5 --- 5 files changed, 9 insertions(+), 51 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java index fe497266f..9b2395ac8 100644 --- a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java +++ b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java @@ -277,12 +277,6 @@ private static synchronized void evaluateStartNewSiegeAttempt(Player player, if(SiegeController.getActiveOffensiveSieges(residentsNation).size() >= SiegeWarSettings.getWarSiegeMaxActiveSiegeAttacksPerNation()) throw new TownyException(Translation.of("msg_err_siege_war_nation_has_too_many_active_siege_attacks")); - if (SiegeWarSettings.isPostWarNationImmunityEnabled() - && nearbyTown.hasNation() - && SiegeController.getNumActiveHomeDefenceSieges(nearbyTown.getNation()) > SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges()) { - throw new TownyException(Translation.of("msg_err_cannot_attack_nation_too_many_towns_under_attack", SiegeWarSettings.getPostWarNationImmunityMaxHomeDefenceSieges())); - } - if (TownOccupationController.isTownOccupied(nearbyTown)) { Nation occupierOfNearbyTown = TownOccupationController.getTownOccupier(nearbyTown); if (residentsNation == occupierOfNearbyTown) { 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 21161964d..87e2acf64 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -717,38 +717,16 @@ public enum ConfigNodes { "", "# If this setting is true, then post-war nation immunity is enabled.", "# ", - "# This feature gives each nation regular breaks from war,", - "# by granting siege-immunity to all its towns after a home-defence war.", - "# (A home-defence war is when one or more of the nation's towns are under non-revolt sieges)", + "# This feature gives each nation regular breaks from war, by granting siege-immunity to all its towns after a home-defence war.", + "# (A home-defence war occurs when one or more of a nation's towns are under a non-revolt siege)", "# ", - "# Effects on Each Nation:", - "# 1. The number of simultaneous attacks on the nation's towns is limited.", - "# 2. After a home-defence war ends, each of the nation's town gets some siege immunity.", - "# 3. To mitigate exploits, the nation suffers some mild negative effects while fighting a home-defence war: cannot claim/unclaim/recruit.", - "# 4. To mitigate annoyance-sieges, the cost to attack the nation's towns increases as the nation increases in size.", - "# ", - "# NOTE 1: ", - "# This feature only applies to the 'home' towns of each nation (not occupied foreign towns).", - "# Thus if a nation has chosen to occupy any foreign towns, it is not guaranteed any breaks from war - because this feature does not restrict revolts.", - "# ", - "# NOTE 2: ", - "# If a town switches home nation during a siege", - "# then when the home-defence war ends, the post-war immunity from that town,", - "# is distributed between all the home nations which the town had during the course of the siege."), - POST_WAR_NATION_IMMUNITY_MAX_HOME_DEFENCE_SIEGES( - "post_war_nation_immunity.max_home_defence_sieges", - "3", - "", - "# This setting determines the max number of home defence sieges which a nation must fight.", - "# ", - "# EXAMPLE:", - "# If this value is 3, and the nation already has 3 hometowns under attack", - "# then no more attacks on its hometowns are allowed until after all the current sieges end.", - "# ", - "# If this value is set to very high (e.g. 999999),", - "# the restriction is effectively disabled, ", - "# allowing all hometowns to be attacked at once,", - "# along with the possibility that nations could be forced to fight continuously i.e. no rest days."), + "# NOTES:", + "# 1. To mitigate exploits, nations suffer some mild negative effects while fighting a home-defence war - cannot claim/unclaim/recruit.", + "# 2. To mitigate annoyance-sieges, the cost to attack a nation's towns increases as that nation increases in size.", + "# 3. This feature only applies to the home towns of each nation (not occupied foreign towns).", + "# 4. If a town switches home nation during a home-defence war", + "# then when the home-defence war ends, the post-war immunity from that town,", + "# is distributed between all the home nations which the town had during the siege."), POST_WAR_NATION_IMMUNITY_DURATION_MODIFIER( "post_war_nation_immunity.duration_modifier", "0.75", diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java index 808914425..2853f38f5 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java @@ -401,10 +401,6 @@ public static boolean isPostWarNationImmunityEnabled() { return Settings.getBoolean(ConfigNodes.POST_WAR_NATION_IMMUNITY_ENABLED); } - public static double getPostWarNationImmunityMaxHomeDefenceSieges() { - return Settings.getInt(ConfigNodes.POST_WAR_NATION_IMMUNITY_MAX_HOME_DEFENCE_SIEGES); - } - public static double getPostWarNationImmunityDurationModifier() { return Settings.getDouble(ConfigNodes.POST_WAR_NATION_IMMUNITY_DURATION_MODIFIER); } diff --git a/src/main/resources/english.yml b/src/main/resources/english.yml index cfba2c050..fe287d495 100644 --- a/src/main/resources/english.yml +++ b/src/main/resources/english.yml @@ -427,8 +427,3 @@ msg_err_peaceful_town_cannot_move_homeblock: "&cPeaceful towns cannot move their # Homeblock move restrictions msg_err_besieged_town_cannot_move_homeblock: "&cBesieged towns cannot move their homeblocks." msg_err_occupied_town_cannot_move_homeblock: "&cOccupied towns cannot move their homeblocks." - -# Added in 0.19 - -#Post-War Nation Immunity -msg_err_cannot_attack_nation_too_many_towns_under_attack: "You cannot attack this town, because too many of its home nation's towns are already under attack." \ No newline at end of file diff --git a/src/main/resources/french.yml b/src/main/resources/french.yml index caa6bb43f..ccc9e11cc 100644 --- a/src/main/resources/french.yml +++ b/src/main/resources/french.yml @@ -438,8 +438,3 @@ msg_err_peaceful_town_cannot_move_homeblock: "&cPeaceful towns cannot move their # Homeblock move restrictions msg_err_besieged_town_cannot_move_homeblock: "&cBesieged towns cannot move their homeblocks." msg_err_occupied_town_cannot_move_homeblock: "&cOccupied towns cannot move their homeblocks." - -# Added in 0.19 - -#Post-War Nation Immunity -msg_err_cannot_attack_nation_too_many_towns_under_attack: "You cannot start a siege on this nation, because too many of its home towns are already under attack." \ No newline at end of file From 7bcd532b42bef9b2724b15d0cfcea9ee6606bcf0 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Sun, 25 Apr 2021 12:14:08 +0100 Subject: [PATCH 18/39] BLurb pdate --- .../gmail/goosius/siegewar/settings/ConfigNodes.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 87e2acf64..fe3bc8c5c 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -717,14 +717,14 @@ public enum ConfigNodes { "", "# If this setting is true, then post-war nation immunity is enabled.", "# ", - "# This feature gives each nation regular breaks from war, by granting siege-immunity to all its towns after a home-defence war.", - "# (A home-defence war occurs when one or more of a nation's towns are under a non-revolt siege)", + "# This feature gives each nation regular full-breaks from war, ", + "# by granting siege-immunity to all their towns after a home-defence war.", + "# (A home-defence war occurs when one or ore of a nation's towns are under a non-revolt siege)", "# ", "# NOTES:", "# 1. To mitigate exploits, nations suffer some mild negative effects while fighting a home-defence war - cannot claim/unclaim/recruit.", "# 2. To mitigate annoyance-sieges, the cost to attack a nation's towns increases as that nation increases in size.", - "# 3. This feature only applies to the home towns of each nation (not occupied foreign towns).", - "# 4. If a town switches home nation during a home-defence war", + "# 3. If a town switches home nation during a home-defence war", "# then when the home-defence war ends, the post-war immunity from that town,", "# is distributed between all the home nations which the town had during the siege."), POST_WAR_NATION_IMMUNITY_DURATION_MODIFIER( @@ -750,7 +750,7 @@ public enum ConfigNodes { "# ", "# EXAMPLE:", "# If this setting is 0.1,", - "# and a nation home town is attacked,", + "# and an attack is attempted on a nation town,", "# then for every home town in that nation (including the attacked one),", "# the attack-cost (i.e. warchest) requirement is increased by 10% of the amount it would take to attack that town."); From 5e2e5c18ba8664835cb81eb148dc166ca162dd7a Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Sun, 25 Apr 2021 12:18:15 +0100 Subject: [PATCH 19/39] Blyurb update --- .../java/com/gmail/goosius/siegewar/settings/ConfigNodes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fe3bc8c5c..f908bd0e3 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -719,7 +719,7 @@ public enum ConfigNodes { "# ", "# This feature gives each nation regular full-breaks from war, ", "# by granting siege-immunity to all their towns after a home-defence war.", - "# (A home-defence war occurs when one or ore of a nation's towns are under a non-revolt siege)", + "# (A home-defence war occurs when one or ore of a nation's towns are under non-revolt sieges)", "# ", "# NOTES:", "# 1. To mitigate exploits, nations suffer some mild negative effects while fighting a home-defence war - cannot claim/unclaim/recruit.", From b070e4f1790e2535f209bc501bd354edb2c82032 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Sun, 25 Apr 2021 12:21:39 +0100 Subject: [PATCH 20/39] Removed unused message --- .../goosius/siegewar/SiegeController.java | 23 +------------------ 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index 5f589df97..1e1a2e8f0 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -413,7 +413,7 @@ public static boolean isTownsNationFightingAHomeDefenceWar(Town town) { * @param nation the nation to check * @return true if the given nation is fighting a home-defence war * - * Note: A home defence war is when one of the nation's towns is is under siege attack. + * Note: A home defence war is when one of the nation's towns is is under a non-revolt siege. */ public static boolean isNationFightingAHomeDefenceWar(Nation nation) { for(Siege siege: SiegeController.getSieges()) { @@ -429,27 +429,6 @@ public static boolean isNationFightingAHomeDefenceWar(Nation nation) { return false; } - /** - * @param nation the nation to check - * @return the number of home defences sieges which the nation is involved in - * - * NOTE: A home-defence siege occurs when a nation town is under siege attack. - */ - public static int getNumActiveHomeDefenceSieges(Nation nation) { - int result = 0; - for(Siege siege: SiegeController.getSieges()) { - try { - if(siege.getStatus().isActive() - && siege.getSiegeType() != SiegeType.REVOLT - && siege.getTown().hasNation() - && siege.getTown().getNation() == nation) { - result++; - } - } catch (NotRegisteredException ignored) {} - } - return result; - } - /** * Start a siege * From 5ef6b5c7949a9be52ea78f3db61da1e87d608b45 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Sun, 25 Apr 2021 12:29:34 +0100 Subject: [PATCH 21/39] Comment update --- .../siegewar/listeners/SiegeWarNationEventListener.java | 2 +- .../siegewar/listeners/SiegeWarTownEventListener.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java index 501ed6b64..daf247c12 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java @@ -306,7 +306,7 @@ public void on(NationTownLeaveEvent event) { } /* - * If nation is under siege, it cannot add new towns + * If nation is fighting a home-defence war it cannot add new towns */ @EventHandler public void on(NationPreAddTownEvent event) { diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java index 488859c5b..77c2f54d8 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java @@ -84,6 +84,7 @@ public void onTownAddResident(TownPreAddResidentEvent event) { return; } + //Cannot recruit if nation is fighting a home-defence war if (SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.isTownsNationFightingAHomeDefenceWar(event.getTown())) { event.setCancelled(true); @@ -216,7 +217,7 @@ public void onTownClaim(TownPreClaimEvent event) { return; } - //If the town is affected by an all-nation-siege, they cannot claim any land + //If the town is fighting a home-defence war, they cannot claim any land if (SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.isTownsNationFightingAHomeDefenceWar(event.getTown())) { event.setCancelled(true); @@ -270,7 +271,7 @@ public void onTownUnclaim(TownPreUnclaimCmdEvent event) { return; } - //Town affected by all-nation-siege + //Town fighting a home-defence war if (SiegeWarSettings.isPostWarNationImmunityEnabled() && SiegeController.isTownsNationFightingAHomeDefenceWar(event.getTown())) { event.setCancelled(true); From bf80310039445e332342a84a9ac7638479d0f27c Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Sun, 25 Apr 2021 12:35:39 +0100 Subject: [PATCH 22/39] Ensure that pending immunity is wiped after being granted --- .../com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index 221661950..ce3d646cc 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -110,6 +110,9 @@ private static void grantSiegeImmunityToNation(Nation nation, double siegeImmuni nationTown.save(); } } + + NationMetaDataController.setPendingSiegeImmunityMillis(nation, 0); + nation.save(); } } } \ No newline at end of file From 5d82efeb5aa5b64c3360ddfa08e7bb0131ae8866 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Mon, 26 Apr 2021 12:01:47 +0100 Subject: [PATCH 23/39] Cleanup --- .../com/gmail/goosius/siegewar/objects/Siege.java | 12 ------------ .../gmail/goosius/siegewar/settings/ConfigNodes.java | 2 +- .../siegewar/utils/SiegeWarBattleSessionUtil.java | 5 +++-- .../goosius/siegewar/utils/SiegeWarTownUtil.java | 2 +- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java index bc49737fe..399485348 100644 --- a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java +++ b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java @@ -480,18 +480,6 @@ public void recordTownDefenceHomeNation() throws NotRegisteredException { } } - /** - * Returns true if this siege is a "town defence" - * - * A town defence is a siege where the town itself is being attacked, - * rather than a siege where the town occupier is being attacked - * - * @return true if the siege is a town defence - */ - public boolean isTownDefence() { - return siegeType == SiegeType.CONQUEST || siegeType == SiegeType.SUPPRESSION; - } - public int getTotalTownDefenceBattles() { int result = 0; for(int homeNationContribution: townDefenceHomeNations.values()) { 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 f908bd0e3..edb61abf5 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -719,7 +719,7 @@ public enum ConfigNodes { "# ", "# This feature gives each nation regular full-breaks from war, ", "# by granting siege-immunity to all their towns after a home-defence war.", - "# (A home-defence war occurs when one or ore of a nation's towns are under non-revolt sieges)", + "# (A home-defence war occurs when one or more of a nation's towns are under non-revolt sieges)", "# ", "# NOTES:", "# 1. To mitigate exploits, nations suffer some mild negative effects while fighting a home-defence war - cannot claim/unclaim/recruit.", 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 857881224..84042602d 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java @@ -5,6 +5,7 @@ import com.gmail.goosius.siegewar.SiegeWar; import com.gmail.goosius.siegewar.enums.SiegeSide; import com.gmail.goosius.siegewar.enums.SiegeStatus; +import com.gmail.goosius.siegewar.enums.SiegeType; import com.gmail.goosius.siegewar.objects.BattleSession; import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.settings.SiegeWarSettings; @@ -49,12 +50,12 @@ public static void evaluateBattleSessions() { try { if (siege.getStatus() == SiegeStatus.IN_PROGRESS) { //Record home nation if this is a town defence siege - if(siege.isTownDefence()) + if(siege.getSiegeType() != SiegeType.REVOLT) siege.recordTownDefenceHomeNation(); //Continue to next siege if there were no battle points if(siege.getAttackerBattlePoints() == 0 || siege.getDefenderBattlePoints() == 0) { - if(siege.isTownDefence()) + if(siege.getSiegeType() != SiegeType.REVOLT) SiegeController.saveSiege(siege); continue; } diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index ce3d646cc..4ad2ee417 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -70,7 +70,7 @@ public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { * If this was a town defence siege, * Grant siege immunity to any nations who were the home nation of the town during the siege */ - if(SiegeWarSettings.isPostWarNationImmunityEnabled() && siege.isTownDefence()) { + if(SiegeWarSettings.isPostWarNationImmunityEnabled() && siege.getSiegeType() != SiegeType.REVOLT) { int totalBattles = siege.getTotalTownDefenceBattles(); double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getPostWarNationImmunityDurationModifier(); int numBattlesFoughtByNation; From f2acaacc049df0419bd48ac6e18a485493280836 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Mon, 26 Apr 2021 12:51:51 +0100 Subject: [PATCH 24/39] post war nation imm - Fixed bug and cleanup --- .../goosius/siegewar/SiegeController.java | 6 +-- .../metadata/SiegeMetaDataController.java | 23 +++++------ .../gmail/goosius/siegewar/objects/Siege.java | 39 ++++++++----------- .../utils/SiegeWarBattleSessionUtil.java | 2 +- .../siegewar/utils/SiegeWarTownUtil.java | 17 ++++---- 5 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index 1e1a2e8f0..787b7342f 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -90,7 +90,7 @@ public static void saveSiege(Siege siege) { SiegeMetaDataController.setEndTime(town, siege.getScheduledEndTime()); SiegeMetaDataController.setActualEndTime(town, siege.getActualEndTime()); SiegeMetaDataController.setAttackerSiegeContributors(town, siege.getAttackerSiegeContributors()); - SiegeMetaDataController.setTownDefenceHomeNations(town, siege.getTownDefenceHomeNations()); + SiegeMetaDataController.setTownDefenceGovernments(town, siege.getTownDefenceGovernments()); town.save(); } @@ -229,7 +229,7 @@ public static boolean loadSiege(Siege siege) { siege.setAttackerSiegeContributors(SiegeMetaDataController.getAttackerSiegeContributors(town)); - siege.setTownDefenceHomeNations(SiegeMetaDataController.getTownDefenceHomeNations(town)); + siege.setTownDefenceGovernments(SiegeMetaDataController.getTownDefenceGovernments(town)); return true; } @@ -584,7 +584,7 @@ private static void sendGlobalSiegeStartMessage(Siege siege) throws NotRegistere public static boolean doesNationHaveAnyHomeDefenceContributionsInActiveSieges(Nation nation) { for(Siege siege: townSiegeMap.values()) { if(siege.getStatus().isActive() - && siege.getTownDefenceHomeNations().containsKey(nation.getUUID().toString())) { + && siege.getTownDefenceGovernments().containsKey(nation.getUUID())) { return true; } } diff --git a/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java b/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java index 0f2809419..6e6cea930 100644 --- a/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java +++ b/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.UUID; /** * @@ -49,7 +50,7 @@ public class SiegeMetaDataController { private static LongDataField endTime = new LongDataField("siegewar_endTime", 0l); private static LongDataField actualEndTime = new LongDataField("siegewar_actualEndTime", 0l); private static StringDataField attackerSiegeContributors = new StringDataField("siegewar_attackerSiegeContributors", ""); - private static StringDataField townDefenceHomeNations = new StringDataField("siegewar_townDefenceHomeNations", ""); + private static StringDataField townDefenceGovernments = new StringDataField("siegewar_townDefenceGovernments", ""); public SiegeMetaDataController(SiegeWar plugin) { this.plugin = plugin; @@ -361,8 +362,8 @@ public static Map getAttackerSiegeContributors(Town town) { } } - public static Map getTownDefenceHomeNations(Town town) { - StringDataField sdf = (StringDataField) townDefenceHomeNations.clone(); + public static Map getTownDefenceGovernments(Town town) { + StringDataField sdf = (StringDataField) townDefenceGovernments.clone(); String dataAsString = null; if (town.hasMeta(sdf.getKey())) @@ -371,14 +372,14 @@ public static Map getTownDefenceHomeNations(Town town) { if(dataAsString == null || dataAsString.length() == 0) { return new HashMap<>(); } else { - Map contributionsMap = new HashMap<>(); + Map governmentsMap = new HashMap<>(); String[] contributionDataEntries = dataAsString.split(","); String[] contributionDataPair; for(String contributionDataEntry: contributionDataEntries) { contributionDataPair = contributionDataEntry.split(":"); - contributionsMap.put(contributionDataPair[0], Integer.parseInt(contributionDataPair[1])); + governmentsMap.put(UUID.fromString(contributionDataPair[0]), Integer.parseInt(contributionDataPair[1])); } - return contributionsMap; + return governmentsMap; } } @@ -401,22 +402,22 @@ public static void setAttackerSiegeContributors(Town town, Map c town.addMetaData(new StringDataField("siegewar_attackerSiegeContributors", mapAsStringBuilder.toString())); } - public static void setTownDefenceHomeNations(Town town, Map contributorsMap) { + public static void setTownDefenceGovernments(Town town, Map governmentsMap) { StringBuilder mapAsStringBuilder = new StringBuilder(); boolean firstEntry = true; - for(Map.Entry contributorEntry: contributorsMap.entrySet()) { + for(Map.Entry governmentEntry: governmentsMap.entrySet()) { if(firstEntry) { firstEntry = false; } else { mapAsStringBuilder.append(","); } - mapAsStringBuilder.append(contributorEntry.getKey()).append(":").append(contributorEntry.getValue()); + mapAsStringBuilder.append(governmentEntry.getKey()).append(":").append(governmentEntry.getValue()); } - StringDataField sdf = (StringDataField) townDefenceHomeNations.clone(); + StringDataField sdf = (StringDataField) townDefenceGovernments.clone(); if (town.hasMeta(sdf.getKey())) MetaDataUtil.setString(town, sdf, mapAsStringBuilder.toString()); else - town.addMetaData(new StringDataField(townDefenceHomeNations.getKey(), mapAsStringBuilder.toString())); + town.addMetaData(new StringDataField(townDefenceGovernments.getKey(), mapAsStringBuilder.toString())); } } diff --git a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java index 399485348..a0ef71e85 100644 --- a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java +++ b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java @@ -13,12 +13,7 @@ import org.bukkit.Location; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.HashSet; +import java.util.*; import static com.palmergames.util.TimeMgmt.ONE_HOUR_IN_MILLIS; @@ -62,7 +57,7 @@ public class Siege { private int defenderBattlePoints; private Set attackerBattleContributors; //UUID's of attackers who contributed during the current battle private Map attackerSiegeContributors; //UUID:numContributions map of attackers who contributed during current siege - private Map townDefenceHomeNations; //UUID:numBattleSessions map of nations who served as the home nation of the town during the siege + private Map townDefenceGovernments; //UUID:numBattleSessions map of governments who led the defence of the town. If town is in nation, nation UUID will be used. If town is nationless, town UUID will be used public Siege(Town town) { this.town = town; @@ -83,7 +78,7 @@ public Siege(Town town) { defenderBattlePoints = 0; attackerBattleContributors = new HashSet<>(); attackerSiegeContributors = new HashMap<>(); - townDefenceHomeNations = new HashMap<>(); + townDefenceGovernments = new HashMap<>(); } public Town getTown() { @@ -411,12 +406,12 @@ public void setAttackerSiegeContributors(Map attackerSiegeContr this.attackerSiegeContributors = attackerSiegeContributors; } - public Map getTownDefenceHomeNations() { - return townDefenceHomeNations; + public Map getTownDefenceGovernments() { + return townDefenceGovernments; } - public void setTownDefenceHomeNations(Map townDefenceHomeNations) { - this.townDefenceHomeNations = townDefenceHomeNations; + public void setTownDefenceGovernments(Map townDefenceGovernments) { + this.townDefenceGovernments = townDefenceGovernments; } public void registerAttackerBattleContributorsFromBannerControl() { @@ -462,27 +457,27 @@ public void setSiegeType(SiegeType siegeType) { * * @throws NotRegisteredException */ - public void recordTownDefenceHomeNation() throws NotRegisteredException { + public void recordTownDefenceGovernment() throws NotRegisteredException { //Identify key - String contributorKey; + UUID governmentUUID; if(town.hasNation()) - contributorKey = town.getNation().getUUID().toString(); + governmentUUID = town.getNation().getUUID(); else - contributorKey = "NO_HOME_NATION"; + governmentUUID = town.getUUID(); //Record battle session contribution - if(townDefenceHomeNations.containsKey(contributorKey)) { - int numBattleSessions = townDefenceHomeNations.get(contributorKey); + if(townDefenceGovernments.containsKey(governmentUUID)) { + int numBattleSessions = townDefenceGovernments.get(governmentUUID); numBattleSessions++; - townDefenceHomeNations.put(contributorKey, numBattleSessions); + townDefenceGovernments.put(governmentUUID, numBattleSessions); } else { - townDefenceHomeNations.put(contributorKey, 1); + townDefenceGovernments.put(governmentUUID, 1); } } - public int getTotalTownDefenceBattles() { + public int getTotalTownDefenceBattleSessions() { int result = 0; - for(int homeNationContribution: townDefenceHomeNations.values()) { + for(int homeNationContribution: townDefenceGovernments.values()) { result += homeNationContribution; } return result; 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 84042602d..99a4f865a 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java @@ -51,7 +51,7 @@ public static void evaluateBattleSessions() { if (siege.getStatus() == SiegeStatus.IN_PROGRESS) { //Record home nation if this is a town defence siege if(siege.getSiegeType() != SiegeType.REVOLT) - siege.recordTownDefenceHomeNation(); + siege.recordTownDefenceGovernment(); //Continue to next siege if there were no battle points if(siege.getAttackerBattlePoints() == 0 || siege.getDefenderBattlePoints() == 0) { diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index 4ad2ee417..c463de0e2 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -13,6 +13,7 @@ import com.palmergames.bukkit.towny.object.TownBlockType; import java.util.Map; +import java.util.UUID; /** * Util class containing methods related to town flags/permssions. @@ -71,15 +72,15 @@ public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { * Grant siege immunity to any nations who were the home nation of the town during the siege */ if(SiegeWarSettings.isPostWarNationImmunityEnabled() && siege.getSiegeType() != SiegeType.REVOLT) { - int totalBattles = siege.getTotalTownDefenceBattles(); + int totalBattles = siege.getTotalTownDefenceBattleSessions(); double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getPostWarNationImmunityDurationModifier(); int numBattlesFoughtByNation; double siegeImmunityRewardInMillis; - for(Map.Entry nationEntry: siege.getTownDefenceHomeNations().entrySet()) { - if(!nationEntry.getKey().equals("NO_HOME_NATION")) { - Nation nation = TownyUniverse.getInstance().getNation(nationEntry.getKey()); + for(Map.Entry townDefenceGovernmentEntry: siege.getTownDefenceGovernments().entrySet()) { + if(!townDefenceGovernmentEntry.getKey().equals(town.getUUID())) { + Nation nation = TownyUniverse.getInstance().getNation(townDefenceGovernmentEntry.getKey()); if(nation != null) { - numBattlesFoughtByNation = nationEntry.getValue(); + numBattlesFoughtByNation = townDefenceGovernmentEntry.getValue(); siegeImmunityRewardInMillis = immunityRewardDurationPerBattleInMillis * numBattlesFoughtByNation; grantSiegeImmunityToNation(nation, siegeImmunityRewardInMillis); } @@ -95,13 +96,15 @@ private static void grantSiegeImmunityToNation(Nation nation, double siegeImmuni * * Otherwise, grant the immunity immediately. */ + long pendingSiegeImmunityMillis = NationMetaDataController.getPendingSiegeImmunityMillis(nation); + if(SiegeController.doesNationHaveAnyHomeDefenceContributionsInActiveSieges(nation)) { - long pendingSiegeImmunityMillis = NationMetaDataController.getPendingSiegeImmunityMillis(nation); + //Make immunity pending pendingSiegeImmunityMillis += siegeImmunityMillis; NationMetaDataController.setPendingSiegeImmunityMillis(nation, pendingSiegeImmunityMillis); nation.save(); } else { - long pendingSiegeImmunityMillis = NationMetaDataController.getPendingSiegeImmunityMillis(nation); + //Grant immunity immediately long totalSiegeImmunityMillis = pendingSiegeImmunityMillis + (long)siegeImmunityMillis; for(Town nationTown: nation.getTowns()) { From 0f3a699d666e49e2cd11ac9a156d3ecaad18541c Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Tue, 27 Apr 2021 16:19:14 +0100 Subject: [PATCH 25/39] post war nation imm- set to disabled by default --- .../java/com/gmail/goosius/siegewar/settings/ConfigNodes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 edb61abf5..ae510c29c 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -713,7 +713,7 @@ public enum ConfigNodes { ""), POST_WAR_NATION_IMMUNITY_ENABLED( "post_war_nation_immunity.enabled", - "true", + "false", "", "# If this setting is true, then post-war nation immunity is enabled.", "# ", From e83159c4efc3be03888476412053731f6b37b72a Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 09:34:12 +0100 Subject: [PATCH 26/39] nation siege immunity bugfix --- .../SiegeWarNationEventListener.java | 19 +---------- .../listeners/SiegeWarTownEventListener.java | 6 ++-- .../siegewar/settings/ConfigNodes.java | 33 ++++++++++--------- .../siegewar/settings/SiegeWarSettings.java | 12 +++---- .../utils/SiegeWarBattleSessionUtil.java | 4 +-- .../siegewar/utils/SiegeWarMoneyUtil.java | 6 ++-- .../siegewar/utils/SiegeWarTownUtil.java | 20 ++++++++--- 7 files changed, 47 insertions(+), 53 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java index daf247c12..db65044e1 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarNationEventListener.java @@ -288,30 +288,13 @@ public void onTownTriesToLeaveNation(NationPreTownLeaveEvent event) { event.setCancelled(false); } - /** - * When a besieged town leaves a nation, - * pvp in the remaining towns is returned to the off state. - */ - @EventHandler - public void on(NationTownLeaveEvent event) { - if (SiegeWarSettings.getWarSiegeEnabled() - && SiegeWarSettings.isPostWarNationImmunityEnabled() - && SiegeController.hasActiveSiege(event.getTown())) { - - for(Town nationTown: event.getNation().getTowns()) { - if(nationTown != event.getTown() && !nationTown.isNeutral()) - SiegeWarTownUtil.setPvpFlag(nationTown, false); - } - } - } - /* * If nation is fighting a home-defence war it cannot add new towns */ @EventHandler public void on(NationPreAddTownEvent event) { if (SiegeWarSettings.getWarSiegeEnabled() - && SiegeWarSettings.isPostWarNationImmunityEnabled() + && SiegeWarSettings.isNationSiegeImmunityEnabled() && SiegeController.isNationFightingAHomeDefenceWar(event.getNation())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_cannot_recruit")); diff --git a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java index 77c2f54d8..eba9c68c3 100644 --- a/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java +++ b/src/main/java/com/gmail/goosius/siegewar/listeners/SiegeWarTownEventListener.java @@ -85,7 +85,7 @@ public void onTownAddResident(TownPreAddResidentEvent event) { } //Cannot recruit if nation is fighting a home-defence war - if (SiegeWarSettings.isPostWarNationImmunityEnabled() + if (SiegeWarSettings.isNationSiegeImmunityEnabled() && SiegeController.isTownsNationFightingAHomeDefenceWar(event.getTown())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_recruit")); @@ -218,7 +218,7 @@ public void onTownClaim(TownPreClaimEvent event) { } //If the town is fighting a home-defence war, they cannot claim any land - if (SiegeWarSettings.isPostWarNationImmunityEnabled() + if (SiegeWarSettings.isNationSiegeImmunityEnabled() && SiegeController.isTownsNationFightingAHomeDefenceWar(event.getTown())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_claim")); @@ -272,7 +272,7 @@ public void onTownUnclaim(TownPreUnclaimCmdEvent event) { } //Town fighting a home-defence war - if (SiegeWarSettings.isPostWarNationImmunityEnabled() + if (SiegeWarSettings.isNationSiegeImmunityEnabled() && SiegeController.isTownsNationFightingAHomeDefenceWar(event.getTown())) { event.setCancelled(true); event.setCancelMessage(Translation.of("plugin_prefix") + Translation.of("msg_err_siege_affected_home_nation_town_cannot_unclaim")); 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 ae510c29c..76177f5b7 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -702,24 +702,25 @@ public enum ConfigNodes { "# The banner xyz text is an alternative to beacon markers for siege banners (but they can also be used together).", "# If enabled, besieged towns will show the XYZ of the siege banner on their town screens."), - POST_WAR_NATION_IMMUNITY( - "post_war_nation_immunity", + NATION_SIEGE_IMMUNITY( + "nation_siege_immunity", "", "############################################################", "# +------------------------------------------------------------+ #", - "# | Post-War Nation Immunity | #", + "# | Nation Siege Immunity | #", "# +------------------------------------------------------------+ #", "#######################################################################", ""), - POST_WAR_NATION_IMMUNITY_ENABLED( - "post_war_nation_immunity.enabled", + NATION_SIEGE_IMMUNITY_ENABLED( + "nation_siege_immunity.enabled", "false", "", - "# If this setting is true, then post-war nation immunity is enabled.", + "# If this setting is true, then nation siege immunity is enabled.", "# ", - "# This feature gives each nation regular full-breaks from war, ", + "# This feature gives each nation regular breaks from war, ", "# by granting siege-immunity to all their towns after a home-defence war.", - "# (A home-defence war occurs when one or more of a nation's towns are under non-revolt sieges)", + "# ", + "# A home-defence war is a period in which one or more of a nation's towns are under siege.", "# ", "# NOTES:", "# 1. To mitigate exploits, nations suffer some mild negative effects while fighting a home-defence war - cannot claim/unclaim/recruit.", @@ -727,24 +728,24 @@ public enum ConfigNodes { "# 3. If a town switches home nation during a home-defence war", "# then when the home-defence war ends, the post-war immunity from that town,", "# is distributed between all the home nations which the town had during the siege."), - POST_WAR_NATION_IMMUNITY_DURATION_MODIFIER( - "post_war_nation_immunity.duration_modifier", + NATION_SIEGE_IMMUNITY_DURATION_MODIFIER( + "nation_siege_immunity.duration_modifier", "0.75", "", - "# This setting determines the duration ofsiege immunity which each nation town receives after a war period,", + "# This setting determines the duration of siege immunity which each nation town receives after a home defence war.", "# ", "# EXAMPLE:", - "# If this value is 0.75, and a nation fights continuously in home defence for 4 days,", - "# then at the end of the fighting, all nation hometowns will receive siege immunity of 3 days."), - POST_WAR_NATION_IMMUNITY_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST( - "post_war_nation_immunity.home_town_contribution_to_attack_cost", + "# If this value is 0.75, and a home defence war lasts 4 days,", + "# then at the end of the fighting, all nation towns will receive siege immunity of 3 days."), + NATION_SIEGE_IMMUNITY_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST( + "nation_siege_immunity.home_town_contribution_to_attack_cost", "0.1", "", "# If this setting is higher than 0,", "# then the larger a nation is, the higher the cost to attack one of its towns.", "# ", "# This setting is important to mitigate 'annoyance sieges', ", - "# because large nations are disproportionately affected by the mild nation-under-siege costs.", + "# because large nations are disproportionately affected by the mild home defence war restrictions.", "# Thus without mitigation, small nations could attack larger ones,", "# with no intention of fighting, but just to cheaply disrupt them.", "# ", diff --git a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java index 2853f38f5..96472cdbe 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/SiegeWarSettings.java @@ -397,15 +397,15 @@ public static boolean isTrapWarfareMitigationEnabled() { return Settings.getBoolean(ConfigNodes.WAR_SIEGE_SWITCHES_TRAP_WARFARE_MITIGATION_ENABLED); } - public static boolean isPostWarNationImmunityEnabled() { - return Settings.getBoolean(ConfigNodes.POST_WAR_NATION_IMMUNITY_ENABLED); + public static boolean isNationSiegeImmunityEnabled() { + return Settings.getBoolean(ConfigNodes.NATION_SIEGE_IMMUNITY_ENABLED); } - public static double getPostWarNationImmunityDurationModifier() { - return Settings.getDouble(ConfigNodes.POST_WAR_NATION_IMMUNITY_DURATION_MODIFIER); + public static double getNationSiegeImmunityDurationModifier() { + return Settings.getDouble(ConfigNodes.NATION_SIEGE_IMMUNITY_DURATION_MODIFIER); } - public static double getPostWarNationImmunityHomeTownContributionToAttackCost() { - return Settings.getDouble(ConfigNodes.POST_WAR_NATION_IMMUNITY_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST); + public static double getNationSiegeImmunityHomeTownContributionToAttackCost() { + return Settings.getDouble(ConfigNodes.NATION_SIEGE_IMMUNITY_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST); } } 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 99a4f865a..8a6a731c4 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java @@ -50,12 +50,12 @@ public static void evaluateBattleSessions() { try { if (siege.getStatus() == SiegeStatus.IN_PROGRESS) { //Record home nation if this is a town defence siege - if(siege.getSiegeType() != SiegeType.REVOLT) + if(SiegeWarSettings.isNationSiegeImmunityEnabled()) siege.recordTownDefenceGovernment(); //Continue to next siege if there were no battle points if(siege.getAttackerBattlePoints() == 0 || siege.getDefenderBattlePoints() == 0) { - if(siege.getSiegeType() != SiegeType.REVOLT) + if(SiegeWarSettings.isNationSiegeImmunityEnabled()) SiegeController.saveSiege(siege); continue; } diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java index 45b466f19..d9870f86c 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarMoneyUtil.java @@ -206,15 +206,15 @@ public static double calculateSiegeCost(Town town) { * town.getTownBlocks().size(); //Increase cost due to nation size - if(SiegeWarSettings.isPostWarNationImmunityEnabled() - && SiegeWarSettings.getPostWarNationImmunityHomeTownContributionToAttackCost() > 0 + if(SiegeWarSettings.isNationSiegeImmunityEnabled() + && SiegeWarSettings.getNationSiegeImmunityHomeTownContributionToAttackCost() > 0 && town.hasNation()) { try { Nation nation = town.getNation(); for (Town nationHomeTown : nation.getTowns()) { cost += SiegeWarSettings.getWarSiegeAttackerCostUpFrontPerPlot() * nationHomeTown.getTownBlocks().size() - * SiegeWarSettings.getPostWarNationImmunityHomeTownContributionToAttackCost(); + * SiegeWarSettings.getNationSiegeImmunityHomeTownContributionToAttackCost(); } } catch (NotRegisteredException ignored) {} } diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index c463de0e2..e6b58df63 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -71,15 +71,23 @@ public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { * If this was a town defence siege, * Grant siege immunity to any nations who were the home nation of the town during the siege */ - if(SiegeWarSettings.isPostWarNationImmunityEnabled() && siege.getSiegeType() != SiegeType.REVOLT) { + if(SiegeWarSettings.isNationSiegeImmunityEnabled()) { int totalBattles = siege.getTotalTownDefenceBattleSessions(); - double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getPostWarNationImmunityDurationModifier(); + double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getNationSiegeImmunityDurationModifier(); int numBattlesFoughtByNation; double siegeImmunityRewardInMillis; + + System.out.println("xxxTotal Battles" + totalBattles); + System.out.println("xxxReward Per battle" + immunityRewardDurationPerBattleInMillis); + + for(Map.Entry townDefenceGovernmentEntry: siege.getTownDefenceGovernments().entrySet()) { if(!townDefenceGovernmentEntry.getKey().equals(town.getUUID())) { Nation nation = TownyUniverse.getInstance().getNation(townDefenceGovernmentEntry.getKey()); if(nation != null) { + + System.out.println("Granting Immunity now"); + numBattlesFoughtByNation = townDefenceGovernmentEntry.getValue(); siegeImmunityRewardInMillis = immunityRewardDurationPerBattleInMillis * numBattlesFoughtByNation; grantSiegeImmunityToNation(nation, siegeImmunityRewardInMillis); @@ -105,11 +113,13 @@ private static void grantSiegeImmunityToNation(Nation nation, double siegeImmuni nation.save(); } else { //Grant immunity immediately - long totalSiegeImmunityMillis = pendingSiegeImmunityMillis + (long)siegeImmunityMillis; + long siegeImmunityToGrantMillis = pendingSiegeImmunityMillis + (long)siegeImmunityMillis; + double currentSiegeImmunityMillis; for(Town nationTown: nation.getTowns()) { - if(TownMetaDataController.getSiegeImmunityEndTime(nationTown) < siegeImmunityMillis) { - TownMetaDataController.setSiegeImmunityEndTime(nationTown, totalSiegeImmunityMillis); + currentSiegeImmunityMillis = TownMetaDataController.getSiegeImmunityEndTime(nationTown)- System.currentTimeMillis(); + if(currentSiegeImmunityMillis < siegeImmunityToGrantMillis) { + TownMetaDataController.setSiegeImmunityEndTime(nationTown, siegeImmunityToGrantMillis); nationTown.save(); } } From 1f34826a64b47a60021835f7cd3ff4763ca933ef Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 10:25:39 +0100 Subject: [PATCH 27/39] Cleanup --- .../goosius/siegewar/SiegeController.java | 6 ++-- .../siegewar/metadata/MetaDataUtil.java | 1 - .../metadata/SiegeMetaDataController.java | 12 ++++---- .../gmail/goosius/siegewar/objects/Siege.java | 28 ++++++++++--------- .../utils/SiegeWarBattleSessionUtil.java | 4 +-- .../siegewar/utils/SiegeWarTownUtil.java | 14 ++++------ 6 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index 787b7342f..abf3f4f98 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -90,7 +90,7 @@ public static void saveSiege(Siege siege) { SiegeMetaDataController.setEndTime(town, siege.getScheduledEndTime()); SiegeMetaDataController.setActualEndTime(town, siege.getActualEndTime()); SiegeMetaDataController.setAttackerSiegeContributors(town, siege.getAttackerSiegeContributors()); - SiegeMetaDataController.setTownDefenceGovernments(town, siege.getTownDefenceGovernments()); + SiegeMetaDataController.setPrimaryTownGovernments(town, siege.getPrimaryTownGovernments()); town.save(); } @@ -229,7 +229,7 @@ public static boolean loadSiege(Siege siege) { siege.setAttackerSiegeContributors(SiegeMetaDataController.getAttackerSiegeContributors(town)); - siege.setTownDefenceGovernments(SiegeMetaDataController.getTownDefenceGovernments(town)); + siege.setPrimaryTownGovernments(SiegeMetaDataController.getPrimaryTownGovernments(town)); return true; } @@ -584,7 +584,7 @@ private static void sendGlobalSiegeStartMessage(Siege siege) throws NotRegistere public static boolean doesNationHaveAnyHomeDefenceContributionsInActiveSieges(Nation nation) { for(Siege siege: townSiegeMap.values()) { if(siege.getStatus().isActive() - && siege.getTownDefenceGovernments().containsKey(nation.getUUID())) { + && siege.getPrimaryTownGovernments().containsKey(nation.getUUID())) { return true; } } diff --git a/src/main/java/com/gmail/goosius/siegewar/metadata/MetaDataUtil.java b/src/main/java/com/gmail/goosius/siegewar/metadata/MetaDataUtil.java index eb8aa805f..67fceb6df 100644 --- a/src/main/java/com/gmail/goosius/siegewar/metadata/MetaDataUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/metadata/MetaDataUtil.java @@ -1,6 +1,5 @@ package com.gmail.goosius.siegewar.metadata; -import com.palmergames.bukkit.towny.object.Government; import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.TownyObject; import com.palmergames.bukkit.towny.object.metadata.BooleanDataField; diff --git a/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java b/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java index 6e6cea930..66fa6339c 100644 --- a/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java +++ b/src/main/java/com/gmail/goosius/siegewar/metadata/SiegeMetaDataController.java @@ -50,7 +50,7 @@ public class SiegeMetaDataController { private static LongDataField endTime = new LongDataField("siegewar_endTime", 0l); private static LongDataField actualEndTime = new LongDataField("siegewar_actualEndTime", 0l); private static StringDataField attackerSiegeContributors = new StringDataField("siegewar_attackerSiegeContributors", ""); - private static StringDataField townDefenceGovernments = new StringDataField("siegewar_townDefenceGovernments", ""); + private static StringDataField primaryTownGovernments = new StringDataField("siegewar_primaryTownGovernments", ""); public SiegeMetaDataController(SiegeWar plugin) { this.plugin = plugin; @@ -362,8 +362,8 @@ public static Map getAttackerSiegeContributors(Town town) { } } - public static Map getTownDefenceGovernments(Town town) { - StringDataField sdf = (StringDataField) townDefenceGovernments.clone(); + public static Map getPrimaryTownGovernments(Town town) { + StringDataField sdf = (StringDataField) primaryTownGovernments.clone(); String dataAsString = null; if (town.hasMeta(sdf.getKey())) @@ -402,7 +402,7 @@ public static void setAttackerSiegeContributors(Town town, Map c town.addMetaData(new StringDataField("siegewar_attackerSiegeContributors", mapAsStringBuilder.toString())); } - public static void setTownDefenceGovernments(Town town, Map governmentsMap) { + public static void setPrimaryTownGovernments(Town town, Map governmentsMap) { StringBuilder mapAsStringBuilder = new StringBuilder(); boolean firstEntry = true; for(Map.Entry governmentEntry: governmentsMap.entrySet()) { @@ -414,10 +414,10 @@ public static void setTownDefenceGovernments(Town town, Map govern mapAsStringBuilder.append(governmentEntry.getKey()).append(":").append(governmentEntry.getValue()); } - StringDataField sdf = (StringDataField) townDefenceGovernments.clone(); + StringDataField sdf = (StringDataField) primaryTownGovernments.clone(); if (town.hasMeta(sdf.getKey())) MetaDataUtil.setString(town, sdf, mapAsStringBuilder.toString()); else - town.addMetaData(new StringDataField(townDefenceGovernments.getKey(), mapAsStringBuilder.toString())); + town.addMetaData(new StringDataField(primaryTownGovernments.getKey(), mapAsStringBuilder.toString())); } } diff --git a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java index a0ef71e85..9e53eeabb 100644 --- a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java +++ b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java @@ -57,7 +57,7 @@ public class Siege { private int defenderBattlePoints; private Set attackerBattleContributors; //UUID's of attackers who contributed during the current battle private Map attackerSiegeContributors; //UUID:numContributions map of attackers who contributed during current siege - private Map townDefenceGovernments; //UUID:numBattleSessions map of governments who led the defence of the town. If town is in nation, nation UUID will be used. If town is nationless, town UUID will be used + private Map primaryTownGovernments; //UUID:numBattleSessions map of governments who led the town during the siege. If town was is a nation, nation UUID will be used, otherwise town UUID will be used public Siege(Town town) { this.town = town; @@ -78,7 +78,7 @@ public Siege(Town town) { defenderBattlePoints = 0; attackerBattleContributors = new HashSet<>(); attackerSiegeContributors = new HashMap<>(); - townDefenceGovernments = new HashMap<>(); + primaryTownGovernments = new HashMap<>(); } public Town getTown() { @@ -406,12 +406,12 @@ public void setAttackerSiegeContributors(Map attackerSiegeContr this.attackerSiegeContributors = attackerSiegeContributors; } - public Map getTownDefenceGovernments() { - return townDefenceGovernments; + public Map getPrimaryTownGovernments() { + return primaryTownGovernments; } - public void setTownDefenceGovernments(Map townDefenceGovernments) { - this.townDefenceGovernments = townDefenceGovernments; + public void setPrimaryTownGovernments(Map primaryTownGovernments) { + this.primaryTownGovernments = primaryTownGovernments; } public void registerAttackerBattleContributorsFromBannerControl() { @@ -453,11 +453,13 @@ public void setSiegeType(SiegeType siegeType) { } /** - * Record who was the home nation of the town during a town defence battle session + * Record who is the primary government of the town + * If the town has a nation, nation govt will be recorded, + * otherwise town govt will be recorded * * @throws NotRegisteredException */ - public void recordTownDefenceGovernment() throws NotRegisteredException { + public void recordPrimaryTownGovernment() throws NotRegisteredException { //Identify key UUID governmentUUID; if(town.hasNation()) @@ -466,18 +468,18 @@ public void recordTownDefenceGovernment() throws NotRegisteredException { governmentUUID = town.getUUID(); //Record battle session contribution - if(townDefenceGovernments.containsKey(governmentUUID)) { - int numBattleSessions = townDefenceGovernments.get(governmentUUID); + if(primaryTownGovernments.containsKey(governmentUUID)) { + int numBattleSessions = primaryTownGovernments.get(governmentUUID); numBattleSessions++; - townDefenceGovernments.put(governmentUUID, numBattleSessions); + primaryTownGovernments.put(governmentUUID, numBattleSessions); } else { - townDefenceGovernments.put(governmentUUID, 1); + primaryTownGovernments.put(governmentUUID, 1); } } public int getTotalTownDefenceBattleSessions() { int result = 0; - for(int homeNationContribution: townDefenceGovernments.values()) { + for(int homeNationContribution: primaryTownGovernments.values()) { result += homeNationContribution; } return result; 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 8a6a731c4..31141be9f 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java @@ -49,9 +49,9 @@ public static void evaluateBattleSessions() { for (Siege siege : SiegeController.getSieges()) { try { if (siege.getStatus() == SiegeStatus.IN_PROGRESS) { - //Record home nation if this is a town defence siege + //Record primary government of besieged town if(SiegeWarSettings.isNationSiegeImmunityEnabled()) - siege.recordTownDefenceGovernment(); + siege.recordPrimaryTownGovernment(); //Continue to next siege if there were no battle points if(siege.getAttackerBattlePoints() == 0 || siege.getDefenderBattlePoints() == 0) { diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index e6b58df63..e7d191c3e 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -68,28 +68,26 @@ public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { town.save(); /* - * If this was a town defence siege, * Grant siege immunity to any nations who were the home nation of the town during the siege */ if(SiegeWarSettings.isNationSiegeImmunityEnabled()) { int totalBattles = siege.getTotalTownDefenceBattleSessions(); double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getNationSiegeImmunityDurationModifier(); - int numBattlesFoughtByNation; + int numBattleSessionsForNation; double siegeImmunityRewardInMillis; System.out.println("xxxTotal Battles" + totalBattles); System.out.println("xxxReward Per battle" + immunityRewardDurationPerBattleInMillis); - - for(Map.Entry townDefenceGovernmentEntry: siege.getTownDefenceGovernments().entrySet()) { - if(!townDefenceGovernmentEntry.getKey().equals(town.getUUID())) { - Nation nation = TownyUniverse.getInstance().getNation(townDefenceGovernmentEntry.getKey()); + for(Map.Entry primaryTownGovernmentEntry: siege.getPrimaryTownGovernments().entrySet()) { + if(!primaryTownGovernmentEntry.getKey().equals(town.getUUID())) { + Nation nation = TownyUniverse.getInstance().getNation(primaryTownGovernmentEntry.getKey()); if(nation != null) { System.out.println("Granting Immunity now"); - numBattlesFoughtByNation = townDefenceGovernmentEntry.getValue(); - siegeImmunityRewardInMillis = immunityRewardDurationPerBattleInMillis * numBattlesFoughtByNation; + numBattleSessionsForNation = primaryTownGovernmentEntry.getValue(); + siegeImmunityRewardInMillis = immunityRewardDurationPerBattleInMillis * numBattleSessionsForNation; grantSiegeImmunityToNation(nation, siegeImmunityRewardInMillis); } } From bdbddacc7466821194bd17596ca282945d5706bd Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 10:51:07 +0100 Subject: [PATCH 28/39] Cleanup --- src/main/java/com/gmail/goosius/siegewar/objects/Siege.java | 6 +++--- .../com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java index 9e53eeabb..f5ca40b41 100644 --- a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java +++ b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java @@ -454,8 +454,8 @@ public void setSiegeType(SiegeType siegeType) { /** * Record who is the primary government of the town - * If the town has a nation, nation govt will be recorded, - * otherwise town govt will be recorded + * If the town has a nation, nation uuid will be recorded, + * otherwise town uuid will be recorded. * * @throws NotRegisteredException */ @@ -477,7 +477,7 @@ public void recordPrimaryTownGovernment() throws NotRegisteredException { } } - public int getTotalTownDefenceBattleSessions() { + public int getTotalBattleSessions() { int result = 0; for(int homeNationContribution: primaryTownGovernments.values()) { result += homeNationContribution; diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index e7d191c3e..2eaf385cd 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -1,7 +1,6 @@ package com.gmail.goosius.siegewar.utils; import com.gmail.goosius.siegewar.SiegeController; -import com.gmail.goosius.siegewar.enums.SiegeType; import com.gmail.goosius.siegewar.metadata.NationMetaDataController; import com.gmail.goosius.siegewar.metadata.TownMetaDataController; import com.gmail.goosius.siegewar.objects.Siege; @@ -71,7 +70,7 @@ public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { * Grant siege immunity to any nations who were the home nation of the town during the siege */ if(SiegeWarSettings.isNationSiegeImmunityEnabled()) { - int totalBattles = siege.getTotalTownDefenceBattleSessions(); + int totalBattles = siege.getTotalBattleSessions(); double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getNationSiegeImmunityDurationModifier(); int numBattleSessionsForNation; double siegeImmunityRewardInMillis; From d6cd641a0b07d5e2984e800507c056da5708521d Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 11:13:40 +0100 Subject: [PATCH 29/39] cleanup --- .../java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index 2eaf385cd..270068c14 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -121,7 +121,7 @@ private static void grantSiegeImmunityToNation(Nation nation, double siegeImmuni } } - NationMetaDataController.setPendingSiegeImmunityMillis(nation, 0); + NationMetaDataController.removePendingSiegeImmunityMillis(nation); nation.save(); } } From a618098955576476f8c63fdde0bdf069d027450e Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 12:38:14 +0100 Subject: [PATCH 30/39] Nation siege immunity bug fix --- .../siegewar/utils/SiegeWarTownUtil.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index 270068c14..9c04cb325 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -94,29 +94,28 @@ public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { } } - private static void grantSiegeImmunityToNation(Nation nation, double siegeImmunityMillis) { + private static void grantSiegeImmunityToNation(Nation nation, double siegeImmunityDurationMillis) { /* * If the nation has contributions in active sieges, make the immunity pending. * (i.e. wait until those sieges end until it is granted) * * Otherwise, grant the immunity immediately. */ - long pendingSiegeImmunityMillis = NationMetaDataController.getPendingSiegeImmunityMillis(nation); + long pendingSiegeImmunityDurationMillis = NationMetaDataController.getPendingSiegeImmunityMillis(nation); if(SiegeController.doesNationHaveAnyHomeDefenceContributionsInActiveSieges(nation)) { //Make immunity pending - pendingSiegeImmunityMillis += siegeImmunityMillis; - NationMetaDataController.setPendingSiegeImmunityMillis(nation, pendingSiegeImmunityMillis); + pendingSiegeImmunityDurationMillis += siegeImmunityDurationMillis; + NationMetaDataController.setPendingSiegeImmunityMillis(nation, pendingSiegeImmunityDurationMillis); nation.save(); } else { //Grant immunity immediately - long siegeImmunityToGrantMillis = pendingSiegeImmunityMillis + (long)siegeImmunityMillis; - double currentSiegeImmunityMillis; + long totalSiegeImmunityDurationMillis = pendingSiegeImmunityDurationMillis + (long)siegeImmunityDurationMillis; + long siegeImmunityEndTime = System.currentTimeMillis() + totalSiegeImmunityDurationMillis; for(Town nationTown: nation.getTowns()) { - currentSiegeImmunityMillis = TownMetaDataController.getSiegeImmunityEndTime(nationTown)- System.currentTimeMillis(); - if(currentSiegeImmunityMillis < siegeImmunityToGrantMillis) { - TownMetaDataController.setSiegeImmunityEndTime(nationTown, siegeImmunityToGrantMillis); + if(siegeImmunityEndTime > TownMetaDataController.getSiegeImmunityEndTime(nationTown)) { + TownMetaDataController.setSiegeImmunityEndTime(nationTown, siegeImmunityEndTime); nationTown.save(); } } From 03ada299e9c25e4a4da16347e1dbb352a6990670 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 13:16:06 +0100 Subject: [PATCH 31/39] Blurb update --- .../gmail/goosius/siegewar/settings/ConfigNodes.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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 76177f5b7..68e1e5e1b 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -730,13 +730,18 @@ public enum ConfigNodes { "# is distributed between all the home nations which the town had during the siege."), NATION_SIEGE_IMMUNITY_DURATION_MODIFIER( "nation_siege_immunity.duration_modifier", - "0.75", + "0.5", "", "# This setting determines the duration of siege immunity which each nation town receives after a home defence war.", "# ", + "# FORMULA:", + "# Nation-Town Immunity Duration = Total Duration of Sieges x This Value.", + "# ", "# EXAMPLE:", - "# If this value is 0.75, and a home defence war lasts 4 days,", - "# then at the end of the fighting, all nation towns will receive siege immunity of 3 days."), + "# A nation suffers a big home defence war, of 4 sieges, with each siege lasting 3 days.", + "# This gives a Total Siege Duration of 12 days", + "# If this value is 0.5, then immunity duration will be 6 days", + "# Thus each non-besieged nation town will get 6 days of siege immunity."), NATION_SIEGE_IMMUNITY_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST( "nation_siege_immunity.home_town_contribution_to_attack_cost", "0.1", From e9cfe6aef347767d016302cfe849403127194b09 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 14:01:50 +0100 Subject: [PATCH 32/39] Removed dev artefact --- .../com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index 9c04cb325..a9d513247 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -75,16 +75,10 @@ public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { int numBattleSessionsForNation; double siegeImmunityRewardInMillis; - System.out.println("xxxTotal Battles" + totalBattles); - System.out.println("xxxReward Per battle" + immunityRewardDurationPerBattleInMillis); - for(Map.Entry primaryTownGovernmentEntry: siege.getPrimaryTownGovernments().entrySet()) { if(!primaryTownGovernmentEntry.getKey().equals(town.getUUID())) { Nation nation = TownyUniverse.getInstance().getNation(primaryTownGovernmentEntry.getKey()); if(nation != null) { - - System.out.println("Granting Immunity now"); - numBattleSessionsForNation = primaryTownGovernmentEntry.getValue(); siegeImmunityRewardInMillis = immunityRewardDurationPerBattleInMillis * numBattleSessionsForNation; grantSiegeImmunityToNation(nation, siegeImmunityRewardInMillis); From 7bacb4283941206024d4b72693e9985a26430af7 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 14:23:48 +0100 Subject: [PATCH 33/39] Cleanup --- .../java/com/gmail/goosius/siegewar/objects/Siege.java | 8 +++++++- src/main/resources/english.yml | 2 +- src/main/resources/french.yml | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java index a35be3174..48aa19b2e 100644 --- a/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java +++ b/src/main/java/com/gmail/goosius/siegewar/objects/Siege.java @@ -13,7 +13,13 @@ import org.bukkit.Location; import org.bukkit.entity.Player; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.HashSet; +import java.util.UUID; import static com.palmergames.util.TimeMgmt.ONE_HOUR_IN_MILLIS; diff --git a/src/main/resources/english.yml b/src/main/resources/english.yml index fe287d495..887f00667 100644 --- a/src/main/resources/english.yml +++ b/src/main/resources/english.yml @@ -411,7 +411,7 @@ status_nation_plunder_stats: '&2Town Plunder History - Gains/Losses: &a%d&2/&a%d #Siege effects msg_err_siege_war_cannot_spawn_into_siegezone_or_besieged_town: '&cOnly town residents can spawn into a besieged town or siege zone.' -#Post-War Nation Immunity +#Nation Siege Immunity msg_err_siege_affected_home_nation_cannot_recruit: "&cThe nation cannot add new towns, because one of its home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_recruit: "&cThe town cannot add new residents, because one of its nation's home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_claim: "&cCannot claim land, because one of your nation's home towns is under siege attack." diff --git a/src/main/resources/french.yml b/src/main/resources/french.yml index ccc9e11cc..c2e8c2f65 100644 --- a/src/main/resources/french.yml +++ b/src/main/resources/french.yml @@ -422,7 +422,7 @@ status_nation_plunder_stats: '&2Town Plunder History - Gains/Losses: &a%d&2/&a%d #Siege effects msg_err_siege_war_cannot_spawn_into_siegezone_or_besieged_town: '&cOnly town residents can spawn into a besieged town or siege zone.' -#Post-War Nation Immunity +#Nation Siege Immunity msg_err_siege_affected_home_nation_cannot_recruit: "&cThe nation cannot add new towns, because one of its home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_recruit: "&cThe town cannot add new residents, because one of its nation's home towns is under siege attack." msg_err_siege_affected_home_nation_town_cannot_claim: "&cCannot claim land, because one of your nation's home towns is under siege attack." From bd08812c3abbcb61b4031d63f56b1a11e41d3073 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 14:26:27 +0100 Subject: [PATCH 34/39] Nation siege immunity - comment update and removed incorrect restriction --- src/main/java/com/gmail/goosius/siegewar/SiegeController.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index 623efa161..5428f2c5f 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -397,8 +397,7 @@ public static Map getActiveDefensiveSieges(Nation nation) { * @param town the town to check * @return true if the town has a nation & that nation is fighting a home-defence war * - * Note: A home defence war is when one of the nation's towns is under siege attack. - * (In other words, it has an active siege of any type except Revolt.) + * Note: A home defence war is when one or more of the nation's home towns is under siege. */ public static boolean isTownsNationFightingAHomeDefenceWar(Town town) { try { @@ -419,7 +418,6 @@ public static boolean isNationFightingAHomeDefenceWar(Nation nation) { for(Siege siege: SiegeController.getSieges()) { try { if(siege.getStatus().isActive() - && siege.getSiegeType() != SiegeType.REVOLT && siege.getTown().hasNation() && siege.getTown().getNation() == nation) { return true; From c6e1ee3358841c22c6778655d384f3a66b96709d Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 14:29:56 +0100 Subject: [PATCH 35/39] Reverted comment removal --- .../com/gmail/goosius/siegewar/playeractions/PlaceBlock.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java index 9b2395ac8..626ae453e 100644 --- a/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java +++ b/src/main/java/com/gmail/goosius/siegewar/playeractions/PlaceBlock.java @@ -287,6 +287,7 @@ private static synchronized void evaluateStartNewSiegeAttempt(Player player, StartLiberationSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); } } else { + //Conquest siege StartConquestSiege.processStartSiegeRequest(player, residentsTown, residentsNation, nearbyTownBlock, nearbyTown, bannerBlock); } } From ba0a227f7526a966d3278dcab914031cc2f81115 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 17:27:12 +0100 Subject: [PATCH 36/39] Changes in response to CR --- .../goosius/siegewar/SiegeController.java | 9 +- .../siegewar/settings/ConfigNodes.java | 9 +- .../siegewar/timeractions/AttackerWin.java | 4 +- .../siegewar/timeractions/DefenderWin.java | 4 +- .../utils/SiegeWarBattleSessionUtil.java | 2 +- .../siegewar/utils/SiegeWarImmunityUtil.java | 111 ++++++++++++++++++ .../utils/SiegeWarSiegeCompletionUtil.java | 2 +- .../siegewar/utils/SiegeWarTimeUtil.java | 32 ----- .../siegewar/utils/SiegeWarTownUtil.java | 70 ----------- 9 files changed, 125 insertions(+), 118 deletions(-) create mode 100644 src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarImmunityUtil.java delete mode 100644 src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index 5428f2c5f..622a3fa2a 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -17,8 +17,7 @@ import com.gmail.goosius.siegewar.events.SiegeWarStartEvent; import com.gmail.goosius.siegewar.settings.SiegeWarSettings; import com.gmail.goosius.siegewar.settings.Translation; -import com.gmail.goosius.siegewar.utils.CosmeticUtil; -import com.gmail.goosius.siegewar.utils.SiegeWarDistanceUtil; +import com.gmail.goosius.siegewar.utils.*; import com.palmergames.bukkit.towny.TownyEconomyHandler; import com.palmergames.bukkit.towny.TownyMessaging; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; @@ -34,8 +33,6 @@ import com.gmail.goosius.siegewar.enums.SiegeSide; import com.gmail.goosius.siegewar.metadata.SiegeMetaDataController; import com.gmail.goosius.siegewar.objects.Siege; -import com.gmail.goosius.siegewar.utils.SiegeWarMoneyUtil; -import com.gmail.goosius.siegewar.utils.SiegeWarTownUtil; import com.palmergames.bukkit.towny.TownyAPI; import com.palmergames.bukkit.towny.TownyUniverse; import com.palmergames.bukkit.towny.object.Nation; @@ -239,7 +236,7 @@ public static void removeSiege(Siege siege, SiegeSide refundSideIfSiegeIsActive) //If siege is active, initiate siege immunity for town, and return war chest if(siege.getStatus().isActive()) { siege.setActualEndTime(System.currentTimeMillis()); - SiegeWarTownUtil.grantSiegeImmunityAfterEndedSiege(siege.getTown(), siege); + SiegeWarImmunityUtil.grantSiegeImmunityAfterEndedSiege(siege.getTown(), siege); //Return warchest only if siege is not revolt if(siege.getSiegeType() != SiegeType.REVOLT) { @@ -397,7 +394,7 @@ public static Map getActiveDefensiveSieges(Nation nation) { * @param town the town to check * @return true if the town has a nation & that nation is fighting a home-defence war * - * Note: A home defence war is when one or more of the nation's home towns is under siege. + * Note: A home defence war is when one or more of the nation's natural towns (ie not occupied foreign towns) is under siege. */ public static boolean isTownsNationFightingAHomeDefenceWar(Town town) { try { 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 68e1e5e1b..89e804bb6 100644 --- a/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java +++ b/src/main/java/com/gmail/goosius/siegewar/settings/ConfigNodes.java @@ -725,9 +725,10 @@ public enum ConfigNodes { "# NOTES:", "# 1. To mitigate exploits, nations suffer some mild negative effects while fighting a home-defence war - cannot claim/unclaim/recruit.", "# 2. To mitigate annoyance-sieges, the cost to attack a nation's towns increases as that nation increases in size.", - "# 3. If a town switches home nation during a home-defence war", + "# 3. If a town switches nation during a home-defence war", "# then when the home-defence war ends, the post-war immunity from that town,", - "# is distributed between all the home nations which the town had during the siege."), + "# is distributed between all the nations which the town had during the siege", + "# (but not any occupying nation)."), NATION_SIEGE_IMMUNITY_DURATION_MODIFIER( "nation_siege_immunity.duration_modifier", "0.5", @@ -741,7 +742,7 @@ public enum ConfigNodes { "# A nation suffers a big home defence war, of 4 sieges, with each siege lasting 3 days.", "# This gives a Total Siege Duration of 12 days", "# If this value is 0.5, then immunity duration will be 6 days", - "# Thus each non-besieged nation town will get 6 days of siege immunity."), + "# Thus when the war ends, each non-besieged nation town will get 6 days of siege immunity."), NATION_SIEGE_IMMUNITY_HOME_TOWN_CONTRIBUTION_TO_ATTACK_COST( "nation_siege_immunity.home_town_contribution_to_attack_cost", "0.1", @@ -757,7 +758,7 @@ public enum ConfigNodes { "# EXAMPLE:", "# If this setting is 0.1,", "# and an attack is attempted on a nation town,", - "# then for every home town in that nation (including the attacked one),", + "# then for every natural town (i.e. not occupied foreign towns) in that nation,", "# the attack-cost (i.e. warchest) requirement is increased by 10% of the amount it would take to attack that town."); private final String Root; diff --git a/src/main/java/com/gmail/goosius/siegewar/timeractions/AttackerWin.java b/src/main/java/com/gmail/goosius/siegewar/timeractions/AttackerWin.java index 7276a1bb4..2176fb257 100644 --- a/src/main/java/com/gmail/goosius/siegewar/timeractions/AttackerWin.java +++ b/src/main/java/com/gmail/goosius/siegewar/timeractions/AttackerWin.java @@ -5,7 +5,7 @@ import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.utils.SiegeWarMoneyUtil; import com.gmail.goosius.siegewar.utils.SiegeWarSiegeCompletionUtil; -import com.gmail.goosius.siegewar.utils.SiegeWarTimeUtil; +import com.gmail.goosius.siegewar.utils.SiegeWarImmunityUtil; /** * This class is responsible for processing all types of attacker wins @@ -26,7 +26,7 @@ public static void attackerWin(Siege siege, SiegeStatus siegeStatus) { case CONQUEST: case SUPPRESSION: SiegeWarMoneyUtil.giveWarChestTo(siege, siege.getAttacker()); - SiegeWarTimeUtil.activateRevoltImmunityTimer(siege.getTown()); + SiegeWarImmunityUtil.activateRevoltImmunityTimer(siege.getTown()); break; case LIBERATION: SiegeWarMoneyUtil.giveWarChestTo(siege, siege.getAttacker()); diff --git a/src/main/java/com/gmail/goosius/siegewar/timeractions/DefenderWin.java b/src/main/java/com/gmail/goosius/siegewar/timeractions/DefenderWin.java index 477850058..27a9fa1f3 100644 --- a/src/main/java/com/gmail/goosius/siegewar/timeractions/DefenderWin.java +++ b/src/main/java/com/gmail/goosius/siegewar/timeractions/DefenderWin.java @@ -5,7 +5,7 @@ import com.gmail.goosius.siegewar.objects.Siege; import com.gmail.goosius.siegewar.utils.SiegeWarMoneyUtil; import com.gmail.goosius.siegewar.utils.SiegeWarSiegeCompletionUtil; -import com.gmail.goosius.siegewar.utils.SiegeWarTimeUtil; +import com.gmail.goosius.siegewar.utils.SiegeWarImmunityUtil; /** * This class is responsible for processing siege defender wins @@ -34,7 +34,7 @@ public static void defenderWin(Siege siege, SiegeStatus siegeStatus) { TownOccupationController.removeTownOccupation(siege.getTown()); break; case REVOLT: - SiegeWarTimeUtil.activateRevoltImmunityTimer(siege.getTown()); + SiegeWarImmunityUtil.activateRevoltImmunityTimer(siege.getTown()); break; } } 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 dcf783e99..702c0fd11 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarBattleSessionUtil.java @@ -54,7 +54,7 @@ public static void evaluateBattleSessions() { siege.recordPrimaryTownGovernment(); //Continue to next siege if there were no battle points - if(siege.getAttackerBattlePoints() == 0 || siege.getDefenderBattlePoints() == 0) { + if(siege.getAttackerBattlePoints() == 0 && siege.getDefenderBattlePoints() == 0) { if(SiegeWarSettings.isNationSiegeImmunityEnabled()) SiegeController.saveSiege(siege); continue; diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarImmunityUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarImmunityUtil.java new file mode 100644 index 000000000..85639aff4 --- /dev/null +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarImmunityUtil.java @@ -0,0 +1,111 @@ +package com.gmail.goosius.siegewar.utils; + +import com.gmail.goosius.siegewar.SiegeController; +import com.gmail.goosius.siegewar.metadata.NationMetaDataController; +import com.gmail.goosius.siegewar.metadata.TownMetaDataController; +import com.gmail.goosius.siegewar.objects.Siege; +import com.gmail.goosius.siegewar.settings.SiegeWarSettings; +import com.palmergames.bukkit.towny.TownyUniverse; +import com.palmergames.bukkit.towny.object.Nation; +import com.palmergames.bukkit.towny.object.Town; + +import java.util.Map; +import java.util.UUID; + +/** + * This class contains utility functions related to siege/revolt immunity + * + * @author Goosius + */ +public class SiegeWarImmunityUtil { + + /** + * Activate the revolt immunity timer for a town + * + * While this timer is active, the town cannot start a revolt siege. + * When this timer hits 0, the town can start a revolt siege. + * + * Note: + * Siege immunity does not block revolts; + * only revolt immunity blocks revolts. + * + * @param town the town + */ + public static void activateRevoltImmunityTimer(Town town) { + long siegeImmunityDurationMillis = TownMetaDataController.getSiegeImmunityEndTime(town) - System.currentTimeMillis(); + long revoltImmunityDurationMillis = (long)(siegeImmunityDurationMillis * SiegeWarSettings.getWarSiegeRevoltImmunityTimeModifier()); + long revoltImmunityEndTime = System.currentTimeMillis() + revoltImmunityDurationMillis; + TownMetaDataController.setRevoltImmunityEndTime(town, revoltImmunityEndTime); + } + + /** + * The siege ended. + * + * 1. Grant siege immunity to the town which was besieged. + * 2. If the town was the defender, + * grant siege immunity to any nations who were the home nation of the town during the siege + * + * @param town the town which was besieged + * @param siege the siege + */ + public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { + //Grant siege immunity to town + double siegeDurationMillis = siege.getActualEndTime() - siege.getStartTime(); + double immunityDurationMillisDouble = siegeDurationMillis * SiegeWarSettings.getWarSiegeSiegeImmunityTimeModifier(); + long immunityDurationMillis = (long)(immunityDurationMillisDouble + 0.5); + TownMetaDataController.setSiegeImmunityEndTime(town, System.currentTimeMillis() + immunityDurationMillis); + town.save(); + + /* + * Grant siege immunity to any nations who were the home nation of the town during the siege + */ + if(SiegeWarSettings.isNationSiegeImmunityEnabled()) { + int totalBattles = siege.getTotalBattleSessions(); + double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getNationSiegeImmunityDurationModifier(); + int numBattleSessionsForNation; + double siegeImmunityRewardInMillis; + + for(Map.Entry primaryTownGovernmentEntry: siege.getPrimaryTownGovernments().entrySet()) { + if(!primaryTownGovernmentEntry.getKey().equals(town.getUUID())) { + Nation nation = TownyUniverse.getInstance().getNation(primaryTownGovernmentEntry.getKey()); + if(nation != null) { + numBattleSessionsForNation = primaryTownGovernmentEntry.getValue(); + siegeImmunityRewardInMillis = immunityRewardDurationPerBattleInMillis * numBattleSessionsForNation; + grantSiegeImmunityToNation(nation, siegeImmunityRewardInMillis); + } + } + } + } + } + + private static void grantSiegeImmunityToNation(Nation nation, double siegeImmunityDurationMillis) { + /* + * If the nation has contributions in active sieges, make the immunity pending. + * (i.e. wait until those sieges end until it is granted) + * + * Otherwise, grant the immunity immediately. + */ + long pendingSiegeImmunityDurationMillis = NationMetaDataController.getPendingSiegeImmunityMillis(nation); + + if(SiegeController.doesNationHaveAnyHomeDefenceContributionsInActiveSieges(nation)) { + //Make immunity pending + pendingSiegeImmunityDurationMillis += siegeImmunityDurationMillis; + NationMetaDataController.setPendingSiegeImmunityMillis(nation, pendingSiegeImmunityDurationMillis); + nation.save(); + } else { + //Grant immunity immediately + long totalSiegeImmunityDurationMillis = pendingSiegeImmunityDurationMillis + (long)siegeImmunityDurationMillis; + long siegeImmunityEndTime = System.currentTimeMillis() + totalSiegeImmunityDurationMillis; + + for(Town nationTown: nation.getTowns()) { + if(siegeImmunityEndTime > TownMetaDataController.getSiegeImmunityEndTime(nationTown)) { + TownMetaDataController.setSiegeImmunityEndTime(nationTown, siegeImmunityEndTime); + nationTown.save(); + } + } + + NationMetaDataController.removePendingSiegeImmunityMillis(nation); + nation.save(); + } + } +} diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java index 3252f83d8..dd70691fd 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarSiegeCompletionUtil.java @@ -29,7 +29,7 @@ public static void setCommonSiegeCompletionValues(Siege siege, siege.clearBannerControllingResidents(); siege.clearBannerControlSessions(); siege.setActualEndTime(System.currentTimeMillis()); - SiegeWarTownUtil.grantSiegeImmunityAfterEndedSiege(siege.getTown(), siege); + SiegeWarImmunityUtil.grantSiegeImmunityAfterEndedSiege(siege.getTown(), siege); SiegeWarTownUtil.setPvpFlag(siege.getTown(), false); CosmeticUtil.removeFakeBeacons(siege); diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java deleted file mode 100644 index 72309fed7..000000000 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTimeUtil.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.gmail.goosius.siegewar.utils; - -import com.gmail.goosius.siegewar.metadata.TownMetaDataController; -import com.gmail.goosius.siegewar.settings.SiegeWarSettings; -import com.palmergames.bukkit.towny.object.Town; - -/** - * This class contains utility functions related siege timings - * - * @author Goosius - */ -public class SiegeWarTimeUtil { - - /** - * Activate the revolt immunity timer for a town - * - * While this timer is active, the town cannot start a revolt siege. - * When this timer hits 0, the town can start a revolt siege. - * - * Note: - * Siege immunity does not block revolts; - * only revolt immunity blocks revolts. - * - * @param town the town - */ - public static void activateRevoltImmunityTimer(Town town) { - long siegeImmunityDurationMillis = TownMetaDataController.getSiegeImmunityEndTime(town) - System.currentTimeMillis(); - long revoltImmunityDurationMillis = (long)(siegeImmunityDurationMillis * SiegeWarSettings.getWarSiegeRevoltImmunityTimeModifier()); - long revoltImmunityEndTime = System.currentTimeMillis() + revoltImmunityDurationMillis; - TownMetaDataController.setRevoltImmunityEndTime(town, revoltImmunityEndTime); - } -} diff --git a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java index a9d513247..7735a8d68 100644 --- a/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java +++ b/src/main/java/com/gmail/goosius/siegewar/utils/SiegeWarTownUtil.java @@ -48,74 +48,4 @@ public static void setPvpFlag(Town town, boolean desiredSetting) { } } - /** - * The siege ended. - * - * 1. Grant siege immunity to the town which was besieged. - * 2. If the town was the defender, - * grant siege immunity to any nations who were the home nation of the town during the siege - * - * @param town the town which was besieged - * @param siege the siege - */ - public static void grantSiegeImmunityAfterEndedSiege(Town town, Siege siege) { - //Grant siege immunity to town - double siegeDurationMillis = siege.getActualEndTime() - siege.getStartTime(); - double immunityDurationMillisDouble = siegeDurationMillis * SiegeWarSettings.getWarSiegeSiegeImmunityTimeModifier(); - long immunityDurationMillis = (long)(immunityDurationMillisDouble + 0.5); - TownMetaDataController.setSiegeImmunityEndTime(town, System.currentTimeMillis() + immunityDurationMillis); - town.save(); - - /* - * Grant siege immunity to any nations who were the home nation of the town during the siege - */ - if(SiegeWarSettings.isNationSiegeImmunityEnabled()) { - int totalBattles = siege.getTotalBattleSessions(); - double immunityRewardDurationPerBattleInMillis = siegeDurationMillis / totalBattles * SiegeWarSettings.getNationSiegeImmunityDurationModifier(); - int numBattleSessionsForNation; - double siegeImmunityRewardInMillis; - - for(Map.Entry primaryTownGovernmentEntry: siege.getPrimaryTownGovernments().entrySet()) { - if(!primaryTownGovernmentEntry.getKey().equals(town.getUUID())) { - Nation nation = TownyUniverse.getInstance().getNation(primaryTownGovernmentEntry.getKey()); - if(nation != null) { - numBattleSessionsForNation = primaryTownGovernmentEntry.getValue(); - siegeImmunityRewardInMillis = immunityRewardDurationPerBattleInMillis * numBattleSessionsForNation; - grantSiegeImmunityToNation(nation, siegeImmunityRewardInMillis); - } - } - } - } - } - - private static void grantSiegeImmunityToNation(Nation nation, double siegeImmunityDurationMillis) { - /* - * If the nation has contributions in active sieges, make the immunity pending. - * (i.e. wait until those sieges end until it is granted) - * - * Otherwise, grant the immunity immediately. - */ - long pendingSiegeImmunityDurationMillis = NationMetaDataController.getPendingSiegeImmunityMillis(nation); - - if(SiegeController.doesNationHaveAnyHomeDefenceContributionsInActiveSieges(nation)) { - //Make immunity pending - pendingSiegeImmunityDurationMillis += siegeImmunityDurationMillis; - NationMetaDataController.setPendingSiegeImmunityMillis(nation, pendingSiegeImmunityDurationMillis); - nation.save(); - } else { - //Grant immunity immediately - long totalSiegeImmunityDurationMillis = pendingSiegeImmunityDurationMillis + (long)siegeImmunityDurationMillis; - long siegeImmunityEndTime = System.currentTimeMillis() + totalSiegeImmunityDurationMillis; - - for(Town nationTown: nation.getTowns()) { - if(siegeImmunityEndTime > TownMetaDataController.getSiegeImmunityEndTime(nationTown)) { - TownMetaDataController.setSiegeImmunityEndTime(nationTown, siegeImmunityEndTime); - nationTown.save(); - } - } - - NationMetaDataController.removePendingSiegeImmunityMillis(nation); - nation.save(); - } - } } \ No newline at end of file From 20c08c82feba1654e4089fbaf01654a895c4cef0 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 17:30:55 +0100 Subject: [PATCH 37/39] Comment update --- src/main/java/com/gmail/goosius/siegewar/SiegeController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index 622a3fa2a..8e9c3f1b3 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -409,7 +409,7 @@ public static boolean isTownsNationFightingAHomeDefenceWar(Town town) { * @param nation the nation to check * @return true if the given nation is fighting a home-defence war * - * Note: A home defence war is when one of the nation's towns is is under a non-revolt siege. + * Note: A home defence war is when one or more of the nation's natural towns (ie not occupied foreign towns) is under siege. */ public static boolean isNationFightingAHomeDefenceWar(Nation nation) { for(Siege siege: SiegeController.getSieges()) { From cf682283d5300d6bc1afa830a01716d4efab0145 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 17:33:37 +0100 Subject: [PATCH 38/39] Import fix --- .../java/com/gmail/goosius/siegewar/SiegeController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index 8e9c3f1b3..c2cad9f84 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -17,7 +17,11 @@ import com.gmail.goosius.siegewar.events.SiegeWarStartEvent; import com.gmail.goosius.siegewar.settings.SiegeWarSettings; import com.gmail.goosius.siegewar.settings.Translation; -import com.gmail.goosius.siegewar.utils.*; +import com.gmail.goosius.siegewar.utils.CosmeticUtil; +import com.gmail.goosius.siegewar.utils.SiegeWarDistanceUtil; +import com.gmail.goosius.siegewar.utils.SiegeWarMoneyUtil; +import com.gmail.goosius.siegewar.utils.SiegeWarImmunityUtil; +import com.gmail.goosius.siegewar.utils.SiegeWarTownUtil; import com.palmergames.bukkit.towny.TownyEconomyHandler; import com.palmergames.bukkit.towny.TownyMessaging; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; From b1e019a61d0ebb529c17d5eb3f24df3bfaa51c06 Mon Sep 17 00:00:00 2001 From: goosius1 <=> Date: Wed, 28 Apr 2021 17:35:13 +0100 Subject: [PATCH 39/39] reverted import change --- .../java/com/gmail/goosius/siegewar/SiegeController.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java index c2cad9f84..f26d84c9b 100644 --- a/src/main/java/com/gmail/goosius/siegewar/SiegeController.java +++ b/src/main/java/com/gmail/goosius/siegewar/SiegeController.java @@ -19,9 +19,6 @@ import com.gmail.goosius.siegewar.settings.Translation; import com.gmail.goosius.siegewar.utils.CosmeticUtil; import com.gmail.goosius.siegewar.utils.SiegeWarDistanceUtil; -import com.gmail.goosius.siegewar.utils.SiegeWarMoneyUtil; -import com.gmail.goosius.siegewar.utils.SiegeWarImmunityUtil; -import com.gmail.goosius.siegewar.utils.SiegeWarTownUtil; import com.palmergames.bukkit.towny.TownyEconomyHandler; import com.palmergames.bukkit.towny.TownyMessaging; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; @@ -37,6 +34,9 @@ import com.gmail.goosius.siegewar.enums.SiegeSide; import com.gmail.goosius.siegewar.metadata.SiegeMetaDataController; import com.gmail.goosius.siegewar.objects.Siege; +import com.gmail.goosius.siegewar.utils.SiegeWarMoneyUtil; +import com.gmail.goosius.siegewar.utils.SiegeWarImmunityUtil; +import com.gmail.goosius.siegewar.utils.SiegeWarTownUtil; import com.palmergames.bukkit.towny.TownyAPI; import com.palmergames.bukkit.towny.TownyUniverse; import com.palmergames.bukkit.towny.object.Nation;