From ecdcfb771d9ea69146eebc9c4195b4bdb1e374d6 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 6 Jul 2023 00:10:33 +0200 Subject: [PATCH 1/2] check if a plugin has an executor service --- .../loader/VelocityPluginContainer.java | 4 +++ .../proxy/scheduler/VelocityScheduler.java | 26 +++++++++++-------- 2 files changed, 19 insertions(+), 11 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 40b00df7c9..5e757708ef 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 ExecutorService getExecutorService() { 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 96d0b94d60..21adf52eb1 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java @@ -30,11 +30,8 @@ import com.velocitypowered.api.scheduler.Scheduler; import com.velocitypowered.api.scheduler.TaskStatus; import com.velocitypowered.proxy.plugin.loader.VelocityPluginContainer; -import java.util.Collection; -import java.util.HashSet; -import java.util.IdentityHashMap; -import java.util.Optional; -import java.util.Set; + +import java.util.*; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -116,17 +113,24 @@ public boolean shutdown() throws InterruptedException { 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(); From d76bfb27a8103a1666b340fa5c98c5be5c1f19d7 Mon Sep 17 00:00:00 2001 From: Aaron Date: Thu, 6 Jul 2023 00:20:52 +0200 Subject: [PATCH 2/2] checkstyle --- .../proxy/scheduler/VelocityScheduler.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 21adf52eb1..727832bd49 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java @@ -30,8 +30,14 @@ import com.velocitypowered.api.scheduler.Scheduler; import com.velocitypowered.api.scheduler.TaskStatus; import com.velocitypowered.proxy.plugin.loader.VelocityPluginContainer; - -import java.util.*; +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; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors;