diff --git a/src/main/java/net/Indyuce/mmoitems/api/event/BouncingCrackBlockBreakEvent.java b/src/main/java/net/Indyuce/mmoitems/api/event/BouncingCrackBlockBreakEvent.java new file mode 100644 index 00000000..c93d8b55 --- /dev/null +++ b/src/main/java/net/Indyuce/mmoitems/api/event/BouncingCrackBlockBreakEvent.java @@ -0,0 +1,12 @@ +package net.Indyuce.mmoitems.api.event; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.block.BlockBreakEvent; +import org.jetbrains.annotations.NotNull; + +public class BouncingCrackBlockBreakEvent extends BlockBreakEvent { + public BouncingCrackBlockBreakEvent(@NotNull Block theBlock, @NotNull Player player) { + super(theBlock, player); + } +} diff --git a/src/main/java/net/Indyuce/mmoitems/api/interaction/Tool.java b/src/main/java/net/Indyuce/mmoitems/api/interaction/Tool.java index 479fa8fd..0a33f627 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/interaction/Tool.java +++ b/src/main/java/net/Indyuce/mmoitems/api/interaction/Tool.java @@ -5,6 +5,8 @@ import io.lumine.mythic.lib.UtilityMethods; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.comp.flags.CustomFlag; import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.event.BouncingCrackBlockBreakEvent; +import net.Indyuce.mmoitems.api.player.PlayerData; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -43,7 +45,8 @@ public class Tool extends UseItem { } } - if (getNBTItem().getBoolean("MMOITEMS_BOUNCING_CRACK")) + if (getNBTItem().getBoolean("MMOITEMS_BOUNCING_CRACK") && !getPlayerData().isOnCooldown(PlayerData.CooldownType.BOUNCING_CRACK)) { + getPlayerData().applyCooldown(PlayerData.CooldownType.BOUNCING_CRACK, 1); new BukkitRunnable() { final Vector v = player.getEyeLocation().getDirection().multiply(.5); final Location loc = block.getLocation().clone().add(.5, .5, .5); @@ -58,7 +61,7 @@ public class Tool extends UseItem { if (block.getType() == Material.AIR || MMOItems.plugin.getLanguage().isBlacklisted(block.getType())) return; - BlockBreakEvent breakEvent = new BlockBreakEvent(block, player); + BlockBreakEvent breakEvent = new BouncingCrackBlockBreakEvent(block, player); Bukkit.getPluginManager().callEvent(breakEvent); if (breakEvent.isCancelled()) { cancel(); @@ -69,6 +72,7 @@ public class Tool extends UseItem { loc.getWorld().playSound(loc, Sound.BLOCK_GRAVEL_BREAK, 1, 1); } }.runTaskTimer(MMOItems.plugin, 0, 1); + } /*if (getNBTItem().hasTag("MMOITEMS_BREAK_SIZE")) { int breakSize = getNBTItem().getInteger("MMOITEMS_BREAK_SIZE"); diff --git a/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java b/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java index 88b524b7..91014f79 100644 --- a/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java +++ b/src/main/java/net/Indyuce/mmoitems/api/player/PlayerData.java @@ -17,6 +17,7 @@ import net.Indyuce.mmoitems.api.ItemSet.SetBonuses; import net.Indyuce.mmoitems.api.Type; import net.Indyuce.mmoitems.api.crafting.CraftingStatus; import net.Indyuce.mmoitems.api.event.RefreshInventoryEvent; +import net.Indyuce.mmoitems.api.interaction.Tool; import net.Indyuce.mmoitems.api.item.ItemReference; import net.Indyuce.mmoitems.api.item.mmoitem.VolatileMMOItem; import net.Indyuce.mmoitems.api.player.inventory.EquippedItem; @@ -28,6 +29,7 @@ import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; +import org.bukkit.block.Block; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -471,6 +473,16 @@ public class PlayerData { */ SPECIAL_ATTACK, + /** + * Bouncing Crack calls block breaking events which can + * trigger Bouncing Crack again and crash the game. A + * cooldown is therefore required. Bouncing Crack max + * duration is 10 ticks so a 1s cooldown is perfect + * + * @see {@link Tool#miningEffects(Block)} + */ + BOUNCING_CRACK, + /** * Special item set attack effects including slashing, piercing and * blunt attack effects