From 71f09721f0384d4127d6b8c3404f626282dcc678 Mon Sep 17 00:00:00 2001 From: Silverwolfg11 Date: Sat, 4 Apr 2020 00:33:14 -0700 Subject: [PATCH 1/2] Nation Bonus Event --- .../bukkit/towny/TownySettings.java | 12 +++--- .../event/NationBonusCalculationEvent.java | 41 +++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 src/com/palmergames/bukkit/towny/event/NationBonusCalculationEvent.java diff --git a/src/com/palmergames/bukkit/towny/TownySettings.java b/src/com/palmergames/bukkit/towny/TownySettings.java index 5453690272..0219c8c477 100644 --- a/src/com/palmergames/bukkit/towny/TownySettings.java +++ b/src/com/palmergames/bukkit/towny/TownySettings.java @@ -2,6 +2,7 @@ import com.palmergames.bukkit.config.CommentedConfiguration; import com.palmergames.bukkit.config.ConfigNodes; +import com.palmergames.bukkit.towny.event.NationBonusCalculationEvent; import com.palmergames.bukkit.towny.event.NationUpkeepCalculationEvent; import com.palmergames.bukkit.towny.event.TownUpkeepCalculationEvent; import com.palmergames.bukkit.towny.event.TownUpkeepPenalityCalculationEvent; @@ -1114,11 +1115,7 @@ public static int getMaxTownBlocks(Town town) { } else n += town.getNumResidents() * ratio; - if (town.hasNation()) - try { - n += (Integer) getNationLevel(town.getNation()).get(TownySettings.NationLevel.TOWN_BLOCK_LIMIT_BONUS); - } catch (NotRegisteredException e) { - } + n += getNationBonusBlocks(town); return n; } @@ -1142,8 +1139,9 @@ public static int getMaxBonusBlocks(Town town) { } public static int getNationBonusBlocks(Nation nation) { - - return (Integer) getNationLevel(nation).get(TownySettings.NationLevel.TOWN_BLOCK_LIMIT_BONUS); + int bonusBlocks = (Integer) getNationLevel(nation).get(TownySettings.NationLevel.TOWN_BLOCK_LIMIT_BONUS); + NationBonusCalculationEvent calculationEvent = new NationBonusCalculationEvent(nation, bonusBlocks); + return calculationEvent.getBonusBlocks(); } public static int getNationBonusBlocks(Town town) { diff --git a/src/com/palmergames/bukkit/towny/event/NationBonusCalculationEvent.java b/src/com/palmergames/bukkit/towny/event/NationBonusCalculationEvent.java new file mode 100644 index 0000000000..26e0288a39 --- /dev/null +++ b/src/com/palmergames/bukkit/towny/event/NationBonusCalculationEvent.java @@ -0,0 +1,41 @@ +package com.palmergames.bukkit.towny.event; + +import com.palmergames.bukkit.towny.object.Nation; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Event called whenever nation bonus blocks are being fetched. + */ +public class NationBonusCalculationEvent extends Event { + private static HandlerList handlers = new HandlerList(); + + private Nation nation; + private int bonusBlocks; + + public NationBonusCalculationEvent(Nation nation, int bonusBlocks) { + this.nation = nation; + this.bonusBlocks = bonusBlocks; + } + + public Nation getNation() { + return nation; + } + + public int getBonusBlocks() { + return bonusBlocks; + } + + public void setBonusBlocks(int bonusBlocks) { + this.bonusBlocks = bonusBlocks; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} From 1266771ab735c7fa51b28cdf0a8b748d9d30a058 Mon Sep 17 00:00:00 2001 From: silverwolfg11 Date: Sat, 4 Apr 2020 00:37:52 -0700 Subject: [PATCH 2/2] Actually call the event --- src/com/palmergames/bukkit/towny/TownySettings.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/palmergames/bukkit/towny/TownySettings.java b/src/com/palmergames/bukkit/towny/TownySettings.java index 0219c8c477..afe8fc98a7 100644 --- a/src/com/palmergames/bukkit/towny/TownySettings.java +++ b/src/com/palmergames/bukkit/towny/TownySettings.java @@ -1141,6 +1141,7 @@ public static int getMaxBonusBlocks(Town town) { public static int getNationBonusBlocks(Nation nation) { int bonusBlocks = (Integer) getNationLevel(nation).get(TownySettings.NationLevel.TOWN_BLOCK_LIMIT_BONUS); NationBonusCalculationEvent calculationEvent = new NationBonusCalculationEvent(nation, bonusBlocks); + Bukkit.getPluginManager().callEvent(calculationEvent); return calculationEvent.getBonusBlocks(); }