From ca219a1fb2f0f4a0305aa866cd33c7fe018cbeb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86therSurfer?= Date: Wed, 28 Nov 2012 00:51:37 -0500 Subject: [PATCH 1/2] Reward faction members with money every day for every plot they control divided among all the players in the faction --- src/com/massivecraft/factions/Conf.java | 3 +++ src/com/massivecraft/factions/Factions.java | 20 +++++++++++++++ src/com/massivecraft/factions/P.java | 19 ++++++++++++++ .../factions/util/EconLandRewardTask.java | 25 +++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 src/com/massivecraft/factions/util/EconLandRewardTask.java 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); + } + +} From 2f883455ee02a24b4c516f62f5b391f97b5f770d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86therSurfer?= Date: Fri, 30 Nov 2012 15:02:43 -0500 Subject: [PATCH 2/2] Land Reward Task up and running. Conflicts: src/com/massivecraft/factions/Conf.java src/com/massivecraft/factions/listeners/FactionsPlayerListener.java --- src/com/massivecraft/factions/Conf.java | 3 ++- src/com/massivecraft/factions/Factions.java | 3 ++- src/com/massivecraft/factions/P.java | 3 +++ src/com/massivecraft/factions/util/EconLandRewardTask.java | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/com/massivecraft/factions/Conf.java b/src/com/massivecraft/factions/Conf.java index b1c8e323..e0f2b25e 100644 --- a/src/com/massivecraft/factions/Conf.java +++ b/src/com/massivecraft/factions/Conf.java @@ -239,7 +239,8 @@ public class Conf public static double econCostEnemy = 0.0; public static int econLandRewardTaskRunsEveryXMinutes = 20; - public static double econLandReward = 0.01; + public static double econLandReward = 0.03; + public static double econLandRevertEnemyReward = 25.0; //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 84284faa..736ed66c 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -263,6 +263,7 @@ public class Factions extends EntityCollection public void econLandRewardRoutine() { + P.p.log("Running econLandRewardRoutine..."); for (Faction faction : this.get()) { int landCount = faction.getLandRounded(); @@ -273,7 +274,7 @@ public class Factions extends EntityCollection 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"); + Econ.modifyMoney(player, reward, "to own faction land", "for faction owning " + landCount + " land divided among " + playerCount + " member(s)"); } } } diff --git a/src/com/massivecraft/factions/P.java b/src/com/massivecraft/factions/P.java index 87ce2d97..29539959 100644 --- a/src/com/massivecraft/factions/P.java +++ b/src/com/massivecraft/factions/P.java @@ -128,6 +128,9 @@ public class P extends MPlugin // start up task which runs the autoLeaveAfterDaysOfInactivity routine startAutoLeaveTask(false); + // start up task which runs the econLandRewardRoutine + startEconLandRewardTask(false); + // Register Event Handlers getServer().getPluginManager().registerEvents(this.playerListener, this); getServer().getPluginManager().registerEvents(this.chatListener, this); diff --git a/src/com/massivecraft/factions/util/EconLandRewardTask.java b/src/com/massivecraft/factions/util/EconLandRewardTask.java index 1f8f449e..98f150b7 100644 --- a/src/com/massivecraft/factions/util/EconLandRewardTask.java +++ b/src/com/massivecraft/factions/util/EconLandRewardTask.java @@ -10,7 +10,7 @@ public class EconLandRewardTask implements Runnable { public EconLandRewardTask() { - this.rate = Conf.autoLeaveRoutineRunsEveryXMinutes; + this.rate = Conf.econLandRewardTaskRunsEveryXMinutes; } @Override