Fixed a few bugs getting sample plugin to load

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2010-12-24 18:16:00 +00:00
parent 529268213b
commit 2aeec23737
6 changed files with 37 additions and 10 deletions

View file

@ -3,4 +3,9 @@
/nbproject
/build.xml
/manifest.mf
/dist
/dist
/sample/test
/sample/build.xml
/sample/build
/sample/dist
/sample/nbproject

View file

@ -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!");
}
}

View file

@ -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();
}

View file

@ -110,7 +110,6 @@ public final class PluginManager {
if (result != null) {
plugins.add(result);
lookupNames.put(result.getDescription().getName(), result);
result.onInitialize();
}
return result;

View file

@ -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;

View file

@ -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);