Skip to content

Commit

Permalink
better configuration for minimum world heights
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 8, 2024
1 parent ddefc8c commit fd66319
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,27 @@
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;

public class Config {

private final ConfigFile config;
public final Map<String, Integer> 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,
Expand Down Expand Up @@ -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<String, Object> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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) {
Expand Down

0 comments on commit fd66319

Please sign in to comment.