mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 16:35:57 +02:00
Compare commits
No commits in common. "d469171e4d8cb1ef6faf79ca0519a8ccd071ee1b" and "16e4f0a9239585d23e21479513c57d62495c8e32" have entirely different histories.
d469171e4d
...
16e4f0a923
6 changed files with 14 additions and 60 deletions
|
|
@ -40,8 +40,6 @@ Custom Items support is considered unstable. If you find issue please report it
|
||||||
- [Disenchantment](https://www.spigotmc.org/resources/disenchantment-1-21-1-1-20-6-new-book-splitting-mechanics.110741/) by H7KZ
|
- [Disenchantment](https://www.spigotmc.org/resources/disenchantment-1-21-1-1-20-6-new-book-splitting-mechanics.110741/) by H7KZ
|
||||||
Partially use Custom Anvil maximum XP settings (>= 6.1.5)
|
Partially use Custom Anvil maximum XP settings (>= 6.1.5)
|
||||||
|
|
||||||
- [EnchantedBook](https://modrinth.com/plugin/enchantedbook) by Minacle
|
|
||||||
|
|
||||||
- [HavenBags](https://www.spigotmc.org/resources/havenbags-shulker-like-player-bound-bags-1-17-1-21-4.110420/) by hyperdefined
|
- [HavenBags](https://www.spigotmc.org/resources/havenbags-shulker-like-player-bound-bags-1-17-1-21-4.110420/) by hyperdefined
|
||||||
For bag upgrade and skin via anvil. (version >= 1.31.0)
|
For bag upgrade and skin via anvil. (version >= 1.31.0)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,9 +130,9 @@ class DiagnosticExecutor: CASubCommand() {
|
||||||
message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString())
|
message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString())
|
||||||
message.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("§7Click to copy"))
|
message.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("§7Click to copy"))
|
||||||
|
|
||||||
sender.spigot().sendMessage(message)
|
sender.spigot().sendMessage(message);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(stb.toString())
|
sender.sendMessage(stb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
@ -267,8 +267,8 @@ class DiagnosticExecutor: CASubCommand() {
|
||||||
try {
|
try {
|
||||||
val fakeInv = Bukkit.createInventory(player, InventoryType.ANVIL)
|
val fakeInv = Bukkit.createInventory(player, InventoryType.ANVIL)
|
||||||
invView = player.openInventory(fakeInv)!!
|
invView = player.openInventory(fakeInv)!!
|
||||||
event = DependencyManager.createFakeEvent(invView, result)
|
event = PrepareAnvilEvent(invView, result)
|
||||||
} catch (_: Throwable) {
|
} catch (e: Throwable) {
|
||||||
// Help
|
// Help
|
||||||
val menuTypeClazz = Class.forName("org.bukkit.inventory.MenuType")
|
val menuTypeClazz = Class.forName("org.bukkit.inventory.MenuType")
|
||||||
val anvilTypeField = menuTypeClazz.getField("ANVIL")
|
val anvilTypeField = menuTypeClazz.getField("ANVIL")
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
||||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.componentLore
|
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.componentLore
|
||||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError
|
import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError
|
||||||
import java.lang.reflect.Constructor
|
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
||||||
object DependencyManager {
|
object DependencyManager {
|
||||||
|
|
@ -123,10 +122,6 @@ object DependencyManager {
|
||||||
genericDependencies.add(compatibility)
|
genericDependencies.add(compatibility)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pluginManager.isPluginEnabled("EnchantedBook")) {
|
|
||||||
genericDependencies.add(EnchantedBookDependency(pluginManager.getPlugin("EnchantedBook")!!))
|
|
||||||
}
|
|
||||||
|
|
||||||
for (dependency in genericDependencies)
|
for (dependency in genericDependencies)
|
||||||
dependency.redirectListeners()
|
dependency.redirectListeners()
|
||||||
|
|
||||||
|
|
@ -333,12 +328,4 @@ object DependencyManager {
|
||||||
enchantmentSquaredCompatibility?.updateLore(item)
|
enchantmentSquaredCompatibility?.updateLore(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private val prepareAnvilConstructor =
|
|
||||||
PrepareAnvilEvent::class.java.constructors.first() as Constructor<PrepareAnvilEvent>
|
|
||||||
|
|
||||||
fun createFakeEvent(view: InventoryView, result: ItemStack?): PrepareAnvilEvent {
|
|
||||||
return prepareAnvilConstructor.newInstance(view, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
package xyz.alexcrea.cuanvil.dependency.plugins
|
|
||||||
|
|
||||||
import org.bukkit.event.Event
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent
|
|
||||||
import org.bukkit.plugin.Plugin
|
|
||||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
|
||||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_INPUT_LEFT
|
|
||||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
|
|
||||||
|
|
||||||
class EnchantedBookDependency(plugin: Plugin) : GenericPluginDependency(plugin) {
|
|
||||||
|
|
||||||
override fun testAnvilResult(event: InventoryClickEvent): Boolean {
|
|
||||||
val view = event.view
|
|
||||||
val inv = event.inventory
|
|
||||||
|
|
||||||
//TODO use view here (v2)
|
|
||||||
val current = inv.getItem(ANVIL_OUTPUT_SLOT)
|
|
||||||
inv.setItem(ANVIL_OUTPUT_SLOT, null)
|
|
||||||
val fakeEvent = DependencyManager.createFakeEvent(view, null)
|
|
||||||
|
|
||||||
if (testPrepareAnvil(fakeEvent)) {
|
|
||||||
event.result = Event.Result.DEFAULT
|
|
||||||
|
|
||||||
inv.setItem(ANVIL_INPUT_LEFT, fakeEvent.result)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
inv.setItem(ANVIL_INPUT_LEFT, current)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -9,11 +9,11 @@ import org.bukkit.inventory.ItemStack
|
||||||
import org.bukkit.plugin.RegisteredListener
|
import org.bukkit.plugin.RegisteredListener
|
||||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||||
import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResult2Event
|
import xyz.alexcrea.cuanvil.api.event.listener.CATreatAnvilResult2Event
|
||||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEPreV5Enchantment
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEPreV5Enchantment
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5Enchantment
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5Enchantment
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5_4Enchantment
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5_4Enchantment
|
||||||
import xyz.alexcrea.cuanvil.enchant.wrapped.CALegacyEEEnchantment
|
import xyz.alexcrea.cuanvil.enchant.wrapped.CALegacyEEEnchantment
|
||||||
|
import java.lang.reflect.Constructor
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import su.nightexpress.excellentenchants.api.EnchantRegistry as V5EnchantRegistry
|
import su.nightexpress.excellentenchants.api.EnchantRegistry as V5EnchantRegistry
|
||||||
import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant as LegacyCurseOfFragilityEnchant
|
import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant as LegacyCurseOfFragilityEnchant
|
||||||
|
|
@ -47,7 +47,7 @@ class ExcellentEnchantsDependency {
|
||||||
|
|
||||||
listenerVersion = value
|
listenerVersion = value
|
||||||
break
|
break
|
||||||
} catch (_: ClassNotFoundException) {
|
} catch (ignored: ClassNotFoundException) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,7 +60,7 @@ class ExcellentEnchantsDependency {
|
||||||
var isModernCurseOfFragility = true
|
var isModernCurseOfFragility = true
|
||||||
try {
|
try {
|
||||||
Class.forName("su.nightexpress.excellentenchants.enchantment.universal.CurseOfFragilityEnchant")
|
Class.forName("su.nightexpress.excellentenchants.enchantment.universal.CurseOfFragilityEnchant")
|
||||||
} catch (_: ClassNotFoundException) {
|
} catch (ignored: ClassNotFoundException) {
|
||||||
isModernCurseOfFragility = false
|
isModernCurseOfFragility = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,6 +118,8 @@ class ExcellentEnchantsDependency {
|
||||||
private lateinit var handleRechargeMethod: Method
|
private lateinit var handleRechargeMethod: Method
|
||||||
private lateinit var handleCombineMethod: Method
|
private lateinit var handleCombineMethod: Method
|
||||||
|
|
||||||
|
private val prepareAnvilConstructor = PrepareAnvilEvent::class.java.constructors.first() as Constructor<PrepareAnvilEvent>
|
||||||
|
|
||||||
fun redirectListeners() {
|
fun redirectListeners() {
|
||||||
val toUnregister = ArrayList<RegisteredListener>()
|
val toUnregister = ArrayList<RegisteredListener>()
|
||||||
// get required PrepareAnvilEvent listener
|
// get required PrepareAnvilEvent listener
|
||||||
|
|
@ -224,7 +226,7 @@ class ExcellentEnchantsDependency {
|
||||||
|
|
||||||
val first: ItemStack = treatInput(event.leftItem)
|
val first: ItemStack = treatInput(event.leftItem)
|
||||||
val second: ItemStack = treatInput(event.rightItem)
|
val second: ItemStack = treatInput(event.rightItem)
|
||||||
val fakeEvent = DependencyManager.createFakeEvent(event.view, result)
|
val fakeEvent = prepareAnvilConstructor.newInstance(event.view, result)
|
||||||
|
|
||||||
handleCombineMethod.invoke(this.usedAnvilListener, fakeEvent, first, second, result)
|
handleCombineMethod.invoke(this.usedAnvilListener, fakeEvent, first, second, result)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,4 +84,3 @@ softdepend:
|
||||||
- ExcellentEnchants
|
- ExcellentEnchants
|
||||||
- HavenBags
|
- HavenBags
|
||||||
- SuperEnchants
|
- SuperEnchants
|
||||||
- EnchantedBook
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue