Fixed plugin description loading
No longer hardcoding sample plugin, now uses plugins dir
This commit is contained in:
parent
b8c8beab9a
commit
d98b41865e
2
sample/src/plugin.yml
Normal file
2
sample/src/plugin.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
name: Sample Plugin
|
||||||
|
main: com.dinnerbone.bukkit.sample.SamplePlugin
|
@ -81,7 +81,7 @@ public final class PluginManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (Plugin[])result.toArray();
|
return result.toArray(new Plugin[result.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,13 +3,18 @@ package org.bukkit.plugin.java;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginLoader;
|
import org.bukkit.plugin.PluginLoader;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.plugin.InvalidDescriptionException;
|
||||||
import org.bukkit.plugin.InvalidPluginException;
|
import org.bukkit.plugin.InvalidPluginException;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
|
||||||
@ -28,11 +33,29 @@ 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", "com.dinnerbone.bukkit.sample.SamplePlugin");
|
PluginDescriptionFile description = null;
|
||||||
|
|
||||||
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())));
|
||||||
}
|
}
|
||||||
|
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 {
|
try {
|
||||||
ClassLoader loader = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()}, getClass().getClassLoader());
|
ClassLoader loader = URLClassLoader.newInstance(new URL[]{file.toURI().toURL()}, getClass().getClassLoader());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user