From fa8a72ea5e0cc968b326a2012bc139546d314d53 Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Fri, 24 Dec 2010 19:05:14 +0000 Subject: [PATCH] Fixed plugin description loading No longer hardcoding sample plugin, now uses plugins dir By: Dinnerbone --- paper-api/sample/src/plugin.yml | 2 ++ .../src/org/bukkit/plugin/PluginManager.java | 2 +- .../bukkit/plugin/java/JavaPluginLoader.java | 25 ++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 paper-api/sample/src/plugin.yml diff --git a/paper-api/sample/src/plugin.yml b/paper-api/sample/src/plugin.yml new file mode 100644 index 0000000000..e4d19dc7a1 --- /dev/null +++ b/paper-api/sample/src/plugin.yml @@ -0,0 +1,2 @@ +name: Sample Plugin +main: com.dinnerbone.bukkit.sample.SamplePlugin diff --git a/paper-api/src/org/bukkit/plugin/PluginManager.java b/paper-api/src/org/bukkit/plugin/PluginManager.java index d35d91df13..0be6fa5ed9 100644 --- a/paper-api/src/org/bukkit/plugin/PluginManager.java +++ b/paper-api/src/org/bukkit/plugin/PluginManager.java @@ -81,7 +81,7 @@ public final class PluginManager { } } - return (Plugin[])result.toArray(); + return result.toArray(new Plugin[result.size()]); } /** diff --git a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java index 3eb517fffd..aaabe4f41c 100644 --- a/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/paper-api/src/org/bukkit/plugin/java/JavaPluginLoader.java @@ -3,13 +3,18 @@ package org.bukkit.plugin.java; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; import java.lang.reflect.Constructor; import java.net.URL; import java.net.URLClassLoader; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginLoader; import java.util.regex.Pattern; import org.bukkit.Server; +import org.bukkit.plugin.InvalidDescriptionException; import org.bukkit.plugin.InvalidPluginException; import org.bukkit.plugin.PluginDescriptionFile; @@ -28,11 +33,29 @@ public final class JavaPluginLoader implements PluginLoader { public Plugin loadPlugin(File file) throws InvalidPluginException { JavaPlugin result = null; - PluginDescriptionFile description = new PluginDescriptionFile("Sample Plugin", "com.dinnerbone.bukkit.sample.SamplePlugin"); + PluginDescriptionFile description = null; if (!file.exists()) { throw new InvalidPluginException(new FileNotFoundException(String.format("%s does not exist", file.getPath()))); } + try { + JarFile jar = new JarFile(file); + JarEntry entry = jar.getJarEntry("plugin.yml"); + + if (entry == null) { + throw new InvalidPluginException(new FileNotFoundException("Jar does not contain plugin.yml")); + } + + InputStream stream = jar.getInputStream(entry); + description = new PluginDescriptionFile(stream); + + stream.close(); + jar.close(); + } catch (IOException ex) { + throw new InvalidPluginException(ex); + } catch (InvalidDescriptionException ex) { + throw new InvalidPluginException(ex); + } try { ClassLoader loader = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()}, getClass().getClassLoader());