diff --git a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java index a4474052..ba9cd7c8 100644 --- a/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java +++ b/DuneRealms-minecraft-only/src/main/java/com/example/dunerealms/DuneCore.java @@ -556,14 +556,12 @@ public final class DuneCore extends JavaPlugin implements Listener, CommandExecu Bukkit.getScheduler().runTask(this, () -> giveMenuItem(p)); if (!selected.containsKey(p.getUniqueId()) || selected.get(p.getUniqueId()).isEmpty()) { p.sendMessage(ChatColor.GOLD + "Choose your faction with /dune choose ."); - if (p.getWorld().getName().equals("world")) Bukkit.getScheduler().runTask(this, () -> { - World localWorld = Bukkit.getWorld(localPlanet()); - if (p.isOnline() && localWorld != null && p.getWorld().getName().equals("world")) { - p.teleport(localWorld.getSpawnLocation()); - } - }); - } else Bukkit.getScheduler().runTask(this, () -> { - if (p.getWorld().getName().equals("world")) teleport(p, planets[Arrays.asList(factions).indexOf(selected.get(p.getUniqueId()))]); + } + Bukkit.getScheduler().runTask(this, () -> { + World localWorld = Bukkit.getWorld(localPlanet()); + if (p.isOnline() && localWorld != null && p.getWorld().getName().equalsIgnoreCase("world")) { + p.teleport(localWorld.getSpawnLocation()); + } }); } @EventHandler public void onRespawn(PlayerRespawnEvent e) { diff --git a/DuneTerrain/README.md b/DuneTerrain/README.md index 87ccbba1..33518155 100644 --- a/DuneTerrain/README.md +++ b/DuneTerrain/README.md @@ -16,6 +16,16 @@ Valid values are `arrakis`, `giedi_prime`, `kaitain`, `caladan`, and `sigma_drac Install DuneCore alongside DuneTerrain if you want the Guild navigator to open DuneCore's travel menu. DuneCore reads the loaded planet world to identify its local backend. For proxy travel, set `network.local-planet` and `network.servers` in DuneCore's config to match the DuneTerrain selection and proxy server names. -The generator applies when a world is first created and to chunks generated later. Existing chunks are never replaced by a config change. If the selected world already exists with non-Arrakis terrain, stop the server, back up and move that world's folder out of the server directory, then restart to create it with DuneTerrain. DuneTerrain logs a warning when it loads an existing world folder. +Paper's `paper-global.yml` and `paper-world-defaults.yml` do not choose terrain generators; Paper reads those for server and world behavior settings. Terrain generators are registered through `bukkit.yml`. DuneTerrain loads at startup and exposes its generator to Paper. If Arrakis is the primary world (`level-name=arrakis`), add this to `bukkit.yml`: -DuneCore sends new players who have not chosen a faction from Paper's default `world` to the local planet spawn, so they arrive in the world generated by DuneTerrain. +```yaml +worlds: + arrakis: + generator: DuneTerrain:arrakis +``` + +For another primary planet, replace both `arrakis` values with that planet name. When using DuneTerrain's separate planet world alongside a normal primary world named `world`, the plugin assigns the generator directly as it creates the planet world; no `bukkit.yml` entry is needed. + +The generator applies to newly generated chunks. Existing chunks are never replaced by a config change. If the selected planet world already exists with non-Arrakis terrain, stop the server, back up and move that world's folder out of the server directory, then restart to create it with DuneTerrain. DuneTerrain reports whether it found the world already loaded with its generator. + +DuneCore sends players joining Paper's default `world` to the configured local planet spawn, whether or not they have already chosen a faction. diff --git a/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java b/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java index 3b8f1bc9..043d22d2 100644 --- a/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java +++ b/DuneTerrain/src/main/java/com/example/duneterrain/DuneTerrain.java @@ -8,12 +8,29 @@ import org.bukkit.generator.*; import org.bukkit.persistence.PersistentDataType; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; +import java.io.File; import java.util.*; public final class DuneTerrain extends JavaPlugin { private static final String[] PLANETS = {"arrakis", "giedi_prime", "kaitain", "caladan", "sigma_draconis_iv"}; private NamespacedKey guildKey; + @Override public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { + String planet = id == null || id.isBlank() + ? getConfig().getString("server.planet", "arrakis") + : id; + planet = planet.toLowerCase(Locale.ROOT); + if (!Arrays.asList(PLANETS).contains(planet)) { + getLogger().severe("Invalid generator planet '" + planet + "' for world '" + worldName + "'."); + return null; + } + if (!getConfig().getBoolean("planets." + planet + ".enabled", true)) { + getLogger().severe("Generator planet '" + planet + "' is disabled in config.yml."); + return null; + } + return new PlanetChunkGenerator(this, planet); + } + @Override public void onEnable() { saveDefaultConfig(); guildKey = new NamespacedKey("dunerealms", "guild"); @@ -28,6 +45,7 @@ public final class DuneTerrain extends JavaPlugin { getServer().getPluginManager().disablePlugin(this); return; } + World preloadedWorld = Bukkit.getWorld(planet); File worldFolder = new File(getServer().getWorldContainer(), planet); boolean existingWorld = worldFolder.isDirectory(); World world = Bukkit.createWorld(new WorldCreator(planet) @@ -41,7 +59,11 @@ public final class DuneTerrain extends JavaPlugin { world.setGameRule(GameRule.DO_DAYLIGHT_CYCLE, !planet.equals("arrakis")); world.setTime(planet.equals("giedi_prime") ? 18000 : 6000); setupPlanetSpawn(world, planet); - if (existingWorld) { + if (preloadedWorld != null && !(preloadedWorld.getGenerator() instanceof PlanetChunkGenerator)) { + getLogger().severe("World '" + planet + "' was loaded without DuneTerrain's generator. To use Arrakis as the primary Paper world, configure bukkit.yml with worlds." + planet + ".generator: DuneTerrain:" + planet + ", then back up and move the existing world folder so its chunks regenerate."); + } else if (preloadedWorld != null) { + getLogger().info("World '" + planet + "' was loaded with DuneTerrain's configured generator."); + } else if (existingWorld) { getLogger().warning("Loaded existing world '" + planet + "'. DuneTerrain only generates new chunks; existing terrain will remain unchanged. Back up and move the world folder, then restart, to regenerate it."); } else { getLogger().info("Created world '" + planet + "' with DuneTerrain."); diff --git a/DuneTerrain/src/main/resources/config.yml b/DuneTerrain/src/main/resources/config.yml index 04b6d815..a4c078f7 100644 --- a/DuneTerrain/src/main/resources/config.yml +++ b/DuneTerrain/src/main/resources/config.yml @@ -1,4 +1,6 @@ -# Set this separately on each Paper backend. +# Set this separately on each Paper backend. Keep server.properties level-name +# different from this planet so Paper does not load the world before this plugin +# can assign its custom generator. # Accepted values: arrakis, giedi_prime, kaitain, caladan, sigma_draconis_iv server: planet: arrakis diff --git a/DuneTerrain/src/main/resources/plugin.yml b/DuneTerrain/src/main/resources/plugin.yml index 0e884836..0f9bcde4 100644 --- a/DuneTerrain/src/main/resources/plugin.yml +++ b/DuneTerrain/src/main/resources/plugin.yml @@ -2,4 +2,5 @@ name: DuneTerrain version: 1.0.0 main: com.example.duneterrain.DuneTerrain api-version: '1.21' +load: STARTUP description: Configurable Dune planet terrain and spawn generator for Paper