AbilityDisableTask.java 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package com.gmail.nossr50.runnables.skills;
  2. import com.gmail.nossr50.config.MainConfig;
  3. import com.gmail.nossr50.datatypes.interactions.NotificationType;
  4. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  5. import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
  6. import com.gmail.nossr50.mcMMO;
  7. import com.gmail.nossr50.util.EventUtils;
  8. import com.gmail.nossr50.util.Misc;
  9. import com.gmail.nossr50.util.skills.ParticleEffectUtils;
  10. import com.gmail.nossr50.util.skills.PerksUtils;
  11. import com.gmail.nossr50.util.skills.SkillUtils;
  12. import org.bukkit.Chunk;
  13. import org.bukkit.World;
  14. import org.bukkit.entity.Player;
  15. import org.bukkit.scheduler.BukkitRunnable;
  16. public class AbilityDisableTask extends BukkitRunnable {
  17. private McMMOPlayer mcMMOPlayer;
  18. private SuperAbilityType ability;
  19. public AbilityDisableTask(McMMOPlayer mcMMOPlayer, SuperAbilityType ability) {
  20. this.mcMMOPlayer = mcMMOPlayer;
  21. this.ability = ability;
  22. }
  23. @Override
  24. public void run() {
  25. if (!mcMMOPlayer.getAbilityMode(ability)) {
  26. return;
  27. }
  28. Player player = mcMMOPlayer.getPlayer();
  29. switch (ability) {
  30. case SUPER_BREAKER:
  31. case GIGA_DRILL_BREAKER:
  32. SkillUtils.handleAbilitySpeedDecrease(player);
  33. // Fallthrough
  34. case BERSERK:
  35. resendChunkRadiusAt(player);
  36. // Fallthrough
  37. default:
  38. break;
  39. }
  40. EventUtils.callAbilityDeactivateEvent(player, ability);
  41. mcMMOPlayer.setAbilityMode(ability, false);
  42. mcMMOPlayer.setAbilityInformed(ability, false);
  43. if (mcMMOPlayer.useChatNotifications()) {
  44. //player.sendMessage(ability.getAbilityOff());
  45. mcMMO.getNotificationManager().sendPlayerInformation(player, NotificationType.ABILITY_OFF, ability.getAbilityOff());
  46. }
  47. SkillUtils.sendSkillMessage(player, NotificationType.SUPER_ABILITY_ALERT_OTHERS, ability.getAbilityPlayerOff());
  48. new AbilityCooldownTask(mcMMOPlayer, ability).runTaskLater(mcMMO.p, PerksUtils.handleCooldownPerks(player, ability.getCooldown()) * Misc.TICK_CONVERSION_FACTOR);
  49. }
  50. private void resendChunkRadiusAt(Player player) {
  51. Chunk chunk = player.getLocation().getChunk();
  52. World world = player.getWorld();
  53. int chunkX = chunk.getX();
  54. int chunkZ = chunk.getZ();
  55. for (int x = chunkX - 1; x <= chunkX + 1; x++) {
  56. for (int z = chunkZ - 1; z <= chunkZ + 1; z++) {
  57. world.refreshChunk(x, z);
  58. }
  59. }
  60. }
  61. }