Skip to content

Commit

Permalink
Use world methods for min/max height
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed May 6, 2022
1 parent 54aa3a2 commit ffe8ea4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Expand Up @@ -44,7 +44,7 @@ protected CachingChunkBlockSource(World world, int minX, int minZ, int maxX, int

@Override
public BoundingBox getCollisionBox(int x, int y, int z) {
if (y > SpigotUtil.getMaxBlockY()) {
if (!SpigotUtil.checkYSafe(y, world)) {
return BoundingBox.EMPTY;
}
T chunk = getSpecific(x, z);
Expand All @@ -67,7 +67,7 @@ public BoundingBox getCollisionBox(int x, int y, int z) {

@Override
public Material getMaterialAt(int x, int y, int z) {
if (y > SpigotUtil.getMaxBlockY()) {
if (!SpigotUtil.checkYSafe(y, world)) {
return Material.AIR;
}
T chunk = getSpecific(x, z);
Expand Down
Expand Up @@ -49,7 +49,7 @@ private boolean isClimbable(Material mat) {
@Override
public PassableState isPassable(BlockSource source, PathPoint point) {
Vector pos = point.getVector();
if (pos.getBlockY() <= SpigotUtil.getMinBlockY() || pos.getBlockY() >= SpigotUtil.getMaxBlockY()) {
if (!SpigotUtil.checkYSafe(pos.getBlockY(), source.getWorld())) {
return PassableState.UNPASSABLE;
}
Material above = source.getMaterialAt(pos.getBlockX(), pos.getBlockY() + 1, pos.getBlockZ());
Expand Down
Expand Up @@ -121,7 +121,7 @@ public List<PathPoint> getNeighbours(BlockSource source, PathPoint point) {
if (x == 0 && y == 0 && z == 0)
continue;
int modY = location.getBlockY() + y;
if (modY <= SpigotUtil.getMinBlockY() || modY > SpigotUtil.getMaxBlockY()) {
if (!SpigotUtil.checkYSafe(modY, source.getWorld())) {
continue;
}
Vector mod = new Vector(location.getX() + x, modY, location.getZ() + z);
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/net/citizensnpcs/api/util/SpigotUtil.java
@@ -1,23 +1,27 @@
package net.citizensnpcs.api.util;

import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;

public class SpigotUtil {
public static int getMaxBlockY() {
return 255;
public static boolean checkYSafe(double y, World world) {
if (!SUPPORT_WORLD_HEIGHT || world == null) {
return y >= 0 && y <= 255;
}
try {
return y >= world.getMinHeight() && y <= world.getMaxHeight();
} catch (Throwable t) {
SUPPORT_WORLD_HEIGHT = false;
return y >= 0 && y <= 255;
}
}

public static int getMaxNameLength(EntityType type) {
return isUsing1_13API() ? 256 : 64;
}

public static int getMinBlockY() {
int[] version = getVersion();
return version[0] >= 1 && version[1] >= 18 ? -64 : 0;
}

private static int[] getVersion() {
if (BUKKIT_VERSION == null) {
String version = Bukkit.getVersion();
Expand Down Expand Up @@ -45,5 +49,6 @@ public static boolean isUsing1_13API() {
}

private static int[] BUKKIT_VERSION = null;
private static boolean SUPPORT_WORLD_HEIGHT = true;
private static Boolean using1_13API;
}

0 comments on commit ffe8ea4

Please sign in to comment.