diff --git a/CLAUDE.md b/CLAUDE.md index a76be29..d4ac58c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -50,7 +50,7 @@ Never hold the whole region in memory or load the seed world on a normal boot `generators/biomes/BiomeLayout` reads one dimension of a biomes file and answers "which chosen biome is at dx,dz from the middle" (null = the seed's own). It supports per-quarter lists, `rings`, random `patches`, and `blend` (noise that bends the edges). `AbstractSeedBiomeProvider` only adds the centres and the vanilla fallback. `biomes.yml` is the "original" style; `biomes/*.yml` are the others (`workshop/BiomeStyles` maps names to files). With `blend: 0` the original layout must stay exactly as it was, because existing areas depend on it. -`workshop/WorkshopManager` runs the one workshop: temporary worlds `/workshop` and `/workshop_nether` (folders inside the game world's folder, like seed worlds) made with the seed generator, peaceful, spawn limits 0. Its state (`workshop/Workshop`: seed, biomes file, source area, centres, the players inside and the game mode each had outside) is saved to `areas/workshop.yml` on every change and reloaded, with the worlds, in `onEnable`. `listeners/WorkshopListener` forces creative on entry, restores the game mode on exit, respawns in place, and sends players home if the workshop was discarded while they were offline (`areas/displaced.yml`). `/boxadmin areas edit` (`AdminAreasEditCommand`) holds the logic and can be typed; `WorkshopDialogs` is only the Paper dialog UI on top, and cannot be unit tested under MockBukkit. When the workshop overworld is made, `WorkshopManager.scan` searches the vanilla biomes (`reach/SpotFinder`), stores the candidates as unscored `Workshop.Spot`s, calls `setCentres` with all of them (spot 0 is always the starting centre; the others are kept `4 * area radius` from it so layouts do not overlap) and scores them one at a time with `reach/SpotScorer` (shared with the find command). The spot list is saved after each score and the scan resumes after a restart; the centres must be set again before the world is created or new chunks would get the wrong biomes. `/boxadmin areas spots` (`AdminAreasSpotsCommand`) lists them and `select` sets `Workshop.setCentre`, teleports, and `showCentre` sends a fake diamond block and a per-player `WorldBorder`. Still to build: structure logging and turning the workshop into an area without a restart, then the Nether and End spots. +`workshop/WorkshopManager` runs the one workshop: temporary worlds `/workshop` and `/workshop_nether` (folders inside the game world's folder, like seed worlds) made with the seed generator, peaceful, spawn limits 0. Its state (`workshop/Workshop`: seed, biomes file, source area, centres, the players inside and the game mode each had outside) is saved to `areas/workshop.yml` on every change and reloaded, with the worlds, in `onEnable`. `listeners/WorkshopListener` forces creative on entry, restores the game mode on exit, respawns in place, and sends players home if the workshop was discarded while they were offline (`areas/displaced.yml`). `/boxadmin areas edit` (`AdminAreasEditCommand`) holds the logic and can be typed; `WorkshopDialogs` is only the Paper dialog UI on top, and cannot be unit tested under MockBukkit. When the workshop overworld is made, `WorkshopManager.scan` searches the vanilla biomes (`reach/SpotFinder`), stores the candidates as unscored `Workshop.Spot`s, calls `setCentres` with all of them (spot 0 is always the starting centre; the others are kept `4 * area radius` from it so layouts do not overlap) and scores them one at a time with `reach/SpotScorer` (shared with the find command). The spot list is saved after each score and the scan resumes after a restart; the centres must be set again before the world is created or new chunks would get the wrong biomes. `/boxadmin areas spots` (`AdminAreasSpotsCommand`) lists them and `select` sets `Workshop.setCentre`, teleports, and `showCentre` sends a fake diamond block and a per-player `WorldBorder`. `/boxadmin areas make` (`AdminAreasMakeCommand`, `workshop/AreaMaker`) turns the workshop into a live area in two parts. `prepare` copies each dimension with `TemplateBuilder.buildAsync` (one column of chunks per callback, so the server keeps ticking; the blocking `build` is only for startup) into `areas/workshop-build/` and runs `reach/AreaCheck` on the result. `finish` writes `areas.yml`, calls `AreaManager.put` (new row, or the same row when replacing an area that has no boxes), moves the files into `areas//`, `Boxed.setLand`, `registerSeedGenerators`, makes the blueprint bundle, queues `BoxCleaner.clean` for the row when land was replaced, and `WorkshopManager.keepAs` unloads the workshop worlds with a save and renames their folders to the area's seed worlds. Nothing here may need a restart. Still to build: structure logging, then the Nether and End spots. ### Deleted boxes diff --git a/README.md b/README.md index 0c276b6..7c93150 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,8 @@ You can also do the same by hand: add the area to `areas.yml` and make a bluepri | `/boxadmin areas check ` | Plays out how a box grows in the area and reports where players get stuck. See [Checking that an area can be played](#checking-that-an-area-can-be-played). | | `boxadmin areas find [seed\|random] [radius]` | Console only. Looks through a seed for good places to start a box. See [Finding a good place to start](#finding-a-good-place-to-start). | | `/boxadmin areas edit` | Opens the area workshop, where a new area is tried out in a temporary world. See [The area workshop](#the-area-workshop). | +| `/boxadmin areas spots` | Shows the places the workshop found and picks the middle of the box. | +| `/boxadmin areas make [name]` | Makes the workshop into an area that players can use, without a restart. | Areas can be chained so that a player's box in one area has to reach a certain size before the next area is unlocked, and can be closed to new boxes: @@ -204,7 +206,7 @@ A good start does not mean the area can be finished. Run `/boxadmin areas check ### The area workshop -The workshop is a set of temporary worlds for trying out a seed and a biome style before they become an area. **It is not finished yet:** today it makes the worlds, finds good places to start and lets you pick one as the middle of the box. Placing structures and turning the result into an area are still to come. +The workshop is a set of temporary worlds for trying out a seed and a biome style before they become an area. It finds good places to start, lets you pick one as the middle of the box and shape the land, and then makes the area without a restart. **Not finished yet:** structures placed in the workshop are copied as blocks but are not recorded as structures, and the Nether is always taken from 0,0. Run `/boxadmin areas edit`. A dialog box asks for: @@ -244,6 +246,29 @@ The biome style is laid out around every place that was found, so each one looks The permission is `boxed.admin.areas.spots`. +#### Making the area + +When you are happy with the land, run `/boxadmin areas make`. A dialog box asks for the name of the area. Then: + +1. **The land is copied.** This takes about half a minute and the server keeps running. Progress is shown above the hotbar. +2. **The land is checked.** Boxed works out how far a box can grow in it, in the same way as `/boxadmin areas check`, and shows you the result, for example "The box grows to fill its land (size 320). 70 advancements earned for 415 points, 0 out of reach, 27 impossible". +3. **You confirm, or not.** Nothing has been made yet. If you say "Not yet" you are back in the workshop and can change things and try again. + +When you confirm, the area exists straight away and players can pick it. There is no restart. Boxed: + +* writes the area to `areas.yml` with its seed, `centre`, `nether-centre` and biome style, +* makes a blueprint bundle with the same name, copied from the first bundle, if there is not one already, +* sends everyone out of the workshop, and +* keeps the workshop's worlds as the seed worlds of the area, so `/boxadmin areas rebuild ` builds it again with everything you changed by hand. + +Anything you change after the land was copied is not in the area, so run `/boxadmin areas make` again if you change something. + +**Replacing an area.** Give the name of an area that already exists to replace its land. This is only allowed while no player has a box in it, because every box in an area must be the same. The area keeps its row, its structures file and its `requires` and `unlocks-next-at` settings. The default area can be replaced this way on a new server. + +From the console, type `boxadmin areas spots ` to pick the middle, `boxadmin areas make ` to copy and check the land, and `boxadmin areas make confirm` to make the area. + +The permission is `boxed.admin.areas.make`. + #### Coming back and discarding Run `/boxadmin areas edit` again to go back to it, go to its Nether, or discard it. Discarding sends everyone inside to their box (or to spawn if they have none) and deletes the temporary worlds. Players who were inside but offline are sent to their box when they next join. diff --git a/src/main/java/world/bentobox/boxed/Boxed.java b/src/main/java/world/bentobox/boxed/Boxed.java index b7473b5..e77ff91 100644 --- a/src/main/java/world/bentobox/boxed/Boxed.java +++ b/src/main/java/world/bentobox/boxed/Boxed.java @@ -158,14 +158,7 @@ private boolean loadSettings() { new File(getDataFolder(), AREAS_FOLDER + File.separator + "grid.yml"), settings.getSeed(), this::logError); } - String worldName = settings.getWorldName().toLowerCase(Locale.ENGLISH); - for (Area area : areas.getAreas()) { - generatorMaps.put(area.seedWorldName(worldName, false), new BoxedSeedChunkGenerator(this, - Environment.NORMAL, new SeedBiomeGenerator(this, area.biomes(), area.centreX(), area.centreZ()))); - generatorMaps.put(area.seedWorldName(worldName, true), new BoxedSeedChunkGenerator(this, - Environment.NETHER, new NetherSeedBiomeGenerator(this, area.biomes(), area.netherCentreX(), - area.netherCentreZ()))); - } + areas.getAreas().forEach(this::registerSeedGenerators); return true; } @@ -272,7 +265,7 @@ public void createWorlds() { * @param env environment * @return the template file for the area and environment */ - File getTemplateFile(Area area, Environment env) { + public File getTemplateFile(Area area, Environment env) { return new File(getAreaFolder(area), env.name().toLowerCase(Locale.ENGLISH) + ".bxt"); } @@ -294,9 +287,7 @@ private void loadTemplate(Area area, String worldName, Environment env, int seed String seedWorldName = area.seedWorldName(worldName, env == Environment.NETHER); File file = getTemplateFile(area, env); int size = worldGen.getSize(); - Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().enableComplexMapKeySerialization() - .disableHtmlEscaping().registerTypeAdapterFactory(new BentoboxTypeAdapterFactory(getPlugin())) - .create(); + Gson gson = templateGson(); Template template = openTemplate(file, gson, size, area.seed()); if (template == null) { log("Building " + what + " from its seed world. This only happens once..."); @@ -366,6 +357,58 @@ private void close(@Nullable Template template) { } } + /** + * Gives an area its land while the server is running. The land the area had before, if + * any, is closed. + * @param area area + * @param env environment + * @param file a finished template file + * @throws IOException if the file cannot be read + */ + public void setLand(Area area, Environment env, File file) throws IOException { + close(areas.setTemplate(area, env, readTemplate(file))); + } + + /** + * Closes the land of an area so that its files can be replaced. + * @param area area + */ + public void clearLand(Area area) { + areas.removeTemplates(area).forEach(this::close); + } + + /** + * @param file a template file + * @return the land in the file + * @throws IOException if the file cannot be read + */ + public Template readTemplate(File file) throws IOException { + return new Template(file, templateGson(), this::logError); + } + + /** + * @return gson that can read and write the blocks and entities of a template + */ + public Gson templateGson() { + return new GsonBuilder().excludeFieldsWithoutExposeAnnotation().enableComplexMapKeySerialization() + .disableHtmlEscaping().registerTypeAdapterFactory(new BentoboxTypeAdapterFactory(getPlugin())) + .create(); + } + + /** + * Makes the generators of an area's seed worlds known, so that world management plugins + * can load them and the area's land can be rebuilt later. + * @param area area + */ + public void registerSeedGenerators(Area area) { + String worldName = settings.getWorldName().toLowerCase(Locale.ENGLISH); + generatorMaps.put(area.seedWorldName(worldName, false), new BoxedSeedChunkGenerator(this, + Environment.NORMAL, new SeedBiomeGenerator(this, area.biomes(), area.centreX(), area.centreZ()))); + generatorMaps.put(area.seedWorldName(worldName, true), new BoxedSeedChunkGenerator(this, + Environment.NETHER, new NetherSeedBiomeGenerator(this, area.biomes(), area.netherCentreX(), + area.netherCentreZ()))); + } + /** * @return the cleaner that puts the land of deleted boxes back */ diff --git a/src/main/java/world/bentobox/boxed/areas/AreaManager.java b/src/main/java/world/bentobox/boxed/areas/AreaManager.java index 9b82cdb..1ef464e 100644 --- a/src/main/java/world/bentobox/boxed/areas/AreaManager.java +++ b/src/main/java/world/bentobox/boxed/areas/AreaManager.java @@ -42,7 +42,8 @@ public class AreaManager { private final Map areaByRow = new ConcurrentHashMap<>(); private final Map> templates = new ConcurrentHashMap<>(); private final Set pending = ConcurrentHashMap.newKeySet(); - private final Area defaultArea; + private final java.util.function.Consumer errorLog; + private Area defaultArea; /** * @param config the contents of areas.yml @@ -53,6 +54,7 @@ public class AreaManager { public AreaManager(YamlConfiguration config, File gridFile, long defaultSeed, java.util.function.Consumer errorLog) { this.gridFile = gridFile; + this.errorLog = errorLog; this.grid = YamlConfiguration.loadConfiguration(gridFile); ConfigurationSection section = config.getConfigurationSection("areas"); List ids = getIds(section, errorLog); @@ -184,6 +186,36 @@ public Area getArea(@Nullable String id) { return id == null ? null : areas.get(id); } + /** + * Adds an area while the server is running, or replaces the settings of one. A new area + * is given the next free row. An area that is replaced keeps its row. + * @param id name of the area + * @param seed world seed its land was generated from + * @param biomes name of its biomes file + * @param structures name of its structures file + * @param centre block x and z of the place in the overworld seed that is the middle of every box + * @param netherCentre the same for the Nether + * @return the area + */ + public Area put(String id, long seed, String biomes, String structures, int[] centre, int[] netherCentre) { + String path = ROWS + "." + id; + if (!grid.contains(path)) { + grid.set(path, nextFreeRow()); + save(errorLog); + } + Area old = areas.get(id); + Area area = new Area(id, seed, biomes, structures, grid.getInt(path), old == null || old.enabled(), + old == null ? null : old.requires(), old == null ? 0 : old.unlockSize(), centre[0], centre[1], + netherCentre[0], netherCentre[1]); + areas.put(id, area); + areaByRow.put(area.row(), area); + pending.remove(id); + if (area.isDefault()) { + defaultArea = area; + } + return area; + } + /** * Notes an area that has been added to the config but will not exist until the server * restarts. Boxes cannot be made in it until then. @@ -263,6 +295,16 @@ public Template getTemplate(Area area, Environment env) { return map == null ? null : map.get(env); } + /** + * Takes away the land of an area so that it can be closed and replaced. + * @param area area + * @return the land it had + */ + public List