From 5780f1a4a60edce7f25aa92b53dd0866c1db70c0 Mon Sep 17 00:00:00 2001 From: Allink <44676012+allinkdev@users.noreply.github.com> Date: Mon, 18 Jul 2022 18:32:19 +0100 Subject: [PATCH] OOB Random Spawn Fix (#316) * Add warning for "randomizeSpawn" option about the speed of chunk generation * Limit random spawn to half a million blocks, which should hopefully fix the OOB error * Recommend users to use Chunky for pre-world generation * Add missing period * Fix checkstyle violation --- .../extras/modules/player/PlayerConnection.java | 14 +++++++++----- src/main/resources/config.yml | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java index 96448b8..4472a70 100644 --- a/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java +++ b/src/main/java/pw/kaboom/extras/modules/player/PlayerConnection.java @@ -31,7 +31,6 @@ import pw.kaboom.extras.modules.server.ServerTabComplete; public final class PlayerConnection implements Listener { private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig(); - private static final String TITLE = CONFIG.getString("playerJoinTitle"); private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle"); private static final int FADE_IN = 10; @@ -128,11 +127,16 @@ public final class PlayerConnection implements Listener { if (RANDOMIZE_SPAWN && event.getPlayer().getBedSpawnLocation() != event.getSpawnLocation()) { final World world = event.getPlayer().getWorld(); - final double x = ThreadLocalRandom.current().nextInt(-300000000, 30000000) + .5; - final double y = 100; - final double z = ThreadLocalRandom.current().nextInt(-300000000, 30000000) + .5; + final ThreadLocalRandom random = ThreadLocalRandom.current(); - event.setSpawnLocation(new Location(world, x, y, z)); + final double teleportAmount = 500000D; + final Location location = new Location( + world, + random.nextDouble(-teleportAmount, teleportAmount), + 100, + random.nextDouble(-teleportAmount, teleportAmount) + ); + event.setSpawnLocation(location); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2fc19bb..b26129a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,6 +3,10 @@ allowJoinOnFullServer: true enableKick: false enableJoinRestrictions: false opOnJoin: true +# It's recommended to do this on a pre-generated world +# as chunk generation can be very slow in newer Minecraft +# versions. +# You can use the pre-world generation plugin "Chunky" to achieve this. randomizeSpawn: false maxEntitiesPerChunk: 50 maxEntitiesPerWorld: 5120