mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 03:48:01 +01:00
#922: Add keepSpawnInMemory setting to WorldCreator
By: Jishuna <joshl5324@gmail.com>
This commit is contained in:
parent
5889c180cc
commit
8552281a2f
@ -1,5 +1,6 @@
|
||||
package org.bukkit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.util.Random;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.generator.BiomeProvider;
|
||||
@ -21,6 +22,7 @@ public class WorldCreator {
|
||||
private boolean generateStructures = true;
|
||||
private String generatorSettings = "";
|
||||
private boolean hardcore = false;
|
||||
private boolean keepSpawnInMemory = true;
|
||||
|
||||
/**
|
||||
* Creates an empty WorldCreationOptions for the given world name
|
||||
@ -28,9 +30,7 @@ public class WorldCreator {
|
||||
* @param name Name of the world that will be created
|
||||
*/
|
||||
public WorldCreator(@NotNull String name) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("World name cannot be null");
|
||||
}
|
||||
Preconditions.checkArgument(name != null, "World name cannot be null");
|
||||
|
||||
this.name = name;
|
||||
this.seed = (new Random()).nextLong();
|
||||
@ -44,9 +44,7 @@ public class WorldCreator {
|
||||
*/
|
||||
@NotNull
|
||||
public WorldCreator copy(@NotNull World world) {
|
||||
if (world == null) {
|
||||
throw new IllegalArgumentException("World cannot be null");
|
||||
}
|
||||
Preconditions.checkArgument(world != null, "World cannot be null");
|
||||
|
||||
seed = world.getSeed();
|
||||
environment = world.getEnvironment();
|
||||
@ -55,6 +53,7 @@ public class WorldCreator {
|
||||
type = world.getWorldType();
|
||||
generateStructures = world.canGenerateStructures();
|
||||
hardcore = world.isHardcore();
|
||||
keepSpawnInMemory = world.getKeepSpawnInMemory();
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -67,9 +66,7 @@ public class WorldCreator {
|
||||
*/
|
||||
@NotNull
|
||||
public WorldCreator copy(@NotNull WorldCreator creator) {
|
||||
if (creator == null) {
|
||||
throw new IllegalArgumentException("Creator cannot be null");
|
||||
}
|
||||
Preconditions.checkArgument(creator != null, "Creator cannot be null");
|
||||
|
||||
seed = creator.seed();
|
||||
environment = creator.environment();
|
||||
@ -79,6 +76,7 @@ public class WorldCreator {
|
||||
generateStructures = creator.generateStructures();
|
||||
generatorSettings = creator.generatorSettings();
|
||||
hardcore = creator.hardcore();
|
||||
keepSpawnInMemory = creator.keepSpawnInMemory();
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -392,6 +390,33 @@ public class WorldCreator {
|
||||
return hardcore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the spawn chunks will be kept loaded. <br>
|
||||
* Setting this to false will also stop the spawn chunks from being generated
|
||||
* when creating a new world.
|
||||
* <p>
|
||||
* Has little performance benefit unless paired with a {@link ChunkGenerator}
|
||||
* that overrides {@link ChunkGenerator#getFixedSpawnLocation(World, Random)}.
|
||||
*
|
||||
* @param keepSpawnInMemory Whether the spawn chunks will be kept loaded
|
||||
* @return This object, for chaining
|
||||
*/
|
||||
@NotNull
|
||||
public WorldCreator keepSpawnInMemory(boolean keepSpawnInMemory) {
|
||||
this.keepSpawnInMemory = keepSpawnInMemory;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether or not the spawn chunks will be kept loaded.
|
||||
*
|
||||
* @return True if the spawn chunks will be kept loaded
|
||||
*/
|
||||
public boolean keepSpawnInMemory() {
|
||||
return keepSpawnInMemory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a world with the specified options.
|
||||
* <p>
|
||||
@ -434,12 +459,9 @@ public class WorldCreator {
|
||||
*/
|
||||
@Nullable
|
||||
public static ChunkGenerator getGeneratorForName(@NotNull String world, @Nullable String name, @Nullable CommandSender output) {
|
||||
Preconditions.checkArgument(world != null, "World name must be specified");
|
||||
ChunkGenerator result = null;
|
||||
|
||||
if (world == null) {
|
||||
throw new IllegalArgumentException("World name must be specified");
|
||||
}
|
||||
|
||||
if (output == null) {
|
||||
output = Bukkit.getConsoleSender();
|
||||
}
|
||||
@ -479,12 +501,9 @@ public class WorldCreator {
|
||||
*/
|
||||
@Nullable
|
||||
public static BiomeProvider getBiomeProviderForName(@NotNull String world, @Nullable String name, @Nullable CommandSender output) {
|
||||
Preconditions.checkArgument(world != null, "World name must be specified");
|
||||
BiomeProvider result = null;
|
||||
|
||||
if (world == null) {
|
||||
throw new IllegalArgumentException("World name must be specified");
|
||||
}
|
||||
|
||||
if (output == null) {
|
||||
output = Bukkit.getConsoleSender();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user