From 6b42cbdd93819e3889ba9de0c1ca3b9e42053d6e Mon Sep 17 00:00:00 2001 From: Jan Boerman Date: Sat, 23 Mar 2024 16:40:49 +0100 Subject: [PATCH 1/7] Fix commentary mistake. --- .../runtime/types/ScalaCollection.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/configurationserializable/runtime/types/ScalaCollection.java b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/configurationserializable/runtime/types/ScalaCollection.java index b9b25a9d..37b75849 100644 --- a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/configurationserializable/runtime/types/ScalaCollection.java +++ b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/configurationserializable/runtime/types/ScalaCollection.java @@ -435,7 +435,7 @@ private static Date: Mon, 9 Sep 2024 22:33:35 +0200 Subject: [PATCH 2/7] get plugin meta of paper plugin using method handle lookup. --- .github/workflows/compile-test.yml | 1 + .../scalaloader/paper/plugin/PaperHacks.java | 2 ++ .../paper/plugin/ScalaPluginClassLoader.java | 36 +++++++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-test.yml b/.github/workflows/compile-test.yml index 652ac84c..328c48a2 100644 --- a/.github/workflows/compile-test.yml +++ b/.github/workflows/compile-test.yml @@ -21,6 +21,7 @@ jobs: git config --global user.name "Jannyboy11" git clone https://github.com/PaperMC/Paper cd Paper + git checkout ver/1.20.4 ./gradlew applyPatches ./gradlew createReobfBundlerJar ./gradlew build diff --git a/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/PaperHacks.java b/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/PaperHacks.java index e8ed26b6..70e96f57 100644 --- a/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/PaperHacks.java +++ b/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/PaperHacks.java @@ -17,4 +17,6 @@ public static PaperPluginManagerImpl getPaperPluginManager() { } } + + } diff --git a/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/ScalaPluginClassLoader.java b/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/ScalaPluginClassLoader.java index 7aea77f1..a397585e 100644 --- a/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/ScalaPluginClassLoader.java +++ b/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/ScalaPluginClassLoader.java @@ -4,6 +4,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; @@ -23,9 +26,11 @@ import java.util.jar.JarFile; import java.util.stream.Collectors; +import io.papermc.paper.plugin.configuration.PluginMeta; import io.papermc.paper.plugin.entrypoint.classloader.ClassloaderBytecodeModifier; import io.papermc.paper.plugin.entrypoint.classloader.PaperPluginClassLoader; +import io.papermc.paper.plugin.entrypoint.classloader.PaperSimplePluginClassLoader; import io.papermc.paper.plugin.manager.PaperPluginManagerImpl; import org.bukkit.Server; import org.bukkit.command.Command; @@ -44,6 +49,8 @@ import org.objectweb.asm.util.Printer; import org.objectweb.asm.util.Textifier; import org.objectweb.asm.util.TraceClassVisitor; + +import io.papermc.paper.plugin.provider.configuration.PaperPluginMeta; import xyz.janboerman.scalaloader.DebugSettings; import xyz.janboerman.scalaloader.bytecode.TransformerRegistry; import xyz.janboerman.scalaloader.compat.Compat; @@ -59,8 +66,22 @@ public class ScalaPluginClassLoader extends PaperPluginClassLoader implements IScalaPluginClassLoader { + private static final MethodHandle GET_CONFIGURATION; static { ClassLoader.registerAsParallelCapable(); + + MethodHandle getConfiguration; + MethodHandles.Lookup lookup = MethodHandles.lookup(); + try { + getConfiguration = lookup.findVirtual(PaperSimplePluginClassLoader.class, "getConfiguration", MethodType.methodType(PaperPluginMeta.class)); + } catch (NoSuchMethodException | IllegalAccessException e) { + try { + getConfiguration = lookup.findVirtual(PaperSimplePluginClassLoader.class, "getConfiguration", MethodType.methodType(PluginMeta.class)); + } catch (NoSuchMethodException | IllegalAccessException e2) { + getConfiguration = null; + } + } + GET_CONFIGURATION = getConfiguration; } private final ScalaPluginLoader pluginLoader; @@ -127,7 +148,18 @@ public File getPluginJarFile() { @Override public ScalaPluginMeta getConfiguration() { - return (ScalaPluginMeta) super.getConfiguration(); + return (ScalaPluginMeta) _getConfiguration(); + } + + private PluginMeta _getConfiguration() { + //Paper changed PaperSimplePluginClassLoader from PaperPluginMeta to PluginMeta: + //https://github.com/PaperMC/Paper/pull/10758/files#diff-1b48bde36fde990048ba454fb0bcc4e2b92a441c8387c350f1a8f0f09dbc8f8eR1127 + + try { + return (PluginMeta) GET_CONFIGURATION.invoke(this); + } catch (Throwable e) { + throw new RuntimeException("Could not get scala plugin configuration?", e); + } } @Override @@ -236,7 +268,7 @@ private void debugClass(String className, byte[] bytecode) { private byte[] transformBytecode(String className, byte[] byteCode) { //Paper-supported bytecode transformer via ServiceLoader api! - byteCode = ClassloaderBytecodeModifier.bytecodeModifier().modify(configuration, byteCode); + byteCode = ClassloaderBytecodeModifier.bytecodeModifier().modify(getConfiguration(), byteCode); //ScalaLoader transformations (everything except main class) byteCode = ClassLoaderUtils.transform(className, byteCode, this, transformerRegistry, this, ScalaLoader.getInstance().getLogger()); From 5e489a0d5105890294c92336ec004a776a6c528e Mon Sep 17 00:00:00 2001 From: Jan Boerman Date: Mon, 9 Sep 2024 22:43:53 +0200 Subject: [PATCH 3/7] get plugin meta using field reflection. --- .../paper/plugin/ScalaPluginClassLoader.java | 23 ++++--------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/ScalaPluginClassLoader.java b/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/ScalaPluginClassLoader.java index a397585e..2ba2b753 100644 --- a/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/ScalaPluginClassLoader.java +++ b/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/ScalaPluginClassLoader.java @@ -24,14 +24,11 @@ import java.util.jar.JarEntry; import java.util.logging.Logger; import java.util.jar.JarFile; -import java.util.stream.Collectors; import io.papermc.paper.plugin.configuration.PluginMeta; import io.papermc.paper.plugin.entrypoint.classloader.ClassloaderBytecodeModifier; import io.papermc.paper.plugin.entrypoint.classloader.PaperPluginClassLoader; -import io.papermc.paper.plugin.entrypoint.classloader.PaperSimplePluginClassLoader; -import io.papermc.paper.plugin.manager.PaperPluginManagerImpl; import org.bukkit.Server; import org.bukkit.command.Command; import org.bukkit.command.PluginCommand; @@ -50,7 +47,7 @@ import org.objectweb.asm.util.Textifier; import org.objectweb.asm.util.TraceClassVisitor; -import io.papermc.paper.plugin.provider.configuration.PaperPluginMeta; +import io.papermc.paper.plugin.entrypoint.classloader.PaperSimplePluginClassLoader; import xyz.janboerman.scalaloader.DebugSettings; import xyz.janboerman.scalaloader.bytecode.TransformerRegistry; import xyz.janboerman.scalaloader.compat.Compat; @@ -66,22 +63,8 @@ public class ScalaPluginClassLoader extends PaperPluginClassLoader implements IScalaPluginClassLoader { - private static final MethodHandle GET_CONFIGURATION; static { ClassLoader.registerAsParallelCapable(); - - MethodHandle getConfiguration; - MethodHandles.Lookup lookup = MethodHandles.lookup(); - try { - getConfiguration = lookup.findVirtual(PaperSimplePluginClassLoader.class, "getConfiguration", MethodType.methodType(PaperPluginMeta.class)); - } catch (NoSuchMethodException | IllegalAccessException e) { - try { - getConfiguration = lookup.findVirtual(PaperSimplePluginClassLoader.class, "getConfiguration", MethodType.methodType(PluginMeta.class)); - } catch (NoSuchMethodException | IllegalAccessException e2) { - getConfiguration = null; - } - } - GET_CONFIGURATION = getConfiguration; } private final ScalaPluginLoader pluginLoader; @@ -156,7 +139,9 @@ private PluginMeta _getConfiguration() { //https://github.com/PaperMC/Paper/pull/10758/files#diff-1b48bde36fde990048ba454fb0bcc4e2b92a441c8387c350f1a8f0f09dbc8f8eR1127 try { - return (PluginMeta) GET_CONFIGURATION.invoke(this); + Field field = PaperSimplePluginClassLoader.class.getDeclaredField("configuration"); + field.setAccessible(true); + return (PluginMeta) field.get(this); } catch (Throwable e) { throw new RuntimeException("Could not get scala plugin configuration?", e); } From b7700ac18778a6e24436cf56e1c80d13b6ec3146 Mon Sep 17 00:00:00 2001 From: Jan Boerman Date: Tue, 10 Sep 2024 00:31:42 +0200 Subject: [PATCH 4/7] debug Platform bytecode transformer --- .../scalaloader/compat/Platform.java | 62 ++++++++++++++++++- .../scalaloader/paper/plugin/PaperHacks.java | 4 +- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java index a8d2b01f..5a04fefe 100644 --- a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java +++ b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java @@ -10,6 +10,8 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; +import java.util.Collections; +import java.util.Set; /** * This class is NOT part of the public API! @@ -73,14 +75,65 @@ private CraftBukkitPlatform() {} private MethodHandle commodoreConvert = null; private boolean attempted = false; + public byte[] transformNative(Server craftServer, Class apiVersionClass, byte[] classBytes, ScalaPluginClassLoader pluginClassLoader) throws Throwable { + IScalaLoader.getInstance().getLogger().info("DEBUG: transform native.."); + MethodHandles.Lookup lookup = MethodHandles.lookup(); + if (commodoreConvert == null) { + + IScalaLoader.getInstance().getLogger().info("DEBUG: first attempt to find Commodore#convert!"); + attempted = true; + try { + // public static byte[] convert(byte[] b, final String pluginName, final ApiVersion pluginVersion, final Set activeCompatibilities) + Class commodoreClass = Class.forName(getPackageName(craftServer.getClass()) + ".util.Commodore"); + String methodName = "convert"; + MethodType methodType = MethodType.methodType(byte[].class, + new Class[] { byte[].class, String.class, apiVersionClass, Set.class }); + IScalaLoader.getInstance().getLogger().info("DEBUG: looking up static convert method.."); + commodoreConvert = lookup.findStatic(commodoreClass, methodName, methodType); + IScalaLoader.getInstance().getLogger().info("DEBUG: found commodore convert!"); + } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException ignored) { + IScalaLoader.getInstance() + .getLogger() + .info("DEBUG: could not find Commodore#convert!!! " + ignored.getClass().getName() + ": " + + ignored.getMessage()); + //impossible + } + } + + if (commodoreConvert != null) { + IScalaLoader.getInstance().getLogger().info("DEBUG: converting class.."); + String pluginName = pluginClassLoader.getPlugin().getName(); + try { + MethodHandle getOrCreateVersion = lookup.findStatic(apiVersionClass, "getOrCreateVersion", MethodType.methodType(apiVersionClass, String.class)); + Object apiVersion = getOrCreateVersion.invoke(pluginClassLoader.getApiVersion().getVersionString()); + + Set activeCompatibilities = Collections.emptySet(); + try { + MethodHandle compatibilitiesGetter = lookup.findGetter(craftServer.getClass(), "activeCompatibilities", Set.class); + activeCompatibilities = (Set) compatibilitiesGetter.invoke(craftServer); + } catch (Exception couldNotDetermineActiveCompatibilities) { + } + + classBytes = (byte[]) commodoreConvert.invoke(classBytes, pluginName, apiVersion, activeCompatibilities); + IScalaLoader.getInstance().getLogger().info("DEBUG: converted class!"); + } catch (NoSuchMethodException | IllegalAccessException ignored) { + IScalaLoader.getInstance().getLogger().info("DEBUG: could not invoke Commodore#convert!!! " + ignored.getClass().getName() + ": " + ignored.getMessage()); + } + } + + return classBytes; + } + public byte[] transformNative(Server craftServer, byte[] classBytes, boolean modern) throws Throwable { if (!attempted) { attempted = true; MethodHandles.Lookup lookup = MethodHandles.lookup(); try { + // public static byte[] convert(byte[] b, boolean isModern) Class commodoreClass = Class.forName(getPackageName(craftServer.getClass()) + ".util.Commodore"); String methodName = "convert"; - MethodType methodType = MethodType.methodType(byte[].class, new Class[]{byte[].class, boolean.class}); + MethodType methodType = MethodType.methodType(byte[].class, + new Class[] { byte[].class, boolean.class }); commodoreConvert = lookup.findStatic(commodoreClass, methodName, methodType); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException ignored) { //running on craftbukkit 1.12.2 or earlier @@ -96,7 +149,12 @@ public byte[] transformNative(Server craftServer, byte[] classBytes, boolean mod @Override public byte[] transform(String jarEntryPath, byte[] classBytes, ScalaPluginClassLoader pluginClassLoader) throws Throwable { - return transformNative(pluginClassLoader.getServer(), classBytes, pluginClassLoader.getApiVersion() != ApiVersion.LEGACY); + try { + Class apiVersionClass = Class.forName("org.bukkit.craftbukkit.util.ApiVersion"); + return transformNative(pluginClassLoader.getServer(), apiVersionClass, classBytes, pluginClassLoader); + } catch (ClassNotFoundException e) { + return transformNative(pluginClassLoader.getServer(), classBytes, pluginClassLoader.getApiVersion() != ApiVersion.LEGACY); + } } } diff --git a/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/PaperHacks.java b/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/PaperHacks.java index 70e96f57..a24cfdfa 100644 --- a/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/PaperHacks.java +++ b/ScalaLoader-Paper/src/main/java/xyz/janboerman/scalaloader/paper/plugin/PaperHacks.java @@ -4,7 +4,7 @@ import org.bukkit.Bukkit; import org.bukkit.plugin.PluginManager; -public class PaperHacks { +public final class PaperHacks { private PaperHacks() {} @@ -17,6 +17,4 @@ public static PaperPluginManagerImpl getPaperPluginManager() { } } - - } From debed00ba1048f4f70e10a42e5ce101991ee1f12 Mon Sep 17 00:00:00 2001 From: Jan Boerman Date: Tue, 10 Sep 2024 07:51:16 +0200 Subject: [PATCH 5/7] Clean up bytecode transformer debug. --- .../scalaloader/compat/Platform.java | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java index 5a04fefe..be61eb07 100644 --- a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java +++ b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java @@ -70,41 +70,42 @@ public static Platform detect(Server server) { public static class CraftBukkitPlatform extends Platform { + private static final Class API_VERSION_CLASS; + static { + Class apiVersionClass; + try { + apiVersionClass = Class.forName("org.bukkit.craftbukkit.util.ApiVersion"); + } catch (ClassNotFoundException e) { + apiVersionClass = null; + } + API_VERSION_CLASS = apiVersionClass; + } + private CraftBukkitPlatform() {} private MethodHandle commodoreConvert = null; private boolean attempted = false; - public byte[] transformNative(Server craftServer, Class apiVersionClass, byte[] classBytes, ScalaPluginClassLoader pluginClassLoader) throws Throwable { - IScalaLoader.getInstance().getLogger().info("DEBUG: transform native.."); + public byte[] transformNative(Server craftServer, byte[] classBytes, ScalaPluginClassLoader pluginClassLoader) throws Throwable { MethodHandles.Lookup lookup = MethodHandles.lookup(); if (commodoreConvert == null) { - - IScalaLoader.getInstance().getLogger().info("DEBUG: first attempt to find Commodore#convert!"); attempted = true; try { // public static byte[] convert(byte[] b, final String pluginName, final ApiVersion pluginVersion, final Set activeCompatibilities) Class commodoreClass = Class.forName(getPackageName(craftServer.getClass()) + ".util.Commodore"); String methodName = "convert"; MethodType methodType = MethodType.methodType(byte[].class, - new Class[] { byte[].class, String.class, apiVersionClass, Set.class }); - IScalaLoader.getInstance().getLogger().info("DEBUG: looking up static convert method.."); + new Class[] { byte[].class, String.class, API_VERSION_CLASS, Set.class }); commodoreConvert = lookup.findStatic(commodoreClass, methodName, methodType); - IScalaLoader.getInstance().getLogger().info("DEBUG: found commodore convert!"); } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException ignored) { - IScalaLoader.getInstance() - .getLogger() - .info("DEBUG: could not find Commodore#convert!!! " + ignored.getClass().getName() + ": " + - ignored.getMessage()); //impossible } } if (commodoreConvert != null) { - IScalaLoader.getInstance().getLogger().info("DEBUG: converting class.."); String pluginName = pluginClassLoader.getPlugin().getName(); try { - MethodHandle getOrCreateVersion = lookup.findStatic(apiVersionClass, "getOrCreateVersion", MethodType.methodType(apiVersionClass, String.class)); + MethodHandle getOrCreateVersion = lookup.findStatic(API_VERSION_CLASS, "getOrCreateVersion", MethodType.methodType(API_VERSION_CLASS, String.class)); Object apiVersion = getOrCreateVersion.invoke(pluginClassLoader.getApiVersion().getVersionString()); Set activeCompatibilities = Collections.emptySet(); @@ -115,9 +116,7 @@ public by } classBytes = (byte[]) commodoreConvert.invoke(classBytes, pluginName, apiVersion, activeCompatibilities); - IScalaLoader.getInstance().getLogger().info("DEBUG: converted class!"); } catch (NoSuchMethodException | IllegalAccessException ignored) { - IScalaLoader.getInstance().getLogger().info("DEBUG: could not invoke Commodore#convert!!! " + ignored.getClass().getName() + ": " + ignored.getMessage()); } } @@ -149,10 +148,9 @@ public byte[] transformNative(Server craftServer, byte[] classBytes, boolean mod @Override public byte[] transform(String jarEntryPath, byte[] classBytes, ScalaPluginClassLoader pluginClassLoader) throws Throwable { - try { - Class apiVersionClass = Class.forName("org.bukkit.craftbukkit.util.ApiVersion"); - return transformNative(pluginClassLoader.getServer(), apiVersionClass, classBytes, pluginClassLoader); - } catch (ClassNotFoundException e) { + if (API_VERSION_CLASS != null) { + return transformNative(pluginClassLoader.getServer(), classBytes, pluginClassLoader); + } else { return transformNative(pluginClassLoader.getServer(), classBytes, pluginClassLoader.getApiVersion() != ApiVersion.LEGACY); } } From 924a76636a77e14f11e9bad5c5198276f52a6e68 Mon Sep 17 00:00:00 2001 From: Jan Boerman Date: Tue, 10 Sep 2024 08:01:33 +0200 Subject: [PATCH 6/7] upgrade ASM and add some scala versions. --- ScalaLoader-Common/pom.xml | 2 +- .../scalaloader/plugin/description/ScalaVersion.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ScalaLoader-Common/pom.xml b/ScalaLoader-Common/pom.xml index 124d22ee..2fff7b27 100644 --- a/ScalaLoader-Common/pom.xml +++ b/ScalaLoader-Common/pom.xml @@ -13,7 +13,7 @@ 1.20.4-R0.1-SNAPSHOT - 9.6 + 9.7 3.0.0 5.7.1 1.6.2 diff --git a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/plugin/description/ScalaVersion.java b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/plugin/description/ScalaVersion.java index af1fae60..b5f3132c 100644 --- a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/plugin/description/ScalaVersion.java +++ b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/plugin/description/ScalaVersion.java @@ -30,6 +30,9 @@ public enum ScalaVersion { v2_12_15("2.12.15"), v2_12_16("2.12.16"), v2_12_17("2.12.17"), + v2_12_18("2.12.18"), + v2_12_19("2.12.19"), + v2_12_20("2.12.20"), //2.13.x v2_13_0("2.13.0"), @@ -46,6 +49,7 @@ public enum ScalaVersion { v2_13_11("2.13.11"), v2_13_12("2.13.12"), v2_13_13("2.13.13"), + v2_13_14("2.13.14"), //3.0.x v3_0_0("3.0.0"), @@ -70,7 +74,13 @@ public enum ScalaVersion { v3_3_3("3.3.3"), //3.4.0 - v3_4_0("3.4.0"); + v3_4_0("3.4.0"), + v3_4_1("3.4.1"), + v3_4_2("3.4.2"), + v3_4_3("3.4.3"), + + //3.5.0 + v3_5_0("3.5.0"); //TODO include hashes of the jars! so that the loader can verify the integrity of the jars! From 87c6195477d51189683fd4adc629a1a9de664c50 Mon Sep 17 00:00:00 2001 From: Jan Boerman Date: Tue, 10 Sep 2024 08:18:45 +0200 Subject: [PATCH 7/7] Fake a plugin name if one is not yet present. --- .../janboerman/scalaloader/compat/Platform.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java index be61eb07..b7e3b5a0 100644 --- a/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java +++ b/ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java @@ -18,6 +18,8 @@ */ public class Platform { + private static final String FAKE_PLUGIN_NAME = "Fake"; + protected Platform() { } @@ -33,7 +35,7 @@ public by try { Server server = currentPluginClassLoader.getServer(); UnsafeValues unsafeValues = server.getUnsafe(); - String fakeDescription = "name: Fake" + System.lineSeparator() + + String fakeDescription = "name: " + FAKE_PLUGIN_NAME + System.lineSeparator() + "version: 1.0" + System.lineSeparator() + "main: xyz.janboerman.scalaloader.FakePlugin" + System.lineSeparator(); ApiVersion apiVersion = currentPluginClassLoader.getApiVersion(); @@ -103,7 +105,7 @@ public by } if (commodoreConvert != null) { - String pluginName = pluginClassLoader.getPlugin().getName(); + String pluginName = getPluginName(pluginClassLoader); try { MethodHandle getOrCreateVersion = lookup.findStatic(API_VERSION_CLASS, "getOrCreateVersion", MethodType.methodType(API_VERSION_CLASS, String.class)); Object apiVersion = getOrCreateVersion.invoke(pluginClassLoader.getApiVersion().getVersionString()); @@ -155,6 +157,14 @@ public by } } + private static String getPluginName(IScalaPluginClassLoader classLoader) { + IScalaPlugin plugin = classLoader.getPlugin(); + if (plugin == null) { + return FAKE_PLUGIN_NAME; + } else { + return plugin.getName(); + } + } } public static class GlowstonePlatform extends Platform {