Use a temporary executor until the bukkit one has started
This commit is contained in:
parent
a99609e016
commit
41362aa34a
@ -68,6 +68,8 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@ -96,8 +98,14 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
private boolean started = false;
|
private boolean started = false;
|
||||||
private DebugHandler debugHandler;
|
private DebugHandler debugHandler;
|
||||||
|
|
||||||
|
private ExecutorService executorService;
|
||||||
|
private boolean schedulerAvailable = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
// Used whilst the server is still starting
|
||||||
|
executorService = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
log = LogFactory.wrap(getLogger());
|
log = LogFactory.wrap(getLogger());
|
||||||
debugHandler = new DebugHandler();
|
debugHandler = new DebugHandler();
|
||||||
|
|
||||||
@ -227,6 +235,12 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
getServer().getOperators().forEach(o -> o.setOp(false));
|
getServer().getOperators().forEach(o -> o.setOp(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shutdown the temporary executor when the Bukkit one starts
|
||||||
|
doAsync(() -> {
|
||||||
|
schedulerAvailable = true;
|
||||||
|
executorService.shutdown();
|
||||||
|
});
|
||||||
|
|
||||||
started = true;
|
started = true;
|
||||||
getLog().info("Successfully loaded.");
|
getLog().info("Successfully loaded.");
|
||||||
}
|
}
|
||||||
@ -253,7 +267,11 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doAsync(Runnable r) {
|
public void doAsync(Runnable r) {
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, r);
|
if (!schedulerAvailable) {
|
||||||
|
executorService.submit(r);
|
||||||
|
} else {
|
||||||
|
getServer().getScheduler().runTaskAsynchronously(this, r);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user