From be9ecf75b2e1fa014e2ce21ebbcfaea5ecdd458d Mon Sep 17 00:00:00 2001 From: Aaron <71191102+RealBauHD@users.noreply.github.com> Date: Sat, 5 Aug 2023 02:48:01 +0200 Subject: [PATCH] check if a plugin has a executor service (#1038) * check if a plugin has an executor service * checkstyle --- .../loader/VelocityPluginContainer.java | 4 ++++ .../proxy/scheduler/VelocityScheduler.java | 22 ++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java index 40b00df7c..5e757708e 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/plugin/loader/VelocityPluginContainer.java @@ -71,4 +71,8 @@ public class VelocityPluginContainer implements PluginContainer { return this.service; } + + public boolean hasExecutorService() { + return this.service != null; + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java index 96d0b94d6..727832bd4 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java @@ -30,9 +30,12 @@ import com.velocitypowered.api.scheduler.ScheduledTask; import com.velocitypowered.api.scheduler.Scheduler; import com.velocitypowered.api.scheduler.TaskStatus; import com.velocitypowered.proxy.plugin.loader.VelocityPluginContainer; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.IdentityHashMap; +import java.util.Iterator; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -116,17 +119,24 @@ public class VelocityScheduler implements Scheduler { task.cancel(); } timerExecutionService.shutdown(); - for (final PluginContainer container : this.pluginManager.getPlugins()) { + final List plugins = new ArrayList<>(this.pluginManager.getPlugins()); + final Iterator pluginIterator = plugins.iterator(); + while (pluginIterator.hasNext()) { + final PluginContainer container = pluginIterator.next(); if (container instanceof VelocityPluginContainer) { - (container).getExecutorService().shutdown(); + final VelocityPluginContainer pluginContainer = (VelocityPluginContainer) container; + if (pluginContainer.hasExecutorService()) { + container.getExecutorService().shutdown(); + } else { + pluginIterator.remove(); + } + } else { + pluginIterator.remove(); } } boolean allShutdown = true; - for (final PluginContainer container : this.pluginManager.getPlugins()) { - if (!(container instanceof VelocityPluginContainer)) { - continue; - } + for (final PluginContainer container : plugins) { final String id = container.getDescription().getId(); final ExecutorService service = (container).getExecutorService();