Automatic API Remapping via ASM Bytecode Transformation on Plugin Load
メンテナーはふだん 1 日以内に返信
@twisti-dev がすでに取り組んでいます。
2025年4月2日 から。
評価
この issue はまだ評価されていません。
説明
Is your feature request related to a problem?
This plugin serves both as a runtime API and as an API provider. When internal changes occur—like method renames or class relocations—it breaks compatibility for dependent plugins. Developers currently have to manually update and recompile their plugins against the new API, which is cumbersome and error-prone.
Describe the solution you'd like.
Implement a runtime API remapping mechanism using ASM-based bytecode transformation.
The system would:
- Hook into Paper’s
ClassloaderBytecodeModifierinterface - Inject a custom modifier that applies both the default Paper transformations and custom API remapping logic
- Use ASM to rewrite class/method/field references in plugin bytecode at load time
- Maintain a mapping file (like Mojang/Paper mappings) to guide the remapper
This ensures that plugins using the API remain compatible without requiring updates or recompilation.
Describe alternatives you've considered.
- Requiring all plugin developers to recompile against each API version – time-consuming and not scalable.
- Providing adapter shims – limited in scope and still require frequent maintenance.
- Avoiding breaking changes altogether – restricts development flexibility and long-term maintainability.
Other
1. Custom Modifier Implementation
public class MyCustomBytecodeModifier implements ClassloaderBytecodeModifier {
private final ClassloaderBytecodeModifier paperModifier = new PaperClassloaderBytecodeModifier();
@Override
public byte[] modify(PluginMeta config, byte[] bytecode) {
// First, apply Paper's internal transformation
byte[] processed = paperModifier.modify(config, bytecode);
// Then apply custom API remapping
return applyMyApiRemapping(config, processed);
}
private byte[] applyMyApiRemapping(PluginMeta config, byte[] bytecode) {
ClassReader reader = new ClassReader(bytecode);
ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_MAXS);
ClassVisitor visitor = new MyRemappingVisitor(writer); // contains mapping logic
reader.accept(visitor, 0);
return writer.toByteArray();
}
}
2. Overriding the Singleton Using Unsafe (Java 21 Compatible)
import sun.misc.Unsafe;
import java.lang.reflect.Field;
public static void injectCustomModifier() {
try {
Class<?> providerClass = Class.forName("io.papermc.paper.plugin.entrypoint.classloader.ClassloaderBytecodeModifier$Provider");
Field instanceField = providerClass.getDeclaredField("INSTANCE");
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Unsafe unsafe = (Unsafe) unsafeField.get(null);
Object base = unsafe.staticFieldBase(instanceField);
long offset = unsafe.staticFieldOffset(instanceField);
unsafe.putObject(base, offset, new MyCustomBytecodeModifier());
Bukkit.getLogger().info("Successfully injected custom bytecode modifier.");
} catch (Throwable t) {
Bukkit.getLogger().severe("Failed to inject custom bytecode modifier.");
t.printStackTrace();
}
}
- 主要言語
- Kotlin
- スター
- 5
- フォーク
- 0
- 平均マージ
- 15時間 26分
- マージ済み PR(30日)
- 8
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
SLNE-Development/surf-api のほかの issue
-
status: needs triage
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
SLNE-Development/surf-api#158 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
SLNE-Development/surf-api の issue をすべて見る
似ている issue
-
jules
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
open-learning-exchange/myplanet#18199 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
auth0/Auth0.Android#1095 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Scheme-less stream URLs throw NullPointerException instead of URISyntaxException対応中かも @blihio が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
pedroSG94/RootEncoder#2218 ·
メンテナーはふだん 3 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
二维码代签解析失败オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
aquamarine5/ChaoxingSignFaker#235 · コメント 2 件 ·