2013-04-29 20:19:41 +02:00
|
|
|
package com.gmail.nossr50.runnables.skills;
|
|
|
|
|
2019-01-11 16:11:17 +01:00
|
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
2019-01-13 04:56:54 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
|
|
|
import com.gmail.nossr50.util.player.NotificationManager;
|
2014-01-03 17:07:13 +01:00
|
|
|
import org.bukkit.Chunk;
|
|
|
|
import org.bukkit.World;
|
2013-04-29 20:19:41 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
2014-08-18 04:21:23 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-04-29 20:19:41 +02:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.util.EventUtils;
|
2013-04-29 20:19:41 +02:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
2013-05-21 00:15:17 +02:00
|
|
|
import com.gmail.nossr50.util.skills.PerksUtils;
|
2013-04-29 20:19:41 +02:00
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
|
|
|
|
|
|
public class AbilityDisableTask extends BukkitRunnable {
|
|
|
|
private McMMOPlayer mcMMOPlayer;
|
2019-01-13 04:56:54 +01:00
|
|
|
private SuperAbilityType ability;
|
2013-04-29 20:19:41 +02:00
|
|
|
|
2019-01-13 04:56:54 +01:00
|
|
|
public AbilityDisableTask(McMMOPlayer mcMMOPlayer, SuperAbilityType ability) {
|
2013-04-29 20:19:41 +02:00
|
|
|
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:
|
2014-08-18 04:21:23 +02:00
|
|
|
if (Config.getInstance().getRefreshChunksEnabled()) {
|
2014-01-03 17:07:13 +01:00
|
|
|
resendChunkRadiusAt(player, 1);
|
2013-04-29 20:19:41 +02:00
|
|
|
}
|
|
|
|
// Fallthrough
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-18 14:31:00 +02:00
|
|
|
EventUtils.callAbilityDeactivateEvent(player, ability);
|
2013-05-14 18:18:52 +02:00
|
|
|
|
2013-04-29 20:19:41 +02:00
|
|
|
mcMMOPlayer.setAbilityMode(ability, false);
|
|
|
|
mcMMOPlayer.setAbilityInformed(ability, false);
|
|
|
|
|
|
|
|
ParticleEffectUtils.playAbilityDisabledEffect(player);
|
|
|
|
|
|
|
|
if (mcMMOPlayer.useChatNotifications()) {
|
2019-01-11 16:11:17 +01:00
|
|
|
//player.sendMessage(ability.getAbilityOff());
|
2019-01-13 04:56:54 +01:00
|
|
|
NotificationManager.sendPlayerInformation(player, NotificationType.ABILITY_OFF, ability.getAbilityOff());
|
2013-04-29 20:19:41 +02:00
|
|
|
}
|
|
|
|
|
2019-01-11 16:11:17 +01:00
|
|
|
|
|
|
|
SkillUtils.sendSkillMessage(player, NotificationType.SUPER_ABILITY_ALERT_OTHERS, ability.getAbilityPlayerOff());
|
2013-06-13 01:26:09 +02:00
|
|
|
new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLaterAsynchronously(mcMMO.p, PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TICK_CONVERSION_FACTOR);
|
2013-04-29 20:19:41 +02:00
|
|
|
}
|
2014-01-03 17:07:13 +01:00
|
|
|
|
|
|
|
private void resendChunkRadiusAt(Player player, int radius) {
|
|
|
|
Chunk chunk = player.getLocation().getChunk();
|
|
|
|
World world = player.getWorld();
|
|
|
|
|
|
|
|
int chunkX = chunk.getX();
|
|
|
|
int chunkZ = chunk.getZ();
|
|
|
|
|
2016-08-08 00:32:34 +02:00
|
|
|
for (int x = chunkX - radius; x <= chunkX + radius; x++) {
|
|
|
|
for (int z = chunkZ - radius; z <= chunkZ + radius; z++) {
|
2014-01-03 17:07:13 +01:00
|
|
|
world.refreshChunk(x, z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-29 20:19:41 +02:00
|
|
|
}
|