Make the recurring tasks non-tps-dependent.

This commit is contained in:
Olof Larsson
2013-04-18 13:36:52 +02:00
parent 1c5c5557b0
commit af094b6647
5 changed files with 78 additions and 105 deletions

View File

@@ -2,24 +2,38 @@ package com.massivecraft.factions.task;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Factions;
import com.massivecraft.mcore.ModuloRepeatTask;
import com.massivecraft.mcore.util.TimeUnit;
public class AutoLeaveTask implements Runnable
public class AutoLeaveTask extends ModuloRepeatTask
{
double rate;
public AutoLeaveTask()
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static AutoLeaveTask i = new AutoLeaveTask();
public static AutoLeaveTask get() { return i; }
// -------------------------------------------- //
// OVERRIDE: MODULO REPEAT TASK
// -------------------------------------------- //
@Override
public long getDelayMillis()
{
this.rate = ConfServer.autoLeaveRoutineRunsEveryXMinutes;
return (long) (ConfServer.autoLeaveRoutineRunsEveryXMinutes * TimeUnit.MILLIS_PER_MINUTE);
}
public void run()
@Override
public void setDelayMillis(long delayMillis)
{
throw new RuntimeException("operation not supported");
}
@Override
public void invoke()
{
FPlayerColl.get().autoLeaveOnInactivityRoutine();
// TODO: Make it a polling and non-tps-dependent system instead.
// maybe setting has been changed? if so, restart task at new rate
if (this.rate != ConfServer.autoLeaveRoutineRunsEveryXMinutes)
Factions.get().startAutoLeaveTask(true);
}
}

View File

@@ -2,30 +2,38 @@ package com.massivecraft.factions.task;
import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FactionColl;
import com.massivecraft.factions.Factions;
import com.massivecraft.mcore.ModuloRepeatTask;
import com.massivecraft.mcore.util.TimeUnit;
public class EconLandRewardTask implements Runnable
public class EconLandRewardTask extends ModuloRepeatTask
{
double rate;
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static EconLandRewardTask i = new EconLandRewardTask();
public static EconLandRewardTask get() { return i; }
// -------------------------------------------- //
// OVERRIDE: MODULO REPEAT TASK
// -------------------------------------------- //
public EconLandRewardTask()
{
this.rate = ConfServer.econLandRewardTaskRunsEveryXMinutes;
}
@Override
public void run()
public long getDelayMillis()
{
return (long) (ConfServer.econLandRewardTaskRunsEveryXMinutes * TimeUnit.MILLIS_PER_MINUTE);
}
@Override
public void setDelayMillis(long delayMillis)
{
throw new RuntimeException("operation not supported");
}
@Override
public void invoke()
{
FactionColl.get().econLandRewardRoutine();
// TODO: This technique is TPS dependent and wrong.
// Instead of restarting a TPS dependent task the task should poll every once in a while for the system millis.
// With such a setup the need for restarts are gone.
// maybe setting has been changed? if so, restart task at new rate
if (this.rate != ConfServer.econLandRewardTaskRunsEveryXMinutes)
{
Factions.get().startEconLandRewardTask(true);
}
}
}