Skip to content

Commit

Permalink
Fix enchantments avoiding custom anvil rules when an ExcellentEnchant…
Browse files Browse the repository at this point in the history
…s enchantment is present. fix #36

Also version up
  • Loading branch information
alexcrea committed Oct 18, 2024
1 parent 1066508 commit c0af35f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
}

group = "xyz.alexcrea"
version = "1.6.5"
version = "1.6.6"

repositories {
// EcoEnchants
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/delilaheve/CustomAnvil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.util.logging.Level
/**
* Bukkit/Spigot/Paper plugin to alter anvil feature
*/
class CustomAnvil : JavaPlugin() {
open class CustomAnvil : JavaPlugin() {

companion object {
// bstats plugin id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.bukkit.Bukkit
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.PrepareAnvilEvent
import org.bukkit.inventory.AnvilInventory
import org.bukkit.inventory.ItemStack
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.dependency.gui.ExternGuiTester
import xyz.alexcrea.cuanvil.dependency.gui.GuiTesterSelector
Expand Down Expand Up @@ -105,6 +106,10 @@ object DependencyManager {
return bypass
}

fun treatAnvilResult(event: PrepareAnvilEvent, result: ItemStack) {
excellentEnchantsCompatibility?.treatAnvilResult(event, result)
}

fun tryClickAnvilResultBypass(event: InventoryClickEvent, inventory: AnvilInventory): Boolean {
var bypass = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,17 @@ class ExcellentEnchantsDependency {
if(event.result == null) return true
}

var first: ItemStack? = event.inventory.getItem(0)
var second: ItemStack? = event.inventory.getItem(1)
var result = event.result
val first: ItemStack = treatInput(event.inventory.getItem(0))
val second: ItemStack = treatInput(event.inventory.getItem(1))

if (first == null) first = ItemStack(Material.AIR)
if (second == null) second = ItemStack(Material.AIR)
if (result == null) result = ItemStack(Material.AIR)
return handleRechargeMethod.invoke(this.anvilListener, event, first, second) as Boolean
}

fun treatAnvilResult(event: PrepareAnvilEvent, result: ItemStack) {
val first: ItemStack = treatInput(event.inventory.getItem(0))
val second: ItemStack = treatInput(event.inventory.getItem(1))

if(handleRechargeMethod.invoke(this.anvilListener, event, first, second) as Boolean) return true
return handleCombineMethod.invoke(this.anvilListener, event, first, second, result) as Boolean
handleCombineMethod.invoke(this.anvilListener, event, first, second, result)
}

fun testAnvilResult(event: InventoryClickEvent): Any {
Expand All @@ -100,8 +101,12 @@ class ExcellentEnchantsDependency {
return event.inventory.getItem(2) == null
}


return false;
}

fun treatInput(item: ItemStack?): ItemStack {
if(item == null) return ItemStack(Material.AIR)
return item
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class PrepareAnvilListener : Listener {
resultItem.amount *= amount

event.result = resultItem
DependencyManager.treatAnvilResult(event, resultItem)
AnvilXpUtil.setAnvilInvXp(inventory, event.view, recipe.xpCostPerCraft * amount, true)

return true
Expand All @@ -104,6 +105,7 @@ class PrepareAnvilListener : Listener {
}

event.result = resultItem
DependencyManager.treatAnvilResult(event, resultItem)

anvilCost += AnvilXpUtil.calculatePenalty(first, null, resultItem)

Expand Down Expand Up @@ -173,6 +175,7 @@ class PrepareAnvilListener : Listener {

// Finally, we set result
event.result = resultItem
DependencyManager.treatAnvilResult(event, resultItem)

AnvilXpUtil.setAnvilInvXp(inventory, event.view, anvilCost)
}
Expand All @@ -198,6 +201,7 @@ class PrepareAnvilListener : Listener {
return true
}
event.result = resultItem
DependencyManager.treatAnvilResult(event, resultItem)

AnvilXpUtil.setAnvilInvXp(inventory, event.view, anvilCost)
return true
Expand Down

0 comments on commit c0af35f

Please sign in to comment.