From 4d42cf1c6dbacc364172ef5c4b66644af68b1fe1 Mon Sep 17 00:00:00 2001 From: Jie-150 <1503745098@qq.com> Date: Tue, 14 Jul 2026 02:12:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Mojang=20=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=97=B6=E7=B1=BB=E5=90=8D=E8=BD=AC=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/nms/remap/RemapTranslation.kt | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/module/bukkit-nms/src/main/kotlin/taboolib/module/nms/remap/RemapTranslation.kt b/module/bukkit-nms/src/main/kotlin/taboolib/module/nms/remap/RemapTranslation.kt index be680ad43..771d1b836 100644 --- a/module/bukkit-nms/src/main/kotlin/taboolib/module/nms/remap/RemapTranslation.kt +++ b/module/bukkit-nms/src/main/kotlin/taboolib/module/nms/remap/RemapTranslation.kt @@ -1,11 +1,12 @@ package taboolib.module.nms.remap -import org.objectweb.asm.commons.Remapper import org.objectweb.asm.ClassReader import org.objectweb.asm.ClassWriter import org.objectweb.asm.Opcodes +import org.objectweb.asm.commons.Remapper import taboolib.common.reflect.ClassHelper import taboolib.module.nms.MinecraftVersion +import taboolib.module.nms.remap.RemapTranslation.Companion.extraTransformers import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.CopyOnWriteArrayList @@ -99,9 +100,7 @@ open class RemapTranslation : Remapper() { if (!MinecraftVersion.isMojangMapping) { translateMojangToSpigotOrKeepRuntime(key) } else { - // 如果为 Mojang Mapping 环境,这里不管是 Spigot.Fullname 还是 Mojang.Fullname 都不需要动 - // 如果是 Spigot.Fullname,Paper PluginRemapper 会进行转译 - key + translateMojangToRuntimeOrKeep(key) } } } else { @@ -137,6 +136,21 @@ open class RemapTranslation : Remapper() { return spigotName } + /** + * 将 Mojang 类名转为 Runtime 类名,运行时已有类名优先保留。 + */ + fun translateMojangToRuntimeOrKeep(key: String): String { + val runtimeName = key.replace('/', '.') + if (hasRuntimeClass(runtimeName)) { + return key + } + val shortName = runtimeName.substringAfterLast('.') + val mappingName = MinecraftVersion.paperMapping.classMapSpigotToMojang[runtimeName] + ?: MinecraftVersion.paperMapping.classMapSpigotToMojang.values.singleOrNull { it.substringAfterLast('.') == shortName } + ?: return key + return if (hasRuntimeClass(mappingName)) mappingName.replace('.', '/') else key + } + /** * 检查类名是否已是当前运行时可直接加载的名称。 *