mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 22:40:21 +01:00
Fixed a few bugs getting sample plugin to load
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
529268213b
commit
2aeec23737
6 changed files with 37 additions and 10 deletions
7
paper-api/.gitignore
vendored
7
paper-api/.gitignore
vendored
|
@ -3,4 +3,9 @@
|
|||
/nbproject
|
||||
/build.xml
|
||||
/manifest.mf
|
||||
/dist
|
||||
/dist
|
||||
/sample/test
|
||||
/sample/build.xml
|
||||
/sample/build
|
||||
/sample/dist
|
||||
/sample/nbproject
|
|
@ -0,0 +1,28 @@
|
|||
|
||||
package com.dinnerbone.bukkit.sample;
|
||||
|
||||
import java.io.File;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
/**
|
||||
* Sample plugin for Bukkit
|
||||
*
|
||||
* @author Dinnerbone
|
||||
*/
|
||||
public class SamplePlugin extends JavaPlugin {
|
||||
public SamplePlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
|
||||
super(pluginLoader, instance, desc, plugin, cLoader);
|
||||
System.out.println("Johnny five is alive!");
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
System.out.println("Goodbye world!");
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
System.out.println("Hello world!");
|
||||
}
|
||||
}
|
|
@ -44,9 +44,4 @@ public interface Plugin {
|
|||
* Called when this plugin is enabled
|
||||
*/
|
||||
public void onEnable();
|
||||
|
||||
/**
|
||||
* Called when this plugin is first initialized
|
||||
*/
|
||||
public void onInitialize();
|
||||
}
|
||||
|
|
|
@ -110,7 +110,6 @@ public final class PluginManager {
|
|||
if (result != null) {
|
||||
plugins.add(result);
|
||||
lookupNames.put(result.getDescription().getName(), result);
|
||||
result.onInitialize();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -27,7 +27,7 @@ public abstract class JavaPlugin implements Plugin {
|
|||
* @param plugin File containing this plugin
|
||||
* @param cLoader ClassLoader which holds this plugin
|
||||
*/
|
||||
protected JavaPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
|
||||
public JavaPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File plugin, ClassLoader cLoader) {
|
||||
loader = pluginLoader;
|
||||
server = instance;
|
||||
file = plugin;
|
||||
|
|
|
@ -28,7 +28,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||
|
||||
public Plugin loadPlugin(File file) throws InvalidPluginException {
|
||||
JavaPlugin result = null;
|
||||
PluginDescriptionFile description = new PluginDescriptionFile("Sample Plugin", "org.bukkit.plugin.sample.main");
|
||||
PluginDescriptionFile description = new PluginDescriptionFile("Sample Plugin", "com.dinnerbone.bukkit.sample.SamplePlugin");
|
||||
|
||||
if (!file.exists()) {
|
||||
throw new InvalidPluginException(new FileNotFoundException(String.format("%s does not exist", file.getPath())));
|
||||
|
@ -36,7 +36,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
|||
|
||||
try {
|
||||
ClassLoader loader = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()}, getClass().getClassLoader());
|
||||
Class<?> jarClass = Class.forName(description.getMain());
|
||||
Class<?> jarClass = Class.forName(description.getMain(), true, loader);
|
||||
Class<? extends JavaPlugin> plugin = jarClass.asSubclass(JavaPlugin.class);
|
||||
Constructor<? extends JavaPlugin> constructor = plugin.getConstructor(PluginLoader.class, Server.class, PluginDescriptionFile.class, File.class, ClassLoader.class);
|
||||
|
||||
|
|
Loading…
Reference in a new issue