diff --git a/src/com/palmergames/bukkit/towny/TownySettings.java b/src/com/palmergames/bukkit/towny/TownySettings.java index 5453690272..afe8fc98a7 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,10 @@ 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); + Bukkit.getPluginManager().callEvent(calculationEvent); + 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; + } +}