/
minecraftbackup
/
AnarchyExploitFixes
Обзор
Документация
Войти
/
minecraftbackup
/
AnarchyExploitFixes
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/utils/WorldUtil.java
64 строки
3 KB
Ginko
2.7.2 release (#233)
13 авг 2024, 08:21
Не верифицирован
13 авг 2024, 08:21
d20da6e
Код
Авторство
О чём код?
package me.xginko.aef.utils; import me.xginko.aef.AnarchyExploitFixes; import org.bukkit.World; import java.lang.invoke.MethodHandle; public class WorldUtil { private static final MethodHandle GET_MIN_WORLD_HEIGHT, RESPAWNANCHOR_WORKS, BED_WORKS; public static final boolean GET_MIN_WORLD_HEIGHT_AVAILABLE, RESPAWN_ANCHOR_WORKS_AVAILABLE, BED_WORKS_AVAILABLE; static { GET_MIN_WORLD_HEIGHT_AVAILABLE = Crafty.hasMethod(World.class, "getMinHeight"); GET_MIN_WORLD_HEIGHT = Crafty.findMethod(World.class, "getMinHeight", int.class); RESPAWN_ANCHOR_WORKS_AVAILABLE = Crafty.hasMethod(World.class, "isRespawnAnchorWorks"); RESPAWNANCHOR_WORKS = Crafty.findMethod(World.class, "isRespawnAnchorWorks", boolean.class); BED_WORKS_AVAILABLE = Crafty.hasMethod(World.class, "isBedWorks"); BED_WORKS = Crafty.findMethod(World.class, "isBedWorks", boolean.class); } public static int getMinWorldHeight(World world) { if (!GET_MIN_WORLD_HEIGHT_AVAILABLE) { return AnarchyExploitFixes.config().worldMinHeights.getOrDefault(world.getName(), getDefaultMinHeight(world)); } try { return (int) GET_MIN_WORLD_HEIGHT.invoke(world); } catch (Throwable t) { AnarchyExploitFixes.prefixedLogger().error("Error getting min world height from world '{}'.", world.getName(), t); return AnarchyExploitFixes.config().worldMinHeights.getOrDefault(world.getName(), getDefaultMinHeight(world)); } } private static int getDefaultMinHeight(World world) { return world.getEnvironment() == World.Environment.NORMAL && PlatformUtil.getMinecraftVersion() > 17 ? -64 : 0; } public static boolean isRespawnAnchorWorks(World world) { if (!RESPAWN_ANCHOR_WORKS_AVAILABLE) { return world.getEnvironment() != World.Environment.NORMAL; } try { return (boolean) RESPAWNANCHOR_WORKS.invoke(world); } catch (Throwable t) { AnarchyExploitFixes.prefixedLogger().error("Error checking if respawn anchors work in world '{}'.", world.getName(), t); return world.getEnvironment() != World.Environment.NORMAL; } } public static boolean isBedWorks(World world) { if (!BED_WORKS_AVAILABLE) { return world.getEnvironment() == World.Environment.NORMAL; } try { return (boolean) BED_WORKS.invoke(world); } catch (Throwable t) { AnarchyExploitFixes.prefixedLogger().error("Error checking if beds work in world '{}'.", world.getName(), t); return world.getEnvironment() == World.Environment.NORMAL; } } }