From 87c6195477d51189683fd4adc629a1a9de664c50 Mon Sep 17 00:00:00 2001 From: Jan Boerman Date: Tue, 10 Sep 2024 08:18:45 +0200 Subject: [PATCH] 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 be61eb0..b7e3b5a 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 {