Fix watchdog, add negative y support. (#1782)

This commit is contained in:
wizjany 2021-06-13 15:40:19 -04:00 committed by GitHub
parent 043c3315aa
commit a57f66f7cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -125,7 +125,7 @@ public int schedule(long delay, long period, Runnable task) {
@Override
public Watchdog getWatchdog() {
return watchdog.valueOrThrow();
return watchdog.value().orElse(null);
}
@Override

View File

@ -59,6 +59,8 @@
import org.bukkit.inventory.InventoryHolder;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.EnumMap;
@ -76,6 +78,9 @@ public class BukkitWorld extends AbstractWorld {
private static final Logger LOGGER = LogManagerCompat.getLogger();
private static final boolean HAS_3D_BIOMES;
private static final boolean HAS_MIN_Y;
private static final Method GET_MIN_Y;
private int minY;
private static final Map<Integer, Effect> effects = new HashMap<>();
@ -94,6 +99,16 @@ public class BukkitWorld extends AbstractWorld {
temp = false;
}
HAS_3D_BIOMES = temp;
Method tempGetMinY;
try {
tempGetMinY = World.class.getMethod("getMinHeight");
temp = true;
} catch (NoSuchMethodException e) {
tempGetMinY = null;
temp = false;
}
GET_MIN_Y = tempGetMinY;
HAS_MIN_Y = temp;
}
private final WeakReference<World> worldRef;
@ -112,6 +127,13 @@ public BukkitWorld(World world) {
} else {
this.worldNativeAccess = null;
}
if (HAS_MIN_Y) {
try {
minY = (int) GET_MIN_Y.invoke(world);
} catch (IllegalAccessException | InvocationTargetException e) {
minY = super.getMinY();
}
}
}
@Override
@ -350,6 +372,15 @@ public int getMaxY() {
return getWorld().getMaxHeight() - 1;
}
@Override
public int getMinY() {
/*if (HAS_MIN_Y) {
return getWorld().getMinHeight();
}
return super.getMinY();*/
return minY;
}
@SuppressWarnings("deprecation")
@Override
public void fixAfterFastMode(Iterable<BlockVector2> chunks) {