This commit is contained in:
MidnightTale 2023-04-08 09:15:14 +07:00
commit a5f969edb2
3 changed files with 37 additions and 8 deletions

View file

@ -18,7 +18,7 @@ repositories {
} }
dependencies { dependencies {
compileOnly "io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT" compileOnly "dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT"
} }
def targetJavaVersion = 17 def targetJavaVersion = 17

View file

@ -27,18 +27,16 @@ public class Bbsdfia extends JavaPlugin implements Listener {
} }
@EventHandler @EventHandler
public void onFallingBlockToBlock(EntityChangeBlockEvent e){ public void onFallingBlockToBlock(EntityChangeBlockEvent e) {
if(e.getEntityType() == EntityType.FALLING_BLOCK){ if (e.getEntityType() == EntityType.FALLING_BLOCK) {
Entity entity = e.getEntity(); Entity entity = e.getEntity();
Location loc = entity.getLocation(); Location loc = entity.getLocation();
Vector vel = entity.getVelocity(); Vector vel = entity.getVelocity();
Block movingTo = getBlockMovingTo(loc, vel); Block movingTo = getBlockMovingTo(loc, vel);
if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ if (movingTo != null && movingTo.getType() == Material.END_PORTAL) {
Location spawnLoc = movingTo.getLocation(); Location obsidianPlatformCenter = new Location(movingTo.getWorld(), 100, 50, 0); // change coordinates to the center of the obsidian platform in the end dimension
spawnLoc.setX(spawnLoc.getX()+0.5); Location spawnLoc = obsidianPlatformCenter.clone().add(0, 1, 0); // spawn the new falling block entity one block above the obsidian platform
spawnLoc.setY(spawnLoc.getY()+0.5);
spawnLoc.setZ(spawnLoc.getZ()+0.5);
FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData());
Vector dummyVel = vel.clone(); Vector dummyVel = vel.clone();
@ -54,6 +52,7 @@ public class Bbsdfia extends JavaPlugin implements Listener {
} }
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 = ' ';

View file

@ -0,0 +1,30 @@
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);
}
}