Scheduler
This commit is contained in:
parent
e12f798f11
commit
6a43007a49
2 changed files with 20 additions and 38 deletions
|
|
@ -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,6 +40,11 @@ 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
|
||||
|
||||
|
||||
// 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());
|
||||
|
|
@ -48,8 +55,13 @@ public class Bbsdfia extends JavaPlugin implements Listener {
|
|||
|
||||
dummy.setVelocity(dummyVel);
|
||||
}
|
||||
}.runTask(this));
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue