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.Listener;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
|
||||||
public class Bbsdfia extends JavaPlugin implements Listener {
|
public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
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 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
|
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
|
// Schedule the logic to be run asynchronously after 1 tick
|
||||||
dummyVel.add(new Vector(0, 0.3, 0));
|
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;
|
double absMax = 0, max = 0;
|
||||||
char dir = ' ';
|
char dir = ' ';
|
||||||
Block relative = null;
|
Block relative = 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue