Skip to content

Commit

Permalink
Adds TownyTownUpkeep Event
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Ski committed Jun 12, 2013
1 parent 3f3d892 commit 21a3942
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/com/palmergames/bukkit/towny/TownyFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static List<String> getStatus(Nation nation) {
if (TownyEconomyHandler.isActive()) {
line = Colors.Green + "Bank: " + Colors.LightGreen + nation.getHoldingFormattedBalance();

if (TownySettings.getNationUpkeepCost(nation) > 0)
if (nation.getCapital().hasUpkeep())
line += (Colors.Gray + " | " + Colors.Green + "Daily upkeep: " + Colors.Red + TownySettings.getNationUpkeepCost(nation));

}
Expand Down
14 changes: 10 additions & 4 deletions src/com/palmergames/bukkit/towny/TownySettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import com.palmergames.bukkit.config.CommentedConfiguration;
import com.palmergames.bukkit.config.ConfigNodes;
import com.palmergames.bukkit.towny.event.TownyNationUpkeepEvent;
import com.palmergames.bukkit.towny.event.TownyTownUpkeepEvent;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident;
Expand All @@ -27,10 +29,10 @@
import com.palmergames.bukkit.towny.object.TownyPermission.ActionType;
import com.palmergames.bukkit.towny.object.TownyPermission.PermLevel;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.palmergames.bukkit.towny.object.TownyUpkeepModifier;
import com.palmergames.bukkit.towny.object.WorldCoord;
import com.palmergames.bukkit.towny.permissions.PermissionNodes;
import com.palmergames.bukkit.towny.war.flagwar.TownyWarConfig;
import com.palmergames.bukkit.util.BukkitTools;
import com.palmergames.bukkit.util.NameValidation;
import com.palmergames.util.FileMgmt;
import com.palmergames.util.TimeTools;
Expand Down Expand Up @@ -1345,8 +1347,10 @@ public static double getTownUpkeepCost(Town town) {
}
} else
multiplier = 1.0;

return (getTownUpkeep() * multiplier)+TownyUpkeepModifier.getTownUpkeepModifier(town);

TownyTownUpkeepEvent townUpkeepEvent = new TownyTownUpkeepEvent(town,getTownUpkeep()*multiplier);
BukkitTools.getPluginManager().callEvent(townUpkeepEvent);
return townUpkeepEvent.getUpkeep();
}

public static double getTownUpkeep() {
Expand Down Expand Up @@ -1378,7 +1382,9 @@ public static double getNationUpkeepCost(Nation nation) {
else
multiplier = 1.0;

return (getNationUpkeep() * multiplier) + TownyUpkeepModifier.getNationUpkeepModifier(nation);
TownyNationUpkeepEvent nationUpkeepEvent = new TownyNationUpkeepEvent(nation,getNationUpkeep()*multiplier);
BukkitTools.getPluginManager().callEvent(nationUpkeepEvent);
return nationUpkeepEvent.getUpkeep();
}

public static String getFlatFileBackupType() {
Expand Down
39 changes: 39 additions & 0 deletions src/com/palmergames/bukkit/towny/event/TownyNationUpkeepEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.palmergames.bukkit.towny.event;

import org.bukkit.event.HandlerList;

import com.palmergames.bukkit.towny.object.Nation;


public class TownyNationUpkeepEvent extends TownyUpkeepEvent {

private static final HandlerList handlers = new HandlerList();

private Nation nation;

@Override
public HandlerList getHandlers() {

return handlers;
}

public static HandlerList getHandlerList() {

return handlers;
}

public TownyNationUpkeepEvent(Nation nation, Double upkeep) {
super(upkeep);
this.nation = nation;
}


/**
*
* @return the nation
*/
public Nation getNation() {
return this.nation;
}

}
38 changes: 38 additions & 0 deletions src/com/palmergames/bukkit/towny/event/TownyTownUpkeepEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.palmergames.bukkit.towny.event;

import org.bukkit.event.HandlerList;

import com.palmergames.bukkit.towny.object.Town;


public class TownyTownUpkeepEvent extends TownyUpkeepEvent {

private static final HandlerList handlers = new HandlerList();

private Town town;

@Override
public HandlerList getHandlers() {

return handlers;
}

public static HandlerList getHandlerList() {

return handlers;
}

public TownyTownUpkeepEvent(Town town,Double upkeep) {
super(upkeep);
this.town = town;
}

/**
*
* @return the town
*/
public Town getTown() {
return this.town;
}

}
40 changes: 40 additions & 0 deletions src/com/palmergames/bukkit/towny/event/TownyUpkeepEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.palmergames.bukkit.towny.event;

import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;


public class TownyUpkeepEvent extends Event {

private static final HandlerList handlers = new HandlerList();

private double upkeep;

public TownyUpkeepEvent(Double upkeep) {
this.upkeep = upkeep;
}

@Override
public HandlerList getHandlers() {

return handlers;
}

public static HandlerList getHandlerList() {

return handlers;
}

public void setUpkeep(Double cost) {
this.upkeep = cost;
}

/**
*
* @return the upkeep
*/
public double getUpkeep() {
return upkeep;
}

}
45 changes: 0 additions & 45 deletions src/com/palmergames/bukkit/towny/object/TownyUpkeepModifier.java

This file was deleted.

0 comments on commit 21a3942

Please sign in to comment.