Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nation Bonus Event #3873

Merged
merged 2 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/com/palmergames/bukkit/towny/TownySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}