Skip to content

Commit

Permalink
Fake a plugin name if one is not yet present.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Boerman committed Sep 10, 2024
1 parent 924a766 commit 87c6195
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
public class Platform {

private static final String FAKE_PLUGIN_NAME = "Fake";

protected Platform() {
}

Expand All @@ -33,7 +35,7 @@ public <ScalaPluginClassLoader extends ClassLoader & IScalaPluginClassLoader> 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();
Expand Down Expand Up @@ -103,7 +105,7 @@ public <ScalaPluginClassLoader extends ClassLoader & IScalaPluginClassLoader> 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());
Expand Down Expand Up @@ -155,6 +157,14 @@ public <ScalaPluginClassLoader extends ClassLoader & IScalaPluginClassLoader> 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 {
Expand Down

0 comments on commit 87c6195

Please sign in to comment.