Skip to content

Commit 0877619

Browse files
committed
Handle cyclic plugin dependencies by disabling the plugin
1 parent cc76bb1 commit 0877619

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

shreddedpaper-server/src/main/java/io/multipaper/shreddedpaper/threading/SynchronousPluginExecution.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public static void execute(Plugin plugin, RunnableWithException runnable) throws
5656
// computeIfAbsent requires an expensive synchronized call even if the value is already present, so check with a get first
5757
pluginsToLock = cachedDependencyLists.computeIfAbsent(plugin.getName(), (name) -> {
5858
TreeSet<String> dependencyList = new TreeSet<>(Comparator.naturalOrder());
59+
LOGGER.info("Plugin {} does not support Folia! Initializing synchronous execution. This may cause a performance degradation.", plugin);
5960
fillPluginsToLock(plugin, dependencyList);
60-
LOGGER.info("Plugin {} does not support Folia! Initializing synchronous execution. This may cause a performance degradation.", plugin.getName());
61-
LOGGER.info("Dependency list calculated for {}: {}", plugin.getName(), dependencyList);
61+
LOGGER.info("Dependency list calculated for {}: {}", plugin, dependencyList);
6262
return new ArrayList<>(dependencyList);
6363
});
6464
}
@@ -139,8 +139,10 @@ private static boolean tryLockNow(List<String> locksToReacquire) {
139139
}
140140

141141
private static boolean fillPluginsToLock(Plugin plugin, TreeSet<String> pluginsToLock) {
142-
if (pluginsToLock.contains(plugin.getName())) {
142+
if (!pluginsToLock.add(plugin.getName())) {
143143
// Cyclic graphhhh
144+
LOGGER.error("Cyclich graph detected for plugin {}, synchronous execution initialising failure, disabling plugin.", plugin);
145+
plugin.getServer().getPluginManager().disablePlugin(plugin);
144146
return true;
145147
}
146148

@@ -167,10 +169,10 @@ private static boolean fillPluginsToLock(Plugin plugin, TreeSet<String> pluginsT
167169
}
168170
}
169171

170-
if (!hasDependency) {
172+
if (hasDependency) {
171173
// Only add our own plugin if we have no dependencies to lock
172174
// If we have a dependency, there's no point in locking this plugin by itself as we'll always be locking the dependency anyway
173-
pluginsToLock.add(plugin.getName());
175+
pluginsToLock.remove(plugin.getName());
174176
}
175177

176178
return true;

0 commit comments

Comments
 (0)