mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-11-27 12:46:09 +01:00
commit
204c78886f
@ -236,6 +236,10 @@ 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.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;
|
||||
|
@ -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,23 @@ public class Factions extends EntityCollection<Faction>
|
||||
return this.getByTag(str) != null;
|
||||
}
|
||||
|
||||
public void econLandRewardRoutine()
|
||||
{
|
||||
P.p.log("Running 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", "for faction owning " + landCount + " land divided among " + playerCount + " member(s)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,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;
|
||||
|
||||
@ -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;
|
||||
@ -124,6 +126,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);
|
||||
@ -184,6 +189,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()
|
||||
{
|
||||
|
25
src/com/massivecraft/factions/util/EconLandRewardTask.java
Normal file
25
src/com/massivecraft/factions/util/EconLandRewardTask.java
Normal 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.econLandRewardTaskRunsEveryXMinutes;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user