Skip to content

Commit

Permalink
Fix BlockBreaker not calling BlockDamageEvent
Browse files Browse the repository at this point in the history
Fix #312, Fix #337
  • Loading branch information
NichtStudioCode committed Mar 29, 2024
1 parent 16e9140 commit a1d1302
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.bukkit.block.BlockFace
import org.bukkit.craftbukkit.v1_20_R3.event.CraftEventFactory
import org.bukkit.entity.Player
import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.block.BlockDamageEvent
import org.bukkit.event.block.BlockExpEvent
import org.bukkit.inventory.ItemStack
import org.bukkit.potion.PotionEffectType
Expand Down Expand Up @@ -146,14 +147,27 @@ internal sealed class BlockBreaker(val player: Player, val block: Block, val sta
if (isDone)
return

val damage = calculateDamage()
var damage = calculateDamage()
val clientsideDamage = calculateClientsideDamage()

if (clientsideDamage >= 1 && damage < 1) {
stop(false, startSequence)
return
}

val damageEvent = BlockDamageEvent(
player,
block,
BlockFaceUtils.determineBlockFaceLookingAt(player.eyeLocation) ?: BlockFace.NORTH,
tool ?: ItemStack(Material.AIR),
damage > 1
)
callEvent(damageEvent)
if (damageEvent.isCancelled)
return
if (damageEvent.instaBreak && damage < 1)
damage = 1.0

if (damage >= 1.0 || serverTick >= blockedUntil) {
progress += damage

Expand Down

0 comments on commit a1d1302

Please sign in to comment.