Added janky way to cancel spells

This commit is contained in:
Auxilor 2021-03-10 21:23:12 +00:00
parent 4b107da65b
commit d970ce08f9
2 changed files with 15 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchants;
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
import com.willfp.ecoenchants.enchantments.util.SpellActivateEvent;
import com.willfp.ecoenchants.enchantments.util.SpellCancellationInterrupt;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -146,7 +147,11 @@ public abstract class Spell extends EcoEnchant {
player.sendMessage(message);
player.playSound(player.getLocation(), this.getActivationSound(), SoundCategory.PLAYERS, 1, 1);
onUse(player, level, event);
try {
onUse(player, level, event);
} catch (SpellCancellationInterrupt ignored) {
// Do nothing
}
}
}
}
@ -169,7 +174,7 @@ public abstract class Spell extends EcoEnchant {
*/
public abstract void onUse(@NotNull Player player,
int level,
@NotNull PlayerInteractEvent event);
@NotNull PlayerInteractEvent event) throws SpellCancellationInterrupt;
/**
* Utility method to get a player's cooldown time of a specific spell.

View File

@ -0,0 +1,8 @@
package com.willfp.ecoenchants.enchantments.util;
/**
* Exception to cancel spells (janky).
*/
public class SpellCancellationInterrupt extends Exception {
}