Cleanup tasks

This commit is contained in:
TheComputerGeek2 2017-03-13 21:07:14 -07:00 committed by ulumulu1510
parent b13c77b6c5
commit b020375e1e
4 changed files with 45 additions and 42 deletions

View File

@ -9,28 +9,30 @@ import com.massivecraft.massivecore.util.TimeUnit;
public class TaskEconLandReward extends ModuloRepeatTask public class TaskEconLandReward extends ModuloRepeatTask
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE
// -------------------------------------------- // // -------------------------------------------- //
private static TaskEconLandReward i = new TaskEconLandReward(); private static TaskEconLandReward i = new TaskEconLandReward();
public static TaskEconLandReward get() { return i; } public static TaskEconLandReward get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override @Override
public long getDelayMillis() 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); 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 @Override
public void invoke(long now) public void invoke(long now)
{ {
// If this is the task server ...
if (!MassiveCore.isTaskServer()) return; if (!MassiveCore.isTaskServer()) return;
// ... process the econ land rewards.
FactionColl.get().econLandRewardRoutine(); FactionColl.get().econLandRewardRoutine();
} }

View File

@ -7,6 +7,12 @@ import com.massivecraft.massivecore.util.TimeUnit;
public class TaskFlagPermCreate extends ModuloRepeatTask public class TaskFlagPermCreate extends ModuloRepeatTask
{ {
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
private static final long MILLIS_INTERVAL = TimeUnit.MILLIS_PER_SECOND * 3;
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
@ -14,20 +20,19 @@ public class TaskFlagPermCreate extends ModuloRepeatTask
private static TaskFlagPermCreate i = new TaskFlagPermCreate(); private static TaskFlagPermCreate i = new TaskFlagPermCreate();
public static TaskFlagPermCreate get() { return i; } public static TaskFlagPermCreate get() { return i; }
// -------------------------------------------- // public TaskFlagPermCreate()
// OVERRIDE: MODULO REPEAT TASK
// -------------------------------------------- //
@Override
public long getDelayMillis()
{ {
return TimeUnit.MILLIS_PER_SECOND * 3; super(MILLIS_INTERVAL);
} }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override @Override
public void setDelayMillis(long delayMillis) public void setDelayMillis(long delayMillis)
{ {
// No operation
} }
@Override @Override

View File

@ -9,32 +9,30 @@ import com.massivecraft.massivecore.util.TimeUnit;
public class TaskPlayerDataRemove extends ModuloRepeatTask public class TaskPlayerDataRemove extends ModuloRepeatTask
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE
// -------------------------------------------- // // -------------------------------------------- //
private static TaskPlayerDataRemove i = new TaskPlayerDataRemove(); private static TaskPlayerDataRemove i = new TaskPlayerDataRemove();
public static TaskPlayerDataRemove get() { return i; } public static TaskPlayerDataRemove get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: MODULO REPEAT TASK // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public long getDelayMillis() 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); 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 @Override
public void invoke(long now) public void invoke(long now)
{ {
// If this is the task server ...
if (!MassiveCore.isTaskServer()) return; if (!MassiveCore.isTaskServer()) return;
// ... check players for expiration.
MPlayerColl.get().considerRemovePlayerMillis(); MPlayerColl.get().considerRemovePlayerMillis();
} }

View File

@ -1,6 +1,5 @@
package com.massivecraft.factions.task; package com.massivecraft.factions.task;
import com.massivecraft.massivecore.util.PlayerUtil;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.massivecraft.factions.entity.BoardColl; 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.ps.PS;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.TimeUnit; 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 public class TaskPlayerPowerUpdate extends ModuloRepeatTask
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE
// -------------------------------------------- // // -------------------------------------------- //
private static TaskPlayerPowerUpdate i = new TaskPlayerPowerUpdate(); private static TaskPlayerPowerUpdate i = new TaskPlayerPowerUpdate();
public static TaskPlayerPowerUpdate get() { return i; } public static TaskPlayerPowerUpdate get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: MODULO REPEAT TASK // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public long getDelayMillis() 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); 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 @Override
public void invoke(long now) public void invoke(long now)
{ {
long millis = this.getDelayMillis(); long millis = this.getDelayMillis();
MFlag flagPowerGain = MFlag.getFlagPowergain();
// For each player ...
for (Player player : MUtil.getOnlinePlayers()) for (Player player : MUtil.getOnlinePlayers())
{ {
// ... that is a living player ...
if (MUtil.isntPlayer(player)) continue; if (MUtil.isntPlayer(player)) continue;
if (player.isDead()) 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)); 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 // ... in a world that permits power gain ...
if (!MConf.get().worldsPowerGainEnabled.contains(player)) return; if (!MConf.get().worldsPowerGainEnabled.contains(player)) return;
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
// ... calculate new power ...
double newPower = mplayer.getPower() + mplayer.getPowerPerHour() * millis / TimeUnit.MILLIS_PER_HOUR; 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); EventFactionsPowerChange event = new EventFactionsPowerChange(null, mplayer, PowerChangeReason.TIME, newPower);
event.run(); event.run();
if (event.isCancelled()) continue; if (event.isCancelled()) continue;
newPower = event.getNewPower();
// ... set the new power for the player.
newPower = event.getNewPower();
mplayer.setPower(newPower); mplayer.setPower(newPower);
} }
} }