mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 04:17:44 +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;
|
package org.bukkit;
|
||||||
|
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.generator.BiomeProvider;
|
import org.bukkit.generator.BiomeProvider;
|
||||||
@ -21,6 +22,7 @@ public class WorldCreator {
|
|||||||
private boolean generateStructures = true;
|
private boolean generateStructures = true;
|
||||||
private String generatorSettings = "";
|
private String generatorSettings = "";
|
||||||
private boolean hardcore = false;
|
private boolean hardcore = false;
|
||||||
|
private boolean keepSpawnInMemory = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty WorldCreationOptions for the given world name
|
* 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
|
* @param name Name of the world that will be created
|
||||||
*/
|
*/
|
||||||
public WorldCreator(@NotNull String name) {
|
public WorldCreator(@NotNull String name) {
|
||||||
if (name == null) {
|
Preconditions.checkArgument(name != null, "World name cannot be null");
|
||||||
throw new IllegalArgumentException("World name cannot be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.seed = (new Random()).nextLong();
|
this.seed = (new Random()).nextLong();
|
||||||
@ -44,9 +44,7 @@ public class WorldCreator {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public WorldCreator copy(@NotNull World world) {
|
public WorldCreator copy(@NotNull World world) {
|
||||||
if (world == null) {
|
Preconditions.checkArgument(world != null, "World cannot be null");
|
||||||
throw new IllegalArgumentException("World cannot be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
seed = world.getSeed();
|
seed = world.getSeed();
|
||||||
environment = world.getEnvironment();
|
environment = world.getEnvironment();
|
||||||
@ -55,6 +53,7 @@ public class WorldCreator {
|
|||||||
type = world.getWorldType();
|
type = world.getWorldType();
|
||||||
generateStructures = world.canGenerateStructures();
|
generateStructures = world.canGenerateStructures();
|
||||||
hardcore = world.isHardcore();
|
hardcore = world.isHardcore();
|
||||||
|
keepSpawnInMemory = world.getKeepSpawnInMemory();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -67,9 +66,7 @@ public class WorldCreator {
|
|||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public WorldCreator copy(@NotNull WorldCreator creator) {
|
public WorldCreator copy(@NotNull WorldCreator creator) {
|
||||||
if (creator == null) {
|
Preconditions.checkArgument(creator != null, "Creator cannot be null");
|
||||||
throw new IllegalArgumentException("Creator cannot be null");
|
|
||||||
}
|
|
||||||
|
|
||||||
seed = creator.seed();
|
seed = creator.seed();
|
||||||
environment = creator.environment();
|
environment = creator.environment();
|
||||||
@ -79,6 +76,7 @@ public class WorldCreator {
|
|||||||
generateStructures = creator.generateStructures();
|
generateStructures = creator.generateStructures();
|
||||||
generatorSettings = creator.generatorSettings();
|
generatorSettings = creator.generatorSettings();
|
||||||
hardcore = creator.hardcore();
|
hardcore = creator.hardcore();
|
||||||
|
keepSpawnInMemory = creator.keepSpawnInMemory();
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -392,6 +390,33 @@ public class WorldCreator {
|
|||||||
return hardcore;
|
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.
|
* Creates a world with the specified options.
|
||||||
* <p>
|
* <p>
|
||||||
@ -434,12 +459,9 @@ public class WorldCreator {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static ChunkGenerator getGeneratorForName(@NotNull String world, @Nullable String name, @Nullable CommandSender output) {
|
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;
|
ChunkGenerator result = null;
|
||||||
|
|
||||||
if (world == null) {
|
|
||||||
throw new IllegalArgumentException("World name must be specified");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (output == null) {
|
if (output == null) {
|
||||||
output = Bukkit.getConsoleSender();
|
output = Bukkit.getConsoleSender();
|
||||||
}
|
}
|
||||||
@ -479,12 +501,9 @@ public class WorldCreator {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static BiomeProvider getBiomeProviderForName(@NotNull String world, @Nullable String name, @Nullable CommandSender output) {
|
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;
|
BiomeProvider result = null;
|
||||||
|
|
||||||
if (world == null) {
|
|
||||||
throw new IllegalArgumentException("World name must be specified");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (output == null) {
|
if (output == null) {
|
||||||
output = Bukkit.getConsoleSender();
|
output = Bukkit.getConsoleSender();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user