mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
#991: Add PluginManager#loadPlugins(File[])
By: MikChan <georgeendo0@gmail.com>
This commit is contained in:
parent
ef44483fd2
commit
afe543345e
2 changed files with 43 additions and 23 deletions
|
@ -89,6 +89,15 @@ public interface PluginManager {
|
|||
@NotNull
|
||||
public Plugin[] loadPlugins(@NotNull File directory);
|
||||
|
||||
/**
|
||||
* Loads the plugins in the list of the files
|
||||
*
|
||||
* @param files List of files containing plugins to load
|
||||
* @return A list of all plugins loaded
|
||||
*/
|
||||
@NotNull
|
||||
public Plugin[] loadPlugins(@NotNull File[] files);
|
||||
|
||||
/**
|
||||
* Disables all the loaded plugins
|
||||
*/
|
||||
|
|
|
@ -114,13 +114,26 @@ public final class SimplePluginManager implements PluginManager {
|
|||
Preconditions.checkArgument(directory != null, "Directory cannot be null");
|
||||
Preconditions.checkArgument(directory.isDirectory(), "Directory must be a directory");
|
||||
|
||||
List<Plugin> result = new ArrayList<Plugin>();
|
||||
Set<Pattern> filters = fileAssociations.keySet();
|
||||
|
||||
if (!(server.getUpdateFolder().equals(""))) {
|
||||
updateDirectory = new File(directory, server.getUpdateFolder());
|
||||
}
|
||||
|
||||
return loadPlugins(directory.listFiles());
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the plugins in the list of the files
|
||||
*
|
||||
* @param files List of files containing plugins to load
|
||||
* @return A list of all plugins loaded
|
||||
*/
|
||||
@NotNull
|
||||
public Plugin[] loadPlugins(@NotNull File[] files) {
|
||||
Preconditions.checkArgument(files != null, "File list cannot be null");
|
||||
|
||||
List<Plugin> result = new ArrayList<Plugin>();
|
||||
Set<Pattern> filters = fileAssociations.keySet();
|
||||
|
||||
Map<String, File> plugins = new HashMap<String, File>();
|
||||
Set<String> loadedPlugins = new HashSet<String>();
|
||||
Map<String, String> pluginsProvided = new HashMap<>();
|
||||
|
@ -128,7 +141,7 @@ public final class SimplePluginManager implements PluginManager {
|
|||
Map<String, Collection<String>> softDependencies = new HashMap<String, Collection<String>>();
|
||||
|
||||
// This is where it figures out all possible plugins
|
||||
for (File file : directory.listFiles()) {
|
||||
for (File file : files) {
|
||||
PluginLoader loader = null;
|
||||
for (Pattern filter : filters) {
|
||||
Matcher match = filter.matcher(file.getName());
|
||||
|
@ -144,25 +157,24 @@ public final class SimplePluginManager implements PluginManager {
|
|||
description = loader.getPluginDescription(file);
|
||||
String name = description.getName();
|
||||
if (name.equalsIgnoreCase("bukkit") || name.equalsIgnoreCase("minecraft") || name.equalsIgnoreCase("mojang")) {
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': Restricted Name");
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "': Restricted Name");
|
||||
continue;
|
||||
} else if (description.rawName.indexOf(' ') != -1) {
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': uses the space-character (0x20) in its name");
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "': uses the space-character (0x20) in its name");
|
||||
continue;
|
||||
}
|
||||
} catch (InvalidDescriptionException ex) {
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex);
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "'", ex);
|
||||
continue;
|
||||
}
|
||||
|
||||
File replacedFile = plugins.put(description.getName(), file);
|
||||
if (replacedFile != null) {
|
||||
server.getLogger().severe(String.format(
|
||||
"Ambiguous plugin name `%s' for files `%s' and `%s' in `%s'",
|
||||
description.getName(),
|
||||
file.getPath(),
|
||||
replacedFile.getPath(),
|
||||
directory.getPath()
|
||||
"Ambiguous plugin name `%s' for files `%s' and `%s'",
|
||||
description.getName(),
|
||||
file.getPath(),
|
||||
replacedFile.getPath()
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -179,11 +191,10 @@ public final class SimplePluginManager implements PluginManager {
|
|||
File pluginFile = plugins.get(provided);
|
||||
if (pluginFile != null) {
|
||||
server.getLogger().warning(String.format(
|
||||
"`%s provides `%s' while this is also the name of `%s' in `%s'",
|
||||
"`%s provides `%s' while this is also the name of `%s'",
|
||||
file.getPath(),
|
||||
provided,
|
||||
pluginFile.getPath(),
|
||||
directory.getPath()
|
||||
pluginFile.getPath()
|
||||
));
|
||||
} else {
|
||||
String replacedPlugin = pluginsProvided.put(provided, description.getName());
|
||||
|
@ -264,9 +275,9 @@ public final class SimplePluginManager implements PluginManager {
|
|||
dependencies.remove(plugin);
|
||||
|
||||
server.getLogger().log(
|
||||
Level.SEVERE,
|
||||
"Could not load '" + entry.getValue().getPath() + "' in folder '" + directory.getPath() + "'",
|
||||
new UnknownDependencyException("Unknown dependency " + dependency + ". Please download and install " + dependency + " to run this plugin."));
|
||||
Level.SEVERE,
|
||||
"Could not load '" + entry.getValue().getPath() + "'",
|
||||
new UnknownDependencyException("Unknown dependency " + dependency + ". Please download and install " + dependency + " to run this plugin."));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -304,11 +315,11 @@ public final class SimplePluginManager implements PluginManager {
|
|||
loadedPlugins.add(loadedPlugin.getName());
|
||||
loadedPlugins.addAll(loadedPlugin.getDescription().getProvides());
|
||||
} else {
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'");
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "'");
|
||||
}
|
||||
continue;
|
||||
} catch (InvalidPluginException ex) {
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex);
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "'", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -335,11 +346,11 @@ public final class SimplePluginManager implements PluginManager {
|
|||
loadedPlugins.add(loadedPlugin.getName());
|
||||
loadedPlugins.addAll(loadedPlugin.getDescription().getProvides());
|
||||
} else {
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'");
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "'");
|
||||
}
|
||||
break;
|
||||
} catch (InvalidPluginException ex) {
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "'", ex);
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "'", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -352,7 +363,7 @@ public final class SimplePluginManager implements PluginManager {
|
|||
while (failedPluginIterator.hasNext()) {
|
||||
File file = failedPluginIterator.next();
|
||||
failedPluginIterator.remove();
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "' in folder '" + directory.getPath() + "': circular dependency detected");
|
||||
server.getLogger().log(Level.SEVERE, "Could not load '" + file.getPath() + "': circular dependency detected");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue