Interface WorldManager


public interface WorldManager
The worlds of the server: loading, creating and unloading them, and what they share (base game rules, datapack structures).
Since:
0.1.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Collection<? extends World>
    all()
    Gets the worlds currently loaded.
    Creates a new world from the given specification.
    default World
    create(Key key, WorldGenerator generator)
    Creates a new world driven by the given generator, with a seed of 0.
    Returns the key of the world currently preferred as the server's default, or Optional.empty() if none is configured.
    void
    Sets the world that should be preferred as the server's default when resolving a fallback world for players and commands with no other context.
    The base game rules of the server: the overworld's, which every world follows unless it overrides them through World.gameRules().
    default Optional<? extends World>
    get(Key key)
    Looks up a loaded world.
    Datapack structures: packs of <world>/datapacks, templates, jigsaw structures, placement and /locate-style search.
    boolean
    unload(Key key, boolean save)
    Unloads the world identified by key, optionally saving it to disk first.
  • Method Details

    • all

      Collection<? extends World> all()
      Gets the worlds currently loaded.
      Returns:
      the loaded worlds
      Since:
      0.1.0
    • get

      default Optional<? extends World> get(Key key)
      Looks up a loaded world.
      Parameters:
      key - the world key
      Returns:
      the world, or empty if no world is loaded under that key
      Since:
      0.1.0
    • create

      @Contract(mutates="this") World create(WorldSpec spec)
      Creates a new world from the given specification.

      If a world is already registered under the spec's key, that existing world is returned unchanged and the rest of the spec (seed, generator) is ignored; this call is therefore idempotent with respect to the world key. Otherwise a new world is registered using the spec's generator, or the server's built-in default generator when the spec supplies none.

      The returned world is immediately usable: it participates in ticking and its chunks are generated on demand through the configured generator.

      Parameters:
      spec - the description of the world to create
      Returns:
      the newly created world, or the existing world sharing the same key
      Since:
      0.1.0
    • create

      @Contract(mutates="this") default World create(Key key, WorldGenerator generator)
      Creates a new world driven by the given generator, with a seed of 0.
      Parameters:
      key - the world key
      generator - the chunk generator to drive the new world
      Returns:
      the newly created world, or the existing world sharing the same key
      Since:
      0.1.0
      See Also:
    • unload

      @Contract(mutates="this") boolean unload(Key key, boolean save)
      Unloads the world identified by key, optionally saving it to disk first.

      Unloading removes the world from all() and stops it being ticked; entities it held are released. The call is refused, returning false without side effects, when:

      • no world is registered under key;
      • the world is the only one currently loaded; at least one world must always remain; or
      • players are still present in the world; relocate them with another world first.
      Parameters:
      key - the key of the world to unload
      save - whether to save the world before unloading it
      Returns:
      true if the world was unloaded, false if the call was refused
      Since:
      0.1.0
    • defaultWorld

      @Contract(pure=true) Optional<Key> defaultWorld()
      Returns the key of the world currently preferred as the server's default, or Optional.empty() if none is configured.
      Returns:
      the key of the world currently preferred as the server's default, or Optional.empty() if none is configured
      Since:
      0.1.0
    • defaultWorld

      @Contract(mutates="this") void defaultWorld(@Nullable Key key)
      Sets the world that should be preferred as the server's default when resolving a fallback world for players and commands with no other context.
      Parameters:
      key - the key of the preferred world, or null to clear the preference
      Since:
      0.1.0
    • gameRules

      GameRules gameRules()
      The base game rules of the server: the overworld's, which every world follows unless it overrides them through World.gameRules().
      Returns:
      the base game rules, as changed by /gamerule <rule> <value>
      Since:
      0.1.0
    • structures

      StructureManager structures()
      Datapack structures: packs of <world>/datapacks, templates, jigsaw structures, placement and /locate-style search.
      Returns:
      the structure manager of the server
      Since:
      0.1.0