diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java index d64a3232..e4b6d330 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/config/Config.java @@ -5,11 +5,13 @@ import io.github.thatsmusic99.configurationmaster.api.ConfigSection; import me.xginko.aef.AnarchyExploitFixes; import me.xginko.aef.utils.PlatformUtil; +import me.xginko.aef.utils.WorldUtil; import org.bukkit.ChatColor; import org.bukkit.Sound; import java.io.File; import java.time.Duration; +import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -17,12 +19,13 @@ public class Config { private final ConfigFile config; + public final Map worldMinHeights; public final Locale default_lang; public final String cmd_say_format; public final Sound elytra_too_fast_sound; public final Duration tps_cache_duration; public final long elytra_speed_calc_period_millis, elytra_old_chunk_limit; - public final int nether_ceiling_max_y, nether_floor_min_y, overworld_floor_min_y, elytra_spawn_radius; + public final int nether_ceiling_max_y, elytra_spawn_radius; public final boolean auto_lang, packets_disabled, connectionMsgsAreOnByDefault, cmd_say_enabled, cmd_help_enabled, cmd_toggleConMsgs_enabled, elytra_enable_at_spawn, elytra_enable_global, elytra_enable_netherceiling, @@ -51,15 +54,30 @@ public Config() throws Exception { "by the plugin.")) * 50L); this.packets_disabled = getBoolean("general.disable-all-packet-listeners", false, "In case packet modules are causing trouble, you can disable them here."); + this.nether_ceiling_max_y = getInt("general.nether-ceiling-y", 127, "The Y-level at which the nether ceiling generates the last layer\n" + "of bedrock on your server."); - this.nether_floor_min_y = getInt("general.nether-floor-y", 0, - "The Y-level at which the nether floor generates the last layer\n" + - "of bedrock on your server."); - this.overworld_floor_min_y = getInt("general.overworld-floor-y", PlatformUtil.getMinecraftVersion() > 17 ? -64 : 0, - "The Y-level at which the overworld floor generates the last layer\n" + - "of bedrock on your server."); + this.worldMinHeights = new HashMap<>(); + Map defaults = new HashMap<>(); + if (!WorldUtil.GET_MIN_WORLD_HEIGHT_AVAILABLE) { + defaults.put("world", PlatformUtil.getMinecraftVersion() > 17 ? -64 : 0); + defaults.put("world_nether", 0); + defaults.put("world_the_end", 0); + ConfigSection worldMinHeights = getConfigSection("general.world-min-heights", defaults, + "If you see this config option, AEF is unable to get the minimum height\n" + + "of your worlds from the API.\n" + + "Please enter them here manually for each world you're currently using.\n" + + "Use the exact same name as your world folder."); + for (String worldName : worldMinHeights.getKeys(false)) { + try { + worldMinHeights.put(worldName, Integer.parseInt(worldMinHeights.getString(worldName))); + } catch (NumberFormatException e) { + AnarchyExploitFixes.prefixedLogger().warn("Could not parse min height for world '{}'", worldName); + } + } + } + this.cmd_say_enabled = getBoolean("general.commands.say.enable", false); this.cmd_say_format = ChatColor.translateAlternateColorCodes('&', getString("general.commands.say.format", "&7Server: &6%message%")); this.cmd_help_enabled = getBoolean("general.commands.help.enable", false, diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/utils/WorldUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/utils/WorldUtil.java index 785cce63..a1feb5df 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/utils/WorldUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/utils/WorldUtil.java @@ -8,7 +8,7 @@ public class WorldUtil { private static final MethodHandle GET_MIN_WORLD_HEIGHT, RESPAWNANCHOR_WORKS, BED_WORKS; - private static final boolean GET_MIN_WORLD_HEIGHT_AVAILABLE, RESPAWN_ANCHOR_WORKS_AVAILABLE, BED_WORKS_AVAILABLE; + 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"); @@ -21,23 +21,19 @@ public class WorldUtil { public static int getMinWorldHeight(World world) { if (!GET_MIN_WORLD_HEIGHT_AVAILABLE) { - return getMinWorldHeightFromConfig(world); + 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 getMinWorldHeightFromConfig(world); + return AnarchyExploitFixes.config().worldMinHeights.getOrDefault(world.getName(), getDefaultMinHeight(world)); } } - private static int getMinWorldHeightFromConfig(World world) { - if (world.getEnvironment() == World.Environment.NORMAL) { - return AnarchyExploitFixes.config().overworld_floor_min_y; - } else { - return AnarchyExploitFixes.config().nether_floor_min_y; - } + private static int getDefaultMinHeight(World world) { + return world.getEnvironment() == World.Environment.NORMAL && PlatformUtil.getMinecraftVersion() > 17 ? -64 : 0; } public static boolean isRespawnAnchorWorks(World world) {