diff --git a/common-env/src/main/java/taboolib/common/env/RuntimeEnv.java b/common-env/src/main/java/taboolib/common/env/RuntimeEnv.java index 3e763ef6f..30c41b222 100644 --- a/common-env/src/main/java/taboolib/common/env/RuntimeEnv.java +++ b/common-env/src/main/java/taboolib/common/env/RuntimeEnv.java @@ -2,10 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import taboolib.common.ClassAppender; -import taboolib.common.PrimitiveIO; -import taboolib.common.PrimitiveSettings; -import taboolib.common.TabooLib; +import taboolib.common.*; import java.io.File; import java.io.FileOutputStream; @@ -18,7 +15,7 @@ import java.util.List; import java.util.zip.ZipFile; -import static taboolib.common.PrimitiveSettings.KOTLINX_VERSION; +import static taboolib.common.PrimitiveSettings.KOTLIN_COROUTINES_VERSION; import static taboolib.common.PrimitiveSettings.KOTLIN_VERSION; /** @@ -31,7 +28,7 @@ public class RuntimeEnv { public static final String KOTLIN_ID = "!kotlin".substring(1); - public static final String KOTLINX_ID = "!kotlinx.coroutines".substring(1); + public static final String KOTLIN_COROUTINES_ID = "!kotlinx.coroutines".substring(1); public static final RuntimeEnv ENV = new RuntimeEnv(); @@ -49,13 +46,13 @@ static void init() throws Throwable { } // 启用 Kotlin 重定向 if (!PrimitiveSettings.SKIP_KOTLIN_RELOCATE) { - rel.add(new JarRelocation(KOTLIN_ID + ".", KOTLIN_ID + KOTLIN_VERSION.replace(".", "") + ".")); - rel.add(new JarRelocation(KOTLINX_ID + ".", KOTLINX_ID + KOTLINX_VERSION.replace(".", "") + ".")); + rel.add(new JarRelocation(KOTLIN_ID + ".", KOTLIN_ID + PrimitiveLoader.formatVersion(KOTLIN_VERSION) + ".")); + rel.add(new JarRelocation(KOTLIN_COROUTINES_ID + ".", KOTLIN_COROUTINES_ID + PrimitiveLoader.formatVersion(KOTLIN_COROUTINES_VERSION) + ".")); } } // 加载 Kotlin 环境 if (!KOTLIN_VERSION.equals("null")) ENV.loadDependency("org.jetbrains.kotlin:kotlin-stdlib:" + KOTLIN_VERSION, rel); - if (!KOTLINX_VERSION.equals("null")) ENV.loadDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:" + KOTLINX_VERSION, false, rel); + if (!KOTLIN_COROUTINES_VERSION.equals("null")) ENV.loadDependency("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:" + KOTLIN_COROUTINES_VERSION, false, rel); } public void inject(@NotNull Class clazz) throws Throwable { diff --git a/common/src/main/java/taboolib/common/PrimitiveLoader.java b/common/src/main/java/taboolib/common/PrimitiveLoader.java index 47a151831..3939d5908 100644 --- a/common/src/main/java/taboolib/common/PrimitiveLoader.java +++ b/common/src/main/java/taboolib/common/PrimitiveLoader.java @@ -145,15 +145,15 @@ public static void loadFile(File file, boolean isIsolated, boolean isExternal, S // 在非隔离模式下进行 Kotlin 重定向 if (!IS_ISOLATED_MODE && !SKIP_KOTLIN_RELOCATE) { String kt = "!kotlin".substring(1); - String ktx = "!kotlinx.coroutines".substring(1); - String kv = KOTLIN_VERSION.replace(".", ""); - String kvx = KOTLINX_VERSION.replace(".", ""); + String ktc = "!kotlinx.coroutines".substring(1); + String kv = formatVersion(KOTLIN_VERSION); + String kvc = formatVersion(KOTLIN_COROUTINES_VERSION); rel.add(new Relocation(kt + ".", kt + kv + ".")); - rel.add(new Relocation(ktx + ".", ktx + kvx + ".")); + rel.add(new Relocation(ktc + ".", ktc + kvc + ".")); } // 是否重定向 if (!rel.isEmpty()) { - String hash = PrimitiveIO.getHash(file.getName() + Arrays.deepHashCode(relocate) + KOTLIN_VERSION + KOTLINX_VERSION); + String hash = PrimitiveIO.getHash(file.getName() + Arrays.deepHashCode(relocate) + KOTLIN_VERSION + KOTLIN_COROUTINES_VERSION); jar = new File(getCacheFile(), hash + ".jar"); if ((!jar.exists() && jar.length() == 0) || IS_FORCE_DOWNLOAD_IN_DEV_MODE) { PrimitiveIO.println("Relocating ..."); @@ -206,4 +206,8 @@ private static File getLibraryFile() { } return file; } + + public static String formatVersion(String str) { + return str.replaceAll("[._-]", ""); + } } diff --git a/common/src/main/java/taboolib/common/PrimitiveSettings.java b/common/src/main/java/taboolib/common/PrimitiveSettings.java index 0663c773a..431b2e36e 100644 --- a/common/src/main/java/taboolib/common/PrimitiveSettings.java +++ b/common/src/main/java/taboolib/common/PrimitiveSettings.java @@ -35,7 +35,7 @@ public class PrimitiveSettings { /** * Kotlinx 版本 */ - public static final String KOTLINX_VERSION = VERSION_PROPERTIES.getProperty("!kotlin-coroutines".substring(1), "1.7.3"); + public static final String KOTLIN_COROUTINES_VERSION = VERSION_PROPERTIES.getProperty("!kotlin-coroutines".substring(1), "1.7.3"); /** * TabooLib 版本