mirror of
https://hub.spigotmc.org/stash/scm/spigot/bukkit.git
synced 2025-04-13 09:41:09 +00:00
#991: Add PluginManager#loadPlugins(File[])
This commit is contained in:
parent
624c810c36
commit
729fc6a80b
2 changed files with 43 additions and 23 deletions
|
@ -89,6 +89,15 @@ public interface PluginManager {
|
||||||
@NotNull
|
@NotNull
|
||||||
public Plugin[] loadPlugins(@NotNull File directory);
|
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
|
* 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 != null, "Directory cannot be null");
|
||||||
Preconditions.checkArgument(directory.isDirectory(), "Directory must be a directory");
|
Preconditions.checkArgument(directory.isDirectory(), "Directory must be a directory");
|
||||||
|
|
||||||
List<Plugin> result = new ArrayList<Plugin>();
|
|
||||||
Set<Pattern> filters = fileAssociations.keySet();
|
|
||||||
|
|
||||||
if (!(server.getUpdateFolder().equals(""))) {
|
if (!(server.getUpdateFolder().equals(""))) {
|
||||||
updateDirectory = new File(directory, server.getUpdateFolder());
|
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>();
|
Map<String, File> plugins = new HashMap<String, File>();
|
||||||
Set<String> loadedPlugins = new HashSet<String>();
|
Set<String> loadedPlugins = new HashSet<String>();
|
||||||
Map<String, String> pluginsProvided = new HashMap<>();
|
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>>();
|
Map<String, Collection<String>> softDependencies = new HashMap<String, Collection<String>>();
|
||||||
|
|
||||||
// This is where it figures out all possible plugins
|
// This is where it figures out all possible plugins
|
||||||
for (File file : directory.listFiles()) {
|
for (File file : files) {
|
||||||
PluginLoader loader = null;
|
PluginLoader loader = null;
|
||||||
for (Pattern filter : filters) {
|
for (Pattern filter : filters) {
|
||||||
Matcher match = filter.matcher(file.getName());
|
Matcher match = filter.matcher(file.getName());
|
||||||
|
@ -144,25 +157,24 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
description = loader.getPluginDescription(file);
|
description = loader.getPluginDescription(file);
|
||||||
String name = description.getName();
|
String name = description.getName();
|
||||||
if (name.equalsIgnoreCase("bukkit") || name.equalsIgnoreCase("minecraft") || name.equalsIgnoreCase("mojang")) {
|
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;
|
continue;
|
||||||
} else if (description.rawName.indexOf(' ') != -1) {
|
} 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;
|
continue;
|
||||||
}
|
}
|
||||||
} catch (InvalidDescriptionException ex) {
|
} 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
File replacedFile = plugins.put(description.getName(), file);
|
File replacedFile = plugins.put(description.getName(), file);
|
||||||
if (replacedFile != null) {
|
if (replacedFile != null) {
|
||||||
server.getLogger().severe(String.format(
|
server.getLogger().severe(String.format(
|
||||||
"Ambiguous plugin name `%s' for files `%s' and `%s' in `%s'",
|
"Ambiguous plugin name `%s' for files `%s' and `%s'",
|
||||||
description.getName(),
|
description.getName(),
|
||||||
file.getPath(),
|
file.getPath(),
|
||||||
replacedFile.getPath(),
|
replacedFile.getPath()
|
||||||
directory.getPath()
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,11 +191,10 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
File pluginFile = plugins.get(provided);
|
File pluginFile = plugins.get(provided);
|
||||||
if (pluginFile != null) {
|
if (pluginFile != null) {
|
||||||
server.getLogger().warning(String.format(
|
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(),
|
file.getPath(),
|
||||||
provided,
|
provided,
|
||||||
pluginFile.getPath(),
|
pluginFile.getPath()
|
||||||
directory.getPath()
|
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
String replacedPlugin = pluginsProvided.put(provided, description.getName());
|
String replacedPlugin = pluginsProvided.put(provided, description.getName());
|
||||||
|
@ -264,9 +275,9 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
dependencies.remove(plugin);
|
dependencies.remove(plugin);
|
||||||
|
|
||||||
server.getLogger().log(
|
server.getLogger().log(
|
||||||
Level.SEVERE,
|
Level.SEVERE,
|
||||||
"Could not load '" + entry.getValue().getPath() + "' in folder '" + directory.getPath() + "'",
|
"Could not load '" + entry.getValue().getPath() + "'",
|
||||||
new UnknownDependencyException("Unknown dependency " + dependency + ". Please download and install " + dependency + " to run this plugin."));
|
new UnknownDependencyException("Unknown dependency " + dependency + ". Please download and install " + dependency + " to run this plugin."));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,11 +315,11 @@ public final class SimplePluginManager implements PluginManager {
|
||||||
loadedPlugins.add(loadedPlugin.getName());
|
loadedPlugins.add(loadedPlugin.getName());
|
||||||
loadedPlugins.addAll(loadedPlugin.getDescription().getProvides());
|
loadedPlugins.addAll(loadedPlugin.getDescription().getProvides());
|
||||||
} else {
|
} 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;
|
continue;
|
||||||
} catch (InvalidPluginException ex) {
|
} 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.add(loadedPlugin.getName());
|
||||||
loadedPlugins.addAll(loadedPlugin.getDescription().getProvides());
|
loadedPlugins.addAll(loadedPlugin.getDescription().getProvides());
|
||||||
} else {
|
} 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;
|
break;
|
||||||
} catch (InvalidPluginException ex) {
|
} 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()) {
|
while (failedPluginIterator.hasNext()) {
|
||||||
File file = failedPluginIterator.next();
|
File file = failedPluginIterator.next();
|
||||||
failedPluginIterator.remove();
|
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…
Add table
Reference in a new issue