mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 11:58:06 +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,6 +2,7 @@
|
|||||||
package org.bukkit.plugin;
|
package org.bukkit.plugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -24,13 +25,29 @@ public final class PluginManager {
|
|||||||
/**
|
/**
|
||||||
* Registers the specified plugin loader
|
* Registers the specified plugin loader
|
||||||
*
|
*
|
||||||
* @param loader PluginLoader to register
|
* @param loader Class name of the PluginLoader to register
|
||||||
*/
|
*/
|
||||||
public void RegisterInterface(PluginLoader loader) {
|
public void RegisterInterface(Class loader) {
|
||||||
Pattern[] patterns = loader.getPluginFileFilters();
|
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) {
|
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.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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Java plugin loader, allowing plugins in the form of .jars
|
* Represents a Java plugin loader, allowing plugins in the form of .jars
|
||||||
*/
|
*/
|
||||||
public final class JavaPluginLoader implements PluginLoader {
|
public final class JavaPluginLoader implements PluginLoader {
|
||||||
|
private final Server server;
|
||||||
private final Pattern[] fileFilters = new Pattern[] {
|
private final Pattern[] fileFilters = new Pattern[] {
|
||||||
Pattern.compile("\\.jar$"),
|
Pattern.compile("\\.jar$"),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public JavaPluginLoader(Server instance) {
|
||||||
|
server = instance;
|
||||||
|
}
|
||||||
|
|
||||||
public Plugin getPlugin(String name) {
|
public Plugin getPlugin(String name) {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user