Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ object Rebar : JavaPlugin(), RebarAddon {
RebarFlowerPot.register(this, pm)
RebarVanillaContainerBlock.register(this, pm)
RebarHopper.register(this, pm)
RebarFire.register(this, pm)
RebarCargoBlock.register(this, pm)
RebarCopperBlock.register(this, pm)
RebarEntityChangedBlock.register(this, pm)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.github.pylonmc.rebar.block.base

import io.github.pylonmc.rebar.Rebar
import io.github.pylonmc.rebar.block.BlockListener
import io.github.pylonmc.rebar.block.BlockListener.logEventHandleErr
import io.github.pylonmc.rebar.block.BlockStorage
import io.github.pylonmc.rebar.block.context.BlockCreateContext
import io.github.pylonmc.rebar.event.api.MultiListener
import io.github.pylonmc.rebar.event.api.annotation.MultiHandlers
import io.github.pylonmc.rebar.event.api.annotation.UniversalHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.block.BlockSpreadEvent
import org.bukkit.event.entity.EntityDamageEvent
import org.jetbrains.annotations.ApiStatus

@Suppress("unused")
interface RebarFire {
Comment thread
balugaq marked this conversation as resolved.
fun onDamageEntity(event: EntityDamageEvent, priority: EventPriority) {}
fun onFireSpread(event: BlockSpreadEvent, priority: EventPriority) {}

@ApiStatus.Internal
companion object : MultiListener {
@UniversalHandler
private fun onDamageEntity(event: EntityDamageEvent, priority: EventPriority) {
if (event.cause != EntityDamageEvent.DamageCause.FIRE) return

val rebarBlock = BlockStorage.get(event.entity.location)
if (rebarBlock !is RebarFire) {
return
}

try {
MultiHandlers.handleEvent(rebarBlock, "onDamageEntity", event, priority)
} catch (e: Exception) {
BlockListener.logEventHandleErr(event, e, rebarBlock)
}
}

@UniversalHandler
private fun onFireSpread(event: BlockSpreadEvent, priority: EventPriority) {
val rebarBlock = BlockStorage.get(event.source)
if (rebarBlock !is RebarFire) return

try {
MultiHandlers.handleEvent(rebarBlock, "onFireSpread", event, priority)

if (!event.isCancelled) {
// place new fire
BlockStorage.placeBlock(
event.block,
rebarBlock.key,
BlockCreateContext.PluginGenerate(Rebar.javaPlugin, block = event.block)
)
}
} catch (e: Exception) {
BlockListener.logEventHandleErr(event, e, rebarBlock)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ interface BlockCreateContext {
* ex:
* - Growing of Rebar Trees
* - Evolution of Rebar Sponges
* - Spread of Rebar Fire
*/
@JvmRecord
data class PluginGenerate(
val plugin: Plugin,
override val facing: BlockFace = BlockFace.NORTH,
override val facingVertical: BlockFace = BlockFace.NORTH,
override val block: Block,
override val item: ItemStack,
override val item: ItemStack? = null,
) : BlockCreateContext

/**
Expand Down
Loading