From 41362aa34adef99a9a01e4d1e185c1f9d181dc81 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 29 Oct 2016 21:54:13 +0100 Subject: [PATCH] Use a temporary executor until the bukkit one has started --- .../luckperms/bukkit/LPBukkitPlugin.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index 5f39b207e..7d7dac339 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -68,6 +68,8 @@ import org.bukkit.plugin.java.JavaPlugin; import java.io.File; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.stream.Collectors; @Getter @@ -96,8 +98,14 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { private boolean started = false; private DebugHandler debugHandler; + private ExecutorService executorService; + private boolean schedulerAvailable = false; + @Override public void onEnable() { + // Used whilst the server is still starting + executorService = Executors.newCachedThreadPool(); + log = LogFactory.wrap(getLogger()); debugHandler = new DebugHandler(); @@ -227,6 +235,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { getServer().getOperators().forEach(o -> o.setOp(false)); } + // shutdown the temporary executor when the Bukkit one starts + doAsync(() -> { + schedulerAvailable = true; + executorService.shutdown(); + }); + started = true; getLog().info("Successfully loaded."); } @@ -253,7 +267,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { @Override public void doAsync(Runnable r) { - getServer().getScheduler().runTaskAsynchronously(this, r); + if (!schedulerAvailable) { + executorService.submit(r); + } else { + getServer().getScheduler().runTaskAsynchronously(this, r); + } } @Override