Merge pull request #13 from KaiijuMC/master

Paper compatibility
This commit is contained in:
Mid 2023-04-26 16:29:18 +07:00 • committed by GitHub
commit a21172ae28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 3 deletions

View 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);
}
}

View file

@ -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
);
}