Cleanup tasks
This commit is contained in:
parent
b13c77b6c5
commit
b020375e1e
@ -9,28 +9,30 @@ import com.massivecraft.massivecore.util.TimeUnit;
|
||||
public class TaskEconLandReward extends ModuloRepeatTask
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// INSTANCE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TaskEconLandReward i = new TaskEconLandReward();
|
||||
public static TaskEconLandReward get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public long getDelayMillis()
|
||||
{
|
||||
// The interval is determined by the MConf rather than being set with setDelayMillis.
|
||||
return (long) (MConf.get().taskEconLandRewardMinutes * TimeUnit.MILLIS_PER_MINUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDelayMillis(long delayMillis)
|
||||
{
|
||||
MConf.get().taskEconLandRewardMinutes = delayMillis / (double) TimeUnit.MILLIS_PER_MINUTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(long now)
|
||||
{
|
||||
if ( ! MassiveCore.isTaskServer()) return;
|
||||
// If this is the task server ...
|
||||
if (!MassiveCore.isTaskServer()) return;
|
||||
|
||||
// ... process the econ land rewards.
|
||||
FactionColl.get().econLandRewardRoutine();
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,12 @@ import com.massivecraft.massivecore.util.TimeUnit;
|
||||
|
||||
public class TaskFlagPermCreate extends ModuloRepeatTask
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final long MILLIS_INTERVAL = TimeUnit.MILLIS_PER_SECOND * 3;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
@ -14,20 +20,19 @@ public class TaskFlagPermCreate extends ModuloRepeatTask
|
||||
private static TaskFlagPermCreate i = new TaskFlagPermCreate();
|
||||
public static TaskFlagPermCreate get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: MODULO REPEAT TASK
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public long getDelayMillis()
|
||||
public TaskFlagPermCreate()
|
||||
{
|
||||
return TimeUnit.MILLIS_PER_SECOND * 3;
|
||||
super(MILLIS_INTERVAL);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public void setDelayMillis(long delayMillis)
|
||||
{
|
||||
|
||||
// No operation
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,32 +9,30 @@ import com.massivecraft.massivecore.util.TimeUnit;
|
||||
public class TaskPlayerDataRemove extends ModuloRepeatTask
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// INSTANCE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TaskPlayerDataRemove i = new TaskPlayerDataRemove();
|
||||
public static TaskPlayerDataRemove get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: MODULO REPEAT TASK
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public long getDelayMillis()
|
||||
{
|
||||
// The interval is determined by the MConf rather than being set with setDelayMillis.
|
||||
return (long) (MConf.get().taskPlayerDataRemoveMinutes * TimeUnit.MILLIS_PER_MINUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDelayMillis(long delayMillis)
|
||||
{
|
||||
MConf.get().taskPlayerDataRemoveMinutes = delayMillis / (double) TimeUnit.MILLIS_PER_MINUTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(long now)
|
||||
{
|
||||
if ( ! MassiveCore.isTaskServer()) return;
|
||||
// If this is the task server ...
|
||||
if (!MassiveCore.isTaskServer()) return;
|
||||
|
||||
// ... check players for expiration.
|
||||
MPlayerColl.get().considerRemovePlayerMillis();
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.massivecraft.factions.task;
|
||||
|
||||
import com.massivecraft.massivecore.util.PlayerUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
@ -14,60 +13,59 @@ import com.massivecraft.massivecore.ModuloRepeatTask;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.util.TimeUnit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
|
||||
public class TaskPlayerPowerUpdate extends ModuloRepeatTask
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// INSTANCE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static TaskPlayerPowerUpdate i = new TaskPlayerPowerUpdate();
|
||||
public static TaskPlayerPowerUpdate get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE: MODULO REPEAT TASK
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public long getDelayMillis()
|
||||
{
|
||||
// The interval is determined by the MConf rather than being set with setDelayMillis.
|
||||
return (long) (MConf.get().taskPlayerPowerUpdateMinutes * TimeUnit.MILLIS_PER_MINUTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDelayMillis(long delayMillis)
|
||||
{
|
||||
MConf.get().taskPlayerPowerUpdateMinutes = delayMillis / (double) TimeUnit.MILLIS_PER_MINUTE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(long now)
|
||||
{
|
||||
long millis = this.getDelayMillis();
|
||||
MFlag flagPowerGain = MFlag.getFlagPowergain();
|
||||
|
||||
// For each player ...
|
||||
for (Player player : MUtil.getOnlinePlayers())
|
||||
{
|
||||
// ... that is a living player ...
|
||||
if (MUtil.isntPlayer(player)) continue;
|
||||
if (player.isDead()) continue;
|
||||
|
||||
// Check the powergain flag is not disabled
|
||||
// ... in a faction territory that permits power gain ...
|
||||
Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player));
|
||||
if ( ! faction.getFlag(MFlag.getFlagPowergain())) return;
|
||||
if (!faction.getFlag(flagPowerGain)) return;
|
||||
|
||||
// Check power gain has not been disabled in this world
|
||||
if ( ! MConf.get().worldsPowerGainEnabled.contains(player)) return;
|
||||
// ... in a world that permits power gain ...
|
||||
if (!MConf.get().worldsPowerGainEnabled.contains(player)) return;
|
||||
|
||||
MPlayer mplayer = MPlayer.get(player);
|
||||
|
||||
// ... calculate new power ...
|
||||
double newPower = mplayer.getPower() + mplayer.getPowerPerHour() * millis / TimeUnit.MILLIS_PER_HOUR;
|
||||
|
||||
// ... and if other plugins don't object ...
|
||||
EventFactionsPowerChange event = new EventFactionsPowerChange(null, mplayer, PowerChangeReason.TIME, newPower);
|
||||
event.run();
|
||||
if (event.isCancelled()) continue;
|
||||
newPower = event.getNewPower();
|
||||
|
||||
// ... set the new power for the player.
|
||||
newPower = event.getNewPower();
|
||||
mplayer.setPower(newPower);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user