Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Automatic API Remapping via ASM Bytecode Transformation on Plugin Load

クローズ
#77 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@twisti-dev がすでに取り組んでいます。

2025年4月2日 から。

評価

この issue はまだ評価されていません。

説明

status: needs triage
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 ClassloaderBytecodeModifier interface
  • 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.
  1. Requiring all plugin developers to recompile against each API version – time-consuming and not scalable.
  2. Providing adapter shims – limited in scope and still require frequent maintenance.
  3. 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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

SLNE-Development/surf-api のほかの issue

SLNE-Development/surf-api の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。