diff --git a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java index 075cf14..6b8f528 100644 --- a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java +++ b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java @@ -10,8 +10,10 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; + public class Bbsdfia extends JavaPlugin implements Listener { @Override public void onEnable() { @@ -38,22 +40,32 @@ public class Bbsdfia extends JavaPlugin implements Listener { Location obsidianPlatformCenter = new Location(movingTo.getWorld(), 100, 50, 0); // change coordinates to the center of the obsidian platform in the end dimension Location spawnLoc = obsidianPlatformCenter.clone().add(0, 1, 0); // spawn the new falling block entity one block above the obsidian platform - FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); - Vector dummyVel = vel.clone(); - dummyVel.setY(-dummyVel.getY()); - dummyVel.multiply(new Vector(2, 2, 2)); // double the velocity - // add a constant downward velocity to simulate gravity - dummyVel.add(new Vector(0, 0.3, 0)); + // Schedule the logic to be run asynchronously after 1 tick + getServer().getAsyncScheduler().runNow(this, scheduledTask -> new BukkitRunnable() { + @Override + public void run() { + FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); + Vector dummyVel = vel.clone(); + dummyVel.setY(-dummyVel.getY()); + dummyVel.multiply(new Vector(2, 2, 2)); // double the velocity + + // add a constant downward velocity to simulate gravity + dummyVel.add(new Vector(0, 0.3, 0)); + + dummy.setVelocity(dummyVel); + } + }.runTask(this)); + - dummy.setVelocity(dummyVel); } } } - Block getBlockMovingTo(Location loc, Vector vel){ + + Block getBlockMovingTo(Location loc, Vector vel){ double absMax = 0, max = 0; char dir = ' '; Block relative = null; diff --git a/src/main/java/xyz/hynse/bbsdfia/Compatibility.java b/src/main/java/xyz/hynse/bbsdfia/Compatibility.java deleted file mode 100644 index dc4ac48..0000000 --- a/src/main/java/xyz/hynse/bbsdfia/Compatibility.java +++ /dev/null @@ -1,30 +0,0 @@ -package xyz.hynse.bbsdfia; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; - -public class Compatibility { - - public static Boolean IS_FOLIA = null; - - private static boolean methodExist(Class clazz, String methodName, Class... parameterTypes) { - try { - clazz.getDeclaredMethod(methodName, parameterTypes); - return true; - } catch (Throwable ignored) {} - return false; - } - - public static Boolean isFolia() { - if (IS_FOLIA == null) IS_FOLIA = methodExist(Bukkit.class, "getGlobalRegionScheduler"); - return IS_FOLIA; - } - - public static void runTaskAsync(Plugin plugin, Runnable runnable) { - if (isFolia()) { - Bukkit.getAsyncScheduler().runNow(plugin, (task) -> runnable.run()); - return; - } - Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable); - } -} \ No newline at end of file