-
Notifications
You must be signed in to change notification settings - Fork 0
Implement dynamic remapping for InventoryView methods #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,104 @@ | ||||||||||||||||||||||||
| package dev.slne.surf.surfapi.bukkit.server.inventory.framework | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import net.bytebuddy.ByteBuddy | ||||||||||||||||||||||||
| import net.bytebuddy.asm.AsmVisitorWrapper | ||||||||||||||||||||||||
| import net.bytebuddy.description.field.FieldDescription | ||||||||||||||||||||||||
| import net.bytebuddy.description.field.FieldList | ||||||||||||||||||||||||
| import net.bytebuddy.description.method.MethodList | ||||||||||||||||||||||||
| import net.bytebuddy.description.type.TypeDescription | ||||||||||||||||||||||||
| import net.bytebuddy.dynamic.ClassFileLocator | ||||||||||||||||||||||||
| import net.bytebuddy.dynamic.loading.ClassLoadingStrategy | ||||||||||||||||||||||||
| import net.bytebuddy.implementation.Implementation | ||||||||||||||||||||||||
| import net.bytebuddy.jar.asm.ClassVisitor | ||||||||||||||||||||||||
| import net.bytebuddy.jar.asm.MethodVisitor | ||||||||||||||||||||||||
| import net.bytebuddy.jar.asm.Opcodes | ||||||||||||||||||||||||
| import net.bytebuddy.pool.TypePool | ||||||||||||||||||||||||
| import net.bytebuddy.utility.OpenedClassReader | ||||||||||||||||||||||||
| import org.bukkit.inventory.InventoryView | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| object InventoryViewRemapper { | ||||||||||||||||||||||||
| private const val INVENTORY_VIEW_INTERNAL = "org/bukkit/inventory/InventoryView" | ||||||||||||||||||||||||
| private const val INVENTORY_UPDATE_INTERNAL = | ||||||||||||||||||||||||
| "dev/slne/surf/surfapi/libs/devnatan/inventoryframework/runtime/thirdparty/InventoryUpdate" | ||||||||||||||||||||||||
|
Comment on lines
+18
to
+22
|
||||||||||||||||||||||||
| object InventoryViewRemapper { | |
| private const val INVENTORY_VIEW_INTERNAL = "org/bukkit/inventory/InventoryView" | |
| private const val INVENTORY_UPDATE_INTERNAL = | |
| "dev/slne/surf/surfapi/libs/devnatan/inventoryframework/runtime/thirdparty/InventoryUpdate" | |
| import dev.slne.surf.surfapi.libs.devnatan.inventoryframework.runtime.thirdparty.InventoryUpdate | |
| object InventoryViewRemapper { | |
| private val INVENTORY_VIEW_INTERNAL: String = InventoryView::class.java.name.replace('.', '/') | |
| private val INVENTORY_UPDATE_INTERNAL: String = | |
| InventoryUpdate::class.java.name.replace('.', '/') |
Copilot
AI
Mar 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remap() can throw (e.g., TypePool#resolve() if the class name changes / isn't present, or load(...) if injection fails). Because this runs during plugin startup, any uncaught exception here will fail inventory framework initialization (or even plugin load). Consider wrapping the resolve/redefine/load sequence in a try/catch and logging a warning/severe message so the plugin can continue (ideally with a clear indication that InventoryView compatibility patching failed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
InventoryViewRemapper.remap()in the object initializer means any exception during remapping will preventInventoryLoaderfrom initializing (and then breakInventoryLoader.load()/enable()calls). Even ifremap()is made more defensive, it’s safer to ensure failures here are contained (e.g., handle/log exceptions insideremap()or around this call) so inventory framework startup doesn’t hard-fail.