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
2 changes: 2 additions & 0 deletions rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import io.github.pylonmc.rebar.recipe.RecipeType
import io.github.pylonmc.rebar.registry.RebarRegistry
import io.github.pylonmc.rebar.resourcepack.armor.ArmorTextureEngine
import io.github.pylonmc.rebar.culling.BlockCullingEngine
import io.github.pylonmc.rebar.item.base.VanillaAnvilItem
import io.github.pylonmc.rebar.util.mergeGlobalConfig
import io.github.pylonmc.rebar.waila.Waila
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder
Expand Down Expand Up @@ -239,6 +240,7 @@ object Rebar : JavaPlugin(), RebarAddon {
RebarSplashPotion.register(this, pm)
RebarTool.register(this, pm)
RebarWeapon.register(this, pm)
VanillaAnvilItem.register(this, pm)
VanillaCookingFuel.register(this, pm)

// Rebar Entities
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.github.pylonmc.rebar.item.base

import io.github.pylonmc.rebar.event.api.MultiListener
import io.github.pylonmc.rebar.event.api.annotation.MultiHandler
import io.github.pylonmc.rebar.event.api.annotation.UniversalHandler
import io.github.pylonmc.rebar.item.RebarItem
import io.github.pylonmc.rebar.item.RebarItemListener
import org.bukkit.event.EventPriority
import org.bukkit.event.inventory.PrepareAnvilEvent

interface VanillaAnvilItem {
fun onPrepareAnvilCraft(event: PrepareAnvilEvent)

companion object : MultiListener {
@UniversalHandler
private fun onPrepareAnvil(event: PrepareAnvilEvent, priority: EventPriority) {
val rebarItem1 = RebarItem.fromStack(event.inventory.firstItem)
val rebarItem2 = RebarItem.fromStack(event.inventory.secondItem)
if (rebarItem1 is VanillaAnvilItem) {
try {
MultiHandler.handleEvent(rebarItem1, "onPrepareAnvilCraft", event, priority)
} catch (e: Exception) {
RebarItemListener.logEventHandleErr(event, e, rebarItem1)
}
}
if (rebarItem2 is VanillaAnvilItem) {
try {
MultiHandler.handleEvent(rebarItem2, "onPrepareAnvil", event, priority)
Comment thread
JustAHuman-xD marked this conversation as resolved.
Outdated
} catch (e: Exception) {
RebarItemListener.logEventHandleErr(event, e, rebarItem2)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.ShapedRecipe
import org.bukkit.inventory.ShapelessRecipe
import org.bukkit.inventory.StonecutterInventory
import org.bukkit.inventory.meta.Damageable

internal object RebarRecipeListener : Listener {

Expand Down Expand Up @@ -231,14 +232,15 @@ internal object RebarRecipeListener : Listener {
val inventory = e.inventory
val firstItem = inventory.firstItem
val secondItem = inventory.secondItem
val firstRebarItem = RebarItem.fromStack(firstItem)
val secondRebarItem = RebarItem.fromStack(secondItem)

// Disallow using Rebar items but allow renaming them
// Have tried to support this. It's really hard because you end up effectively
// having to do the repair manually for items that can't usually be repaired.
// Gave up after 2 hours or so
if ((firstRebarItem != null && (secondItem != null && !secondItem.isEmpty)) || secondRebarItem != null) {
// Check if the result is a repaired item and if so, cancel it.
if(firstItem != null && e.result != null
&& firstItem.itemMeta is Damageable && e.result!!.itemMeta is Damageable
&& (firstItem.itemMeta as Damageable).damage < (e.result!!.itemMeta as Damageable).damage){
e.result = null
return
}
// Check if either input is a rebar item without VanillaAnvilItem and if the output is vanilla, cancel it
if((firstItem.isRebarAndIsNot<VanillaAnvilItem>() || secondItem.isRebarAndIsNot<VanillaAnvilItem>()) && RebarItem.fromStack(e.result) == null) {
Comment thread
JustAHuman-xD marked this conversation as resolved.
Outdated
e.result = null
return
}
Expand Down