Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adds TownyUpkeepEvent #96

Open
wants to merge 2 commits into from

3 participants

Tomski Kris Chris Holland
Tomski

Also adds TownyTownUpkeepEvent and TownyNationUpkeepEvent

Minor changes to TownyFomatter to prevent the nation event firing double

Chris Holland Zren commented on the diff
src/com/palmergames/bukkit/towny/TownyFormatter.java
@@ -287,7 +287,7 @@ public static String getTime() {
if (TownyEconomyHandler.isActive()) {
line = Colors.Green + "Bank: " + Colors.LightGreen + nation.getHoldingFormattedBalance();
- if (TownySettings.getNationUpkeepCost(nation) > 0)
+ if (nation.getCapital().hasUpkeep())
Chris Holland
Zren added a note

Is this the same thing? Isn't there a nation.hasUpkeep()?

Tomski
Tom-Ski added a note

Not that I could see, I had to change it as getNationUpkeepCost would cause the event to fire twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Kris

Other than formatting issues, looks good :+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 11, 2013
  1. Add api for town and nation upkeep

    TomSki authored
Commits on Jun 12, 2013
  1. Tomski

    Adds TownyTownUpkeep Event

    Tom-Ski authored
This page is out of date. Refresh to see the latest.
2  src/com/palmergames/bukkit/towny/TownyFormatter.java
View
@@ -287,7 +287,7 @@ public static String getTime() {
if (TownyEconomyHandler.isActive()) {
line = Colors.Green + "Bank: " + Colors.LightGreen + nation.getHoldingFormattedBalance();
- if (TownySettings.getNationUpkeepCost(nation) > 0)
+ if (nation.getCapital().hasUpkeep())
Chris Holland
Zren added a note

Is this the same thing? Isn't there a nation.hasUpkeep()?

Tomski
Tom-Ski added a note

Not that I could see, I had to change it as getNationUpkeepCost would cause the event to fire twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
line += (Colors.Gray + " | " + Colors.Green + "Daily upkeep: " + Colors.Red + TownySettings.getNationUpkeepCost(nation));
}
13 src/com/palmergames/bukkit/towny/TownySettings.java
View
@@ -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;
@@ -30,6 +32,7 @@
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;
@@ -1344,8 +1347,10 @@ public static double getTownUpkeepCost(Town town) {
}
} else
multiplier = 1.0;
-
- return getTownUpkeep() * multiplier;
+
+ TownyTownUpkeepEvent townUpkeepEvent = new TownyTownUpkeepEvent(town,getTownUpkeep()*multiplier);
+ BukkitTools.getPluginManager().callEvent(townUpkeepEvent);
+ return townUpkeepEvent.getUpkeep();
}
public static double getTownUpkeep() {
@@ -1377,7 +1382,9 @@ public static double getNationUpkeepCost(Nation nation) {
else
multiplier = 1.0;
- return getNationUpkeep() * multiplier;
+ TownyNationUpkeepEvent nationUpkeepEvent = new TownyNationUpkeepEvent(nation,getNationUpkeep()*multiplier);
+ BukkitTools.getPluginManager().callEvent(nationUpkeepEvent);
+ return nationUpkeepEvent.getUpkeep();
}
public static String getFlatFileBackupType() {
39 src/com/palmergames/bukkit/towny/event/TownyNationUpkeepEvent.java
View
@@ -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 src/com/palmergames/bukkit/towny/event/TownyTownUpkeepEvent.java
View
@@ -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 src/com/palmergames/bukkit/towny/event/TownyUpkeepEvent.java
View
@@ -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;
+ }
+
+}
Something went wrong with that request. Please try again.