mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-28 05:35:28 +01:00
Permit cross edges when validating dependencies. FIXES 91.
This commit is contained in:
parent
6af440789c
commit
02b5dec304
@ -83,7 +83,7 @@ class PluginVerifier {
|
||||
* @throws PluginNotFoundException If a plugin with the given name cannot be found.
|
||||
*/
|
||||
private Plugin getPlugin(String pluginName) {
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin(pluginName);
|
||||
Plugin plugin = getPluginOrDefault(pluginName);
|
||||
|
||||
// Ensure that the plugin exists
|
||||
if (plugin != null)
|
||||
@ -92,6 +92,15 @@ class PluginVerifier {
|
||||
throw new PluginNotFoundException("Cannot find plugin " + pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a plugin by name.
|
||||
* @param pluginName - the non-null name of the plugin to retrieve.
|
||||
* @return The retrieved plugin, or NULL if not found.
|
||||
*/
|
||||
private Plugin getPluginOrDefault(String pluginName) {
|
||||
return Bukkit.getPluginManager().getPlugin(pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs simple verifications on the given plugin.
|
||||
* <p>
|
||||
@ -183,15 +192,15 @@ class PluginVerifier {
|
||||
return Sets.newHashSet(list);
|
||||
}
|
||||
|
||||
// Avoid cycles
|
||||
private boolean hasDependency(Plugin plugin, Plugin dependency, Set<String> checked) {
|
||||
// Avoid cycles. DFS.
|
||||
private boolean hasDependency(Plugin plugin, Plugin dependency, Set<String> checking) {
|
||||
Set<String> childNames = Sets.union(
|
||||
safeConversion(plugin.getDescription().getDepend()),
|
||||
safeConversion(plugin.getDescription().getSoftDepend())
|
||||
);
|
||||
|
||||
// Ensure that the same plugin isn't processed twice
|
||||
if (!checked.add(plugin.getName())) {
|
||||
if (!checking.add(plugin.getName())) {
|
||||
throw new IllegalStateException("Cycle detected in dependency graph: " + plugin);
|
||||
}
|
||||
// Look for the dependency in the immediate children
|
||||
@ -201,13 +210,16 @@ class PluginVerifier {
|
||||
|
||||
// Recurse through their dependencies
|
||||
for (String childName : childNames) {
|
||||
Plugin childPlugin = getPlugin(childName);
|
||||
Plugin childPlugin = getPluginOrDefault(childName);
|
||||
|
||||
if (hasDependency(childPlugin, dependency, checked)) {
|
||||
if (childPlugin != null && hasDependency(childPlugin, dependency, checking)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Cross edges are permitted
|
||||
checking.remove(plugin.getName());
|
||||
|
||||
// No dependency found!
|
||||
return false;
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.comphenix.protocol.Packets;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.error.ReportType;
|
||||
|
Loading…
Reference in New Issue
Block a user