diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 6c4ffca86..b4345a354 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -112,6 +112,7 @@ public class VelocityServer implements ProxyServer { if (!configuration.validate()) { logger.error("Your configuration is invalid. Velocity will refuse to start up until the errors are resolved."); + LogManager.shutdown(); System.exit(1); } @@ -119,6 +120,7 @@ public class VelocityServer implements ProxyServer { } catch (IOException | RuntimeException e) { logger.error("Unable to load your velocity.toml. The server will shut down.", e); + LogManager.shutdown(); System.exit(1); } 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 e3e7b342a..6e10807e3 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/scheduler/VelocityScheduler.java @@ -12,7 +12,8 @@ import com.velocitypowered.api.scheduler.TaskStatus; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; import java.util.IdentityHashMap; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReference; @@ -21,8 +22,8 @@ public class VelocityScheduler implements Scheduler { private final PluginManager pluginManager; private final ExecutorService taskService; private final ScheduledExecutorService timerExecutionService; - private final Multimap tasksByPlugin = Multimaps.synchronizedListMultimap( - Multimaps.newListMultimap(new IdentityHashMap<>(), ArrayList::new)); + private final Multimap tasksByPlugin = Multimaps.synchronizedMultimap( + Multimaps.newSetMultimap(new IdentityHashMap<>(), HashSet::new)); public VelocityScheduler(PluginManager pluginManager) { this.pluginManager = pluginManager; @@ -41,7 +42,11 @@ public class VelocityScheduler implements Scheduler { } public boolean shutdown() throws InterruptedException { - for (ScheduledTask task : ImmutableList.copyOf(tasksByPlugin.values())) { + Collection terminating; + synchronized (tasksByPlugin) { + terminating = ImmutableList.copyOf(tasksByPlugin.values()); + } + for (ScheduledTask task : terminating) { task.cancel(); } timerExecutionService.shutdown();