Reward faction members with money every day for every plot they control divided among all the players in the faction

This commit is contained in:
ÆtherSurfer 2012-11-28 00:51:37 -05:00
parent 9c7ed3bf38
commit ca219a1fb2
4 changed files with 67 additions and 0 deletions

View File

@ -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;

View File

@ -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<Faction>
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<FPlayer> 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");
}
}
}
}
}

View File

@ -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()
{

View File

@ -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);
}
}