diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index 802fa39c..b1c8e323 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -237,6 +237,9 @@ public class Conf public static double econCostTruce = 0.0; public static double econCostNeutral = 0.0; public static double econCostEnemy = 0.0; + + public static int econLandRewardTaskRunsEveryXMinutes = 20; + public static double econLandReward = 0.01; //Faction banks, to pay for land claiming and other costs instead of individuals paying for them public static boolean bankEnabled = true; diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 7599d23b..84284faa 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -10,6 +10,8 @@ import java.util.logging.Level; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken; + +import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Rel; @@ -259,4 +261,22 @@ public class Factions extends EntityCollection return this.getByTag(str) != null; } + public void econLandRewardRoutine() + { + for (Faction faction : this.get()) + { + int landCount = faction.getLandRounded(); + if (!faction.getFlag(FFlag.PEACEFUL) && landCount > 0) + { + Set players = faction.getFPlayers(); + int playerCount = players.size(); + double reward = Conf.econLandReward * landCount / playerCount; + for (FPlayer player : players) + { + Econ.modifyMoney(player, reward, "to own faction land plots", "for faction owning " + landCount + " plots divided among " + playerCount + " members"); + } + } + } + } + } diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index 17cd54d4..87ce2d97 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -38,6 +38,7 @@ import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.struct.TerritoryAccess; import com.massivecraft.factions.util.AutoLeaveTask; +import com.massivecraft.factions.util.EconLandRewardTask; import com.massivecraft.factions.util.LazyLocation; import com.massivecraft.factions.zcore.MPlugin; import com.massivecraft.factions.zcore.util.TextUtil; @@ -64,6 +65,7 @@ public class P extends MPlugin public boolean getLocked() {return this.locked;} public void setLocked(boolean val) {this.locked = val; this.setAutoSave(val);} private Integer AutoLeaveTask = null; + private Integer econLandRewardTaskID = null; // Commands public FCmdRoot cmdBase; @@ -189,6 +191,23 @@ public class P extends MPlugin } } + public void startEconLandRewardTask(boolean restartIfRunning) + { + if (econLandRewardTaskID != null) + { + if (!restartIfRunning) return; + this.getServer().getScheduler().cancelTask(econLandRewardTaskID); + } + + if (Conf.econEnabled && + Conf.econLandRewardTaskRunsEveryXMinutes > 0.0 && + Conf.econLandReward > 0.0) + { + long ticks = (long)(20 * 60 * Conf.econLandRewardTaskRunsEveryXMinutes); + econLandRewardTaskID = getServer().getScheduler().scheduleSyncRepeatingTask(this, new EconLandRewardTask(), ticks, ticks); + } + } + @Override public void postAutoSave() { diff --git a/src/com/massivecraft/factions/util/EconLandRewardTask.java b/src/com/massivecraft/factions/util/EconLandRewardTask.java new file mode 100644 index 00000000..1f8f449e --- /dev/null +++ b/src/com/massivecraft/factions/util/EconLandRewardTask.java @@ -0,0 +1,25 @@ +package com.massivecraft.factions.util; + +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.P; + +public class EconLandRewardTask implements Runnable { + + double rate; + + public EconLandRewardTask() + { + this.rate = Conf.autoLeaveRoutineRunsEveryXMinutes; + } + + @Override + public void run() + { + Factions.i.econLandRewardRoutine(); + // maybe setting has been changed? if so, restart task at new rate + if (this.rate != Conf.econLandRewardTaskRunsEveryXMinutes) + P.p.startEconLandRewardTask(true); + } + +}