mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-14 05:33:56 +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
|
/nbproject
|
||||||
/build.xml
|
/build.xml
|
||||||
/manifest.mf
|
/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
|
* Called when this plugin is enabled
|
||||||
*/
|
*/
|
||||||
public void onEnable();
|
public void onEnable();
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when this plugin is first initialized
|
|
||||||
*/
|
|
||||||
public void onInitialize();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,6 @@ public final class PluginManager {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
plugins.add(result);
|
plugins.add(result);
|
||||||
lookupNames.put(result.getDescription().getName(), result);
|
lookupNames.put(result.getDescription().getName(), result);
|
||||||
result.onInitialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -27,7 +27,7 @@ public abstract class JavaPlugin implements Plugin {
|
||||||
* @param plugin File containing this plugin
|
* @param plugin File containing this plugin
|
||||||
* @param cLoader ClassLoader which holds 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;
|
loader = pluginLoader;
|
||||||
server = instance;
|
server = instance;
|
||||||
file = plugin;
|
file = plugin;
|
||||||
|
|
|
@ -28,7 +28,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
|
|
||||||
public Plugin loadPlugin(File file) throws InvalidPluginException {
|
public Plugin loadPlugin(File file) throws InvalidPluginException {
|
||||||
JavaPlugin result = null;
|
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()) {
|
if (!file.exists()) {
|
||||||
throw new InvalidPluginException(new FileNotFoundException(String.format("%s does not exist", file.getPath())));
|
throw new InvalidPluginException(new FileNotFoundException(String.format("%s does not exist", file.getPath())));
|
||||||
|
@ -36,7 +36,7 @@ public final class JavaPluginLoader implements PluginLoader {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ClassLoader loader = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()}, getClass().getClassLoader());
|
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);
|
Class<? extends JavaPlugin> plugin = jarClass.asSubclass(JavaPlugin.class);
|
||||||
Constructor<? extends JavaPlugin> constructor = plugin.getConstructor(PluginLoader.class, Server.class, PluginDescriptionFile.class, File.class, ClassLoader.class);
|
Constructor<? extends JavaPlugin> constructor = plugin.getConstructor(PluginLoader.class, Server.class, PluginDescriptionFile.class, File.class, ClassLoader.class);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue