Skip to content

Commit 87c6195

Browse files
author
Jan Boerman
committed
Fake a plugin name if one is not yet present.
1 parent 924a766 commit 87c6195

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

  • ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat

ScalaLoader-Common/src/main/java/xyz/janboerman/scalaloader/compat/Platform.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
public class Platform {
2020

21+
private static final String FAKE_PLUGIN_NAME = "Fake";
22+
2123
protected Platform() {
2224
}
2325

@@ -33,7 +35,7 @@ public <ScalaPluginClassLoader extends ClassLoader & IScalaPluginClassLoader> by
3335
try {
3436
Server server = currentPluginClassLoader.getServer();
3537
UnsafeValues unsafeValues = server.getUnsafe();
36-
String fakeDescription = "name: Fake" + System.lineSeparator() +
38+
String fakeDescription = "name: " + FAKE_PLUGIN_NAME + System.lineSeparator() +
3739
"version: 1.0" + System.lineSeparator() +
3840
"main: xyz.janboerman.scalaloader.FakePlugin" + System.lineSeparator();
3941
ApiVersion apiVersion = currentPluginClassLoader.getApiVersion();
@@ -103,7 +105,7 @@ public <ScalaPluginClassLoader extends ClassLoader & IScalaPluginClassLoader> by
103105
}
104106

105107
if (commodoreConvert != null) {
106-
String pluginName = pluginClassLoader.getPlugin().getName();
108+
String pluginName = getPluginName(pluginClassLoader);
107109
try {
108110
MethodHandle getOrCreateVersion = lookup.findStatic(API_VERSION_CLASS, "getOrCreateVersion", MethodType.methodType(API_VERSION_CLASS, String.class));
109111
Object apiVersion = getOrCreateVersion.invoke(pluginClassLoader.getApiVersion().getVersionString());
@@ -155,6 +157,14 @@ public <ScalaPluginClassLoader extends ClassLoader & IScalaPluginClassLoader> by
155157
}
156158
}
157159

160+
private static String getPluginName(IScalaPluginClassLoader classLoader) {
161+
IScalaPlugin plugin = classLoader.getPlugin();
162+
if (plugin == null) {
163+
return FAKE_PLUGIN_NAME;
164+
} else {
165+
return plugin.getName();
166+
}
167+
}
158168
}
159169

160170
public static class GlowstonePlatform extends Platform {

0 commit comments

Comments
 (0)