2023-04-29 18:42:04 +00:00
|
|
|
package lol.pyr.znpcsplus.util;
|
|
|
|
|
2023-05-10 17:06:14 +00:00
|
|
|
import lol.pyr.znpcsplus.ZNpcsPlus;
|
|
|
|
import lol.pyr.znpcsplus.reflection.Reflections;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
2023-04-29 18:42:04 +00:00
|
|
|
public class FoliaUtil {
|
2023-05-03 06:24:34 +00:00
|
|
|
private static final Boolean FOLIA = isFolia();
|
2023-04-29 18:42:04 +00:00
|
|
|
public static boolean isFolia() {
|
2023-05-03 06:24:34 +00:00
|
|
|
if (FOLIA != null) return FOLIA;
|
2023-04-29 18:42:04 +00:00
|
|
|
try {
|
|
|
|
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
|
|
|
return true;
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2023-05-10 17:06:14 +00:00
|
|
|
|
|
|
|
public static void teleport(Entity entity, Location location) {
|
|
|
|
if (!isFolia()) entity.teleport(location);
|
|
|
|
else try {
|
|
|
|
Reflections.FOLIA_TELEPORT_ASYNC.get().invoke(entity, location);
|
|
|
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
|
|
|
ZNpcsPlus.LOGGER.severe("Error while teleporting entity:");
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2023-04-29 18:42:04 +00:00
|
|
|
}
|