Replace SkillMonitorTask with 3 unique timers instead. This should greatly

optimize our tool and ability cooldown tracking and hopefully reduce
server load.
This commit is contained in:
GJ
2013-04-29 14:19:41 -04:00
parent b97afb85a1
commit 339a54b0ac
8 changed files with 123 additions and 102 deletions

View File

@ -0,0 +1,26 @@
package com.gmail.nossr50.runnables.skills;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
public class AbilityCooldownTask extends BukkitRunnable {
private McMMOPlayer mcMMOPlayer;
private AbilityType ability;
public AbilityCooldownTask(McMMOPlayer mcMMOPlayer, AbilityType ability) {
this.mcMMOPlayer = mcMMOPlayer;
this.ability = ability;
}
@Override
public void run() {
if (mcMMOPlayer.getAbilityInformed(ability)) {
return;
}
mcMMOPlayer.setAbilityInformed(ability, true);
mcMMOPlayer.getPlayer().sendMessage(ability.getAbilityRefresh());
}
}

View File

@ -0,0 +1,59 @@
package com.gmail.nossr50.runnables.skills;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.HiddenConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
import com.gmail.nossr50.util.skills.SkillUtils;
public class AbilityDisableTask extends BukkitRunnable {
private McMMOPlayer mcMMOPlayer;
private AbilityType ability;
public AbilityDisableTask(McMMOPlayer mcMMOPlayer, AbilityType ability) {
this.mcMMOPlayer = mcMMOPlayer;
this.ability = ability;
}
@Override
public void run() {
if (!mcMMOPlayer.getAbilityMode(ability)) {
return;
}
Player player = mcMMOPlayer.getPlayer();
switch (ability) {
case SUPER_BREAKER:
case GIGA_DRILL_BREAKER:
SkillUtils.handleAbilitySpeedDecrease(player);
// Fallthrough
case BERSERK:
if (HiddenConfig.getInstance().resendChunksAfterBlockAbility()) {
Misc.resendChunkRadiusAt(player, 1);
}
// Fallthrough
default:
break;
}
mcMMOPlayer.setAbilityMode(ability, false);
mcMMOPlayer.setAbilityInformed(ability, false);
ParticleEffectUtils.playAbilityDisabledEffect(player);
if (mcMMOPlayer.useChatNotifications()) {
player.sendMessage(ability.getAbilityOff());
}
SkillUtils.sendSkillMessage(player, ability.getAbilityPlayerOff(player));
new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLaterAsynchronously(mcMMO.p, ability.getCooldown() * 20);
}
}

View File

@ -1,36 +0,0 @@
package com.gmail.nossr50.runnables.skills;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.AbilityType;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.SkillUtils;
public class SkillMonitorTask extends BukkitRunnable {
@Override
public void run() {
long curTime = System.currentTimeMillis();
for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers().values()) {
/*
* MONITOR SKILLS
*/
for (SkillType skill : SkillType.values()) {
if (skill.getTool() != null && skill.getAbility() != null) {
SkillUtils.monitorSkill(mcMMOPlayer, curTime, skill);
}
}
/*
* COOLDOWN MONITORING
*/
for (AbilityType ability : AbilityType.values()) {
if (ability.getCooldown() > 0) {
SkillUtils.watchCooldown(mcMMOPlayer, ability);
}
}
}
}
}

View File

@ -0,0 +1,30 @@
package com.gmail.nossr50.runnables.skills;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.ToolType;
public class ToolLowerTask extends BukkitRunnable {
private McMMOPlayer mcMMOPlayer;
private ToolType tool;
public ToolLowerTask(McMMOPlayer mcMMOPlayer, ToolType tool) {
this.mcMMOPlayer = mcMMOPlayer;
this.tool = tool;
}
@Override
public void run() {
if (!mcMMOPlayer.getToolPreparationMode(tool)) {
return;
}
mcMMOPlayer.setToolPreparationMode(tool, false);
if (Config.getInstance().getAbilityMessagesEnabled()) {
mcMMOPlayer.getPlayer().sendMessage(tool.getLowerTool());
}
}
}