Skip to content

Commit

Permalink
add migrator for ScalaPluginLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannyboy11 committed Apr 4, 2023
1 parent 7a8cbf3 commit 13e6a95
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,20 @@ public void reloadConfig() {
/**
* Gets the plugin loader.
* @return a {@link ScalaPluginLoader}
* @deprecated use {@link #pluginLoader()} instead.
*/
@Deprecated //TODO at the next deprecation clean up spree, make this method final.
@Override
public ScalaPluginLoader getPluginLoader() {
return pluginLoader();
}

/**
* Get the plugin loader.
* @return a {@link ScalaPluginLoader}
*/
@Override
public ScalaPluginLoader pluginLoader() {
return pluginLoader;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public default IScalaPluginClassLoader classLoader() {
return (IScalaPluginClassLoader) getClass().getClassLoader();
}

/**
* Get the {@link org.bukkit.plugin.PluginLoader} of this plugin.
* @return the plugin loader
*/
public default IScalaPluginLoader pluginLoader() {
return classLoader().getPluginLoader();
}

/**
* Get the prefix of this plugin, used for logging.
* @return the prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.bukkit.event.server.ServerLoadEvent;
import org.bukkit.event.server.ServerLoadEvent.LoadType;
import org.bukkit.plugin.PluginLoadOrder;
import org.bukkit.plugin.UnknownDependencyException;
import org.bukkit.plugin.java.JavaPlugin;
import org.objectweb.asm.ClassReader;
import org.yaml.snakeyaml.Yaml;
Expand Down Expand Up @@ -286,6 +287,7 @@ private void loadScalaPlugins(File[] files) {
File file = byName.get(pluginName);
PluginJarScanResult scanResult = scanResults.get(file);
ScalaPluginDescription description = descriptions.get(file);
//TODO check dependencies. if not available, might want to try to load the ScalaPlugin again once Paper's own JavaPlugin loading process has finished.

ScalaPluginProviderContext context = new ScalaPluginProviderContext(file, description);
var optionalBootstrap = getBootstrap(description, descriptionPlugins.get(file).descriptionClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public ScalaPluginClassLoader classLoader() {
return (ScalaPluginClassLoader) super.getClassLoader();
}

@Override
public ScalaPluginLoader pluginLoader() {
return (ScalaPluginLoader) classLoader().getPluginLoader();
}

/** {@inheritDoc} */
@Override
public File getConfigFile() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public MethodVisitor visitMethod(int access, String name, String descriptor, Str
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
if (asmMainClassName.equals(owner) && name.equals("getClassLoader")) {
super.visitMethodInsn(opcode, asmMainClassName, "classLoader", descriptor, isInterface);
} else if (asmMainClassName.equals(owner) && name.equals("getPluginLoader")) {
super.visitMethodInsn(opcode, asmMainClassName, "pluginLoader", descriptor, isInterface);
} else {
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
}
Expand Down

0 comments on commit 13e6a95

Please sign in to comment.