mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
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:
parent
b97afb85a1
commit
339a54b0ac
@ -35,6 +35,7 @@ Version 1.4.06-dev
|
||||
! Changed default value for recently-hurt cooldown between teleports, this is also fully configurable now
|
||||
! Changed the amount of info messages in the console when enabling/disabling, enable Verbose_Logging to enable them again
|
||||
! Items dropped by players are now being tracked and are not being shared with party members
|
||||
! Optimized tracking of tool & ability cooldowns.
|
||||
|
||||
Version 1.4.05
|
||||
+ Added option to allow refreshing of chunks after block-breaking abilities. (Disabled by default)
|
||||
|
@ -38,7 +38,6 @@ import com.gmail.nossr50.runnables.SaveTimerTask;
|
||||
import com.gmail.nossr50.runnables.database.UserPurgeTask;
|
||||
import com.gmail.nossr50.runnables.party.PartyAutoKickTask;
|
||||
import com.gmail.nossr50.runnables.skills.BleedTimerTask;
|
||||
import com.gmail.nossr50.runnables.skills.SkillMonitorTask;
|
||||
import com.gmail.nossr50.skills.child.ChildConfig;
|
||||
import com.gmail.nossr50.skills.repair.Repairable;
|
||||
import com.gmail.nossr50.skills.repair.RepairableManager;
|
||||
@ -386,9 +385,6 @@ public class mcMMO extends JavaPlugin {
|
||||
|
||||
new SaveTimerTask().runTaskTimer(this, saveIntervalTicks, saveIntervalTicks);
|
||||
|
||||
// Regen & Cooldown timer (Runs every second)
|
||||
new SkillMonitorTask().runTaskTimer(this, 20, 20);
|
||||
|
||||
// Bleed timer (Runs every two seconds)
|
||||
new BleedTimerTask().runTaskTimer(this, 40, 40);
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.skills.AbilityCooldownTask;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.skills.mining.BlastMining.Tier;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
@ -108,6 +109,7 @@ public class MiningManager extends SkillManager{
|
||||
|
||||
getProfile().setSkillDATS(AbilityType.BLAST_MINING, System.currentTimeMillis());
|
||||
mcMMOPlayer.setAbilityInformed(AbilityType.BLAST_MINING, false);
|
||||
new AbilityCooldownTask(mcMMOPlayer, AbilityType.BLAST_MINING).runTaskLaterAsynchronously(mcMMO.p, AbilityType.BLAST_MINING.getCooldown());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,6 +31,8 @@ import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.runnables.skills.AbilityDisableTask;
|
||||
import com.gmail.nossr50.runnables.skills.ToolLowerTask;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.ModUtils;
|
||||
@ -87,21 +89,6 @@ public class SkillUtils {
|
||||
return (int) (((deactivatedTimeStamp + (PerksUtils.handleCooldownPerks(player, cooldown) * Misc.TIME_CONVERSION_FACTOR)) - System.currentTimeMillis()) / Misc.TIME_CONVERSION_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to the player when the cooldown expires.
|
||||
*
|
||||
* @param mcMMOPlayer The player to send a message to
|
||||
* @param ability The ability to watch cooldowns for
|
||||
*/
|
||||
public static void watchCooldown(McMMOPlayer mcMMOPlayer, AbilityType ability) {
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (!mcMMOPlayer.getAbilityInformed(ability) && cooldownOver(mcMMOPlayer.getProfile().getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR, ability.getCooldown(), player)) {
|
||||
mcMMOPlayer.setAbilityInformed(ability, true);
|
||||
player.sendMessage(ability.getAbilityRefresh());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process activating abilities & readying the tool.
|
||||
*
|
||||
@ -152,53 +139,7 @@ public class SkillUtils {
|
||||
|
||||
mcMMOPlayer.setToolPreparationATS(tool, System.currentTimeMillis());
|
||||
mcMMOPlayer.setToolPreparationMode(tool, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors various things relating to skill abilities.
|
||||
*
|
||||
* @param mcMMOPlayer The player using the skill
|
||||
* @param profile The profile of the player
|
||||
* @param curTime The current system time
|
||||
* @param skill The skill being monitored
|
||||
*/
|
||||
public static void monitorSkill(McMMOPlayer mcMMOPlayer, long curTime, SkillType skill) {
|
||||
final int FOUR_SECONDS = 4000;
|
||||
ToolType tool = skill.getTool();
|
||||
|
||||
if (mcMMOPlayer.getToolPreparationMode(tool) && curTime - (mcMMOPlayer.getToolPreparationATS(tool) * Misc.TIME_CONVERSION_FACTOR) >= FOUR_SECONDS) {
|
||||
mcMMOPlayer.setToolPreparationMode(tool, false);
|
||||
|
||||
if (Config.getInstance().getAbilityMessagesEnabled()) {
|
||||
mcMMOPlayer.getPlayer().sendMessage(tool.getLowerTool());
|
||||
}
|
||||
}
|
||||
|
||||
AbilityType ability = skill.getAbility();
|
||||
Player player = mcMMOPlayer.getPlayer();
|
||||
|
||||
if (ability.getPermissions(player)) {
|
||||
if (mcMMOPlayer.getAbilityMode(ability) && (mcMMOPlayer.getProfile().getSkillDATS(ability) * Misc.TIME_CONVERSION_FACTOR) <= curTime) {
|
||||
if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
|
||||
handleAbilitySpeedDecrease(player);
|
||||
}
|
||||
|
||||
if (HiddenConfig.getInstance().resendChunksAfterBlockAbility() && (ability == AbilityType.BERSERK || ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER)) {
|
||||
Misc.resendChunkRadiusAt(player, 1);
|
||||
}
|
||||
|
||||
mcMMOPlayer.setAbilityMode(ability, false);
|
||||
mcMMOPlayer.setAbilityInformed(ability, false);
|
||||
|
||||
ParticleEffectUtils.playAbilityDisabledEffect(player);
|
||||
|
||||
if (mcMMOPlayer.useChatNotifications()) {
|
||||
player.sendMessage(ability.getAbilityOff());
|
||||
}
|
||||
|
||||
sendSkillMessage(player, ability.getAbilityPlayerOff(player));
|
||||
}
|
||||
new ToolLowerTask(mcMMOPlayer, tool).runTaskLaterAsynchronously(mcMMO.p, 4 * 20);
|
||||
}
|
||||
}
|
||||
|
||||
@ -404,6 +345,8 @@ public class SkillUtils {
|
||||
if (ability == AbilityType.SUPER_BREAKER || ability == AbilityType.GIGA_DRILL_BREAKER) {
|
||||
handleAbilitySpeedIncrease(player);
|
||||
}
|
||||
|
||||
new AbilityDisableTask(mcMMOPlayer, ability).runTaskLater(mcMMO.p, ticks * 20);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user