commit
a21172ae28
2 changed files with 32 additions and 3 deletions
28
src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java
Normal file
28
src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package xyz.hynse.foliaflow.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class SchedulerUtil {
|
||||
|
||||
private static Boolean IS_FOLIA = null;
|
||||
|
||||
private static boolean tryFolia() {
|
||||
try {
|
||||
Bukkit.getAsyncScheduler();
|
||||
return true;
|
||||
} catch (Throwable ignored) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Boolean isFolia() {
|
||||
if (IS_FOLIA == null) IS_FOLIA = tryFolia();
|
||||
return IS_FOLIA;
|
||||
}
|
||||
|
||||
public static void runLaterEntity(Entity entity, Plugin plugin, Runnable runnable, int ticks) {
|
||||
if (isFolia()) entity.getScheduler().runDelayed(plugin, (task) -> runnable.run(), null, ticks);
|
||||
else Bukkit.getScheduler().runTaskLater(plugin, runnable, ticks);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,9 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import xyz.hynse.foliaflow.FoliaFlow;
|
||||
import xyz.hynse.foliaflow.util.SchedulerUtil;
|
||||
|
||||
import static xyz.hynse.foliaflow.util.VelocityUtil.getBlockMovingTo;
|
||||
|
||||
|
|
@ -35,9 +37,8 @@ public class PortalWatcher implements Listener {
|
|||
dummy.setVelocity(dummyVel);
|
||||
|
||||
// Add vector seems vanilla.
|
||||
dummy.getScheduler().runDelayed(FoliaFlow.instance,
|
||||
task -> dummy.setVelocity(dummyVel.add(new Vector(0, 0.45, 0))),
|
||||
null,
|
||||
SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance,
|
||||
() -> dummy.setVelocity(dummyVel.add(new Vector(0, 0.45, 0))),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue