From b020375e1e27a4dbbf8443fea0a9aef12ecc6ede Mon Sep 17 00:00:00 2001 From: TheComputerGeek2 Date: Mon, 13 Mar 2017 21:07:14 -0700 Subject: [PATCH] Cleanup tasks --- .../factions/task/TaskEconLandReward.java | 18 ++++++----- .../factions/task/TaskFlagPermCreate.java | 21 +++++++----- .../factions/task/TaskPlayerDataRemove.java | 16 ++++------ .../factions/task/TaskPlayerPowerUpdate.java | 32 +++++++++---------- 4 files changed, 45 insertions(+), 42 deletions(-) diff --git a/src/com/massivecraft/factions/task/TaskEconLandReward.java b/src/com/massivecraft/factions/task/TaskEconLandReward.java index 4bf1e8a3..eafcca1f 100644 --- a/src/com/massivecraft/factions/task/TaskEconLandReward.java +++ b/src/com/massivecraft/factions/task/TaskEconLandReward.java @@ -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(); } diff --git a/src/com/massivecraft/factions/task/TaskFlagPermCreate.java b/src/com/massivecraft/factions/task/TaskFlagPermCreate.java index 3db342ba..3bc4486b 100644 --- a/src/com/massivecraft/factions/task/TaskFlagPermCreate.java +++ b/src/com/massivecraft/factions/task/TaskFlagPermCreate.java @@ -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 diff --git a/src/com/massivecraft/factions/task/TaskPlayerDataRemove.java b/src/com/massivecraft/factions/task/TaskPlayerDataRemove.java index 499c3685..fb290b5d 100644 --- a/src/com/massivecraft/factions/task/TaskPlayerDataRemove.java +++ b/src/com/massivecraft/factions/task/TaskPlayerDataRemove.java @@ -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(); } diff --git a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java index f676fc17..bb5647cc 100644 --- a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java +++ b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java @@ -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); } }