mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 23:10:16 +01:00
Pass the Server instance to pluginloaders, changed register method on pluginmanager
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
7cdc2d46c2
commit
118fbe5d87
2 changed files with 27 additions and 4 deletions
|
@ -2,6 +2,7 @@
|
|||
package org.bukkit.plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -24,13 +25,29 @@ public final class PluginManager {
|
|||
/**
|
||||
* Registers the specified plugin loader
|
||||
*
|
||||
* @param loader PluginLoader to register
|
||||
* @param loader Class name of the PluginLoader to register
|
||||
*/
|
||||
public void RegisterInterface(PluginLoader loader) {
|
||||
Pattern[] patterns = loader.getPluginFileFilters();
|
||||
public void RegisterInterface(Class loader) {
|
||||
PluginLoader instance;
|
||||
|
||||
if (PluginLoader.class.isAssignableFrom(loader)) {
|
||||
Constructor constructor;
|
||||
try {
|
||||
constructor = loader.getConstructor(Server.class);
|
||||
instance = (PluginLoader) constructor.newInstance(server);
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new IllegalArgumentException(String.format("Class %s does not have a public %s(Server) constructor", loader.getName()), ex);
|
||||
} catch (Exception ex) {
|
||||
throw new IllegalArgumentException(String.format("Unexpected exception %s while attempting to construct a new instance of %s", ex.getClass().getName(), loader.getName()), ex);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("Class %s does not implement interface PluginLoader", loader.getName()));
|
||||
}
|
||||
|
||||
Pattern[] patterns = instance.getPluginFileFilters();
|
||||
|
||||
for (Pattern pattern : patterns) {
|
||||
fileAssociations.put(pattern, loader);
|
||||
fileAssociations.put(pattern, instance);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,15 +5,21 @@ import java.io.File;
|
|||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginLoader;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.Server;
|
||||
|
||||
/**
|
||||
* Represents a Java plugin loader, allowing plugins in the form of .jars
|
||||
*/
|
||||
public final class JavaPluginLoader implements PluginLoader {
|
||||
private final Server server;
|
||||
private final Pattern[] fileFilters = new Pattern[] {
|
||||
Pattern.compile("\\.jar$"),
|
||||
};
|
||||
|
||||
public JavaPluginLoader(Server instance) {
|
||||
server = instance;
|
||||
}
|
||||
|
||||
public Plugin getPlugin(String name) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue