Paper compatibility
This commit is contained in:
parent
758b5dc8fc
commit
c5f152fdbf
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.Listener;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import xyz.hynse.foliaflow.FoliaFlow;
|
import xyz.hynse.foliaflow.FoliaFlow;
|
||||||
|
import xyz.hynse.foliaflow.util.SchedulerUtil;
|
||||||
|
|
||||||
import static xyz.hynse.foliaflow.util.VelocityUtil.getBlockMovingTo;
|
import static xyz.hynse.foliaflow.util.VelocityUtil.getBlockMovingTo;
|
||||||
|
|
||||||
|
|
@ -35,9 +37,8 @@ public class PortalWatcher implements Listener {
|
||||||
dummy.setVelocity(dummyVel);
|
dummy.setVelocity(dummyVel);
|
||||||
|
|
||||||
// Add vector seems vanilla.
|
// Add vector seems vanilla.
|
||||||
dummy.getScheduler().runDelayed(FoliaFlow.instance,
|
SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance,
|
||||||
task -> dummy.setVelocity(dummyVel.add(new Vector(0, 0.45, 0))),
|
() -> dummy.setVelocity(dummyVel.add(new Vector(0, 0.45, 0))),
|
||||||
null,
|
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue