I get this message when trying to change the world time asynchronously
java.lang.IllegalStateException: TimeSkipEvent may only be triggered synchronously.
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:595) ~[patched_1.16.3.jar:git-Paper-253]
at org.bukkit.craftbukkit.v1_16_R2.CraftWorld.setFullTime(CraftWorld.java:948) ~[patched_1.16.3.jar:git-Paper-253]
at org.bukkit.craftbukkit.v1_16_R2.CraftWorld.setTime(CraftWorld.java:936) ~[patched_1.16.3.jar:git-Paper-253]
at ru.lmpx.lmpxserverkit.handlers.NightSkipHandler.lambda$onPlayerSleep$0(NightSkipHandler.java:29) ~[?:?]
at org.bukkit.craftbukkit.v1_16_R2.scheduler.CraftTask.run(CraftTask.java:99) ~[patched_1.16.3.jar:git-Paper-253]
at org.bukkit.craftbukkit.v1_16_R2.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:54) ~[patched_1.16.3.jar:git-Paper-253]
at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[patched_1.16.3.jar:git-Paper-253]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_271]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_271]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_271]
@EventHandler
public void onPlayerSleep(PlayerBedEnterEvent e) {
if (!(plugin.getConfig().getBoolean("skipNight.enable"))) return;
if (e.getBedEnterResult().equals(PlayerBedEnterEvent.BedEnterResult.OK)) {
if (plugin.getConfig().getBoolean("skipNight.instantSkip")) {
Bukkit.getWorld("world").setTime(0);
Bukkit.getWorld("world").setStorm(false);
} else {
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
while (Bukkit.getWorld("world").getTime() < 24000) {
Bukkit.getWorld("world").setTime(Bukkit.getWorld("world").getTime() + 10);
try {
Thread.sleep(10);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
});
}
}
}
What needs to be changed so that the asynchronous thread changes time without an IllegalStateException error?