Skip to content

Commit 4b8ed11

Browse files
committed
ServerWorldProperties.LoadOptions
1 parent 1d2d559 commit 4b8ed11

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.world.server;
26+
27+
import org.spongepowered.api.world.WorldType;
28+
import org.spongepowered.api.world.generation.ChunkGenerator;
29+
30+
public interface WorldArchetypeType {
31+
32+
WorldType worldType();
33+
34+
ChunkGenerator chunkGenerator();
35+
36+
interface Builder extends org.spongepowered.api.util.Builder<WorldArchetypeType, Builder> {
37+
38+
Builder worldType(WorldType worldType);
39+
40+
Builder chunkGenerator(ChunkGenerator chunkGenerator);
41+
}
42+
}

src/main/java/org/spongepowered/api/world/server/WorldManager.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,20 @@ default List<ResourceKey> offlineWorldKeys() {
123123
* <p>If a world with the given name is already loaded then it is returned instead.</p>
124124
*
125125
* @param key The key
126-
* @return The world
126+
* @return The world, if found.
127127
*/
128-
CompletableFuture<ServerWorld> loadWorld(ResourceKey key);
128+
CompletableFuture<Optional<ServerWorld>> loadWorld(ResourceKey key);
129+
130+
/**
131+
* Loads a {@link ServerWorld world} by a {@link ResourceKey key}.
132+
*
133+
* <p>If a world with the given name is already loaded then it is returned instead.</p>
134+
*
135+
* @param key The key
136+
* @param propertiesLoadOptions The options used to load the {@link ServerWorldProperties properties}.
137+
* @return The world, if found.
138+
*/
139+
CompletableFuture<Optional<ServerWorld>> loadWorld(ResourceKey key, ServerWorldProperties.LoadOptions propertiesLoadOptions);
129140

130141
/**
131142
* Unloads a {@link ServerWorld world} by a {@link ResourceKey key}.
@@ -159,6 +170,17 @@ default List<ResourceKey> offlineWorldKeys() {
159170
*/
160171
CompletableFuture<Optional<ServerWorldProperties>> loadProperties(ResourceKey key);
161172

173+
/**
174+
* Loads an offline {@link ServerWorldProperties properties}.
175+
*
176+
* <p>It is left up to the implementation on what conditions cause a failure of loading properties.</p>
177+
*
178+
* @param key The key
179+
* @param propertiesLoadOptions The options used to load the {@link ServerWorldProperties properties}.
180+
* @return The properties
181+
*/
182+
CompletableFuture<Optional<ServerWorldProperties>> loadProperties(ResourceKey key, ServerWorldProperties.LoadOptions propertiesLoadOptions);
183+
162184
/**
163185
* Saves a {@link ServerWorldProperties properties}.
164186
*

src/main/java/org/spongepowered/api/world/server/storage/ServerWorldProperties.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@
4343
import org.spongepowered.api.world.gamerule.GameRuleHolder;
4444
import org.spongepowered.api.world.generation.config.WorldGenerationConfig;
4545
import org.spongepowered.api.world.server.ServerWorld;
46+
import org.spongepowered.api.world.server.WorldArchetypeType;
4647
import org.spongepowered.api.world.storage.WorldProperties;
4748
import org.spongepowered.api.world.weather.Weather;
4849
import org.spongepowered.api.world.weather.WeatherUniverse;
4950

5051
import java.util.List;
5152
import java.util.Optional;
5253
import java.util.UUID;
54+
import java.util.function.Consumer;
5355

5456
public interface ServerWorldProperties extends WorldProperties, GameRuleHolder, Nameable, Identifiable, ResourceKeyed, WeatherUniverse.Mutable {
5557

@@ -373,4 +375,40 @@ default WorldBorder worldBorder() {
373375
default Weather weather() {
374376
return this.require(Keys.WEATHER);
375377
}
378+
379+
interface LoadOptions {
380+
381+
FoundOptions foundOptions();
382+
383+
Optional<CreateOptions> createOptions();
384+
385+
interface FoundOptions {
386+
387+
Optional<Consumer<ServerWorldProperties>> loadCallback();
388+
}
389+
390+
interface CreateOptions {
391+
392+
WorldArchetypeType worldArchetype();
393+
394+
Optional<Consumer<ServerWorldProperties>> initializeCallback();
395+
}
396+
397+
interface Builder extends org.spongepowered.api.util.Builder<LoadOptions, Builder> {
398+
399+
Builder.LoadStep load();
400+
401+
Builder.CreateStep create(WorldArchetypeType worldArchetype);
402+
403+
interface LoadStep extends Builder {
404+
405+
LoadStep loadCallback(Consumer<ServerWorldProperties> loadCallback);
406+
}
407+
408+
interface CreateStep extends Builder {
409+
410+
CreateStep initializeCallback(Consumer<ServerWorldProperties> initializeCallback);
411+
}
412+
}
413+
}
376414
}

0 commit comments

Comments
 (0)