Add docs and fix more checkstyles

This commit is contained in:
Ben Woo 2023-09-11 21:52:16 +08:00
parent d77fb43536
commit ffec23c9ed
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
24 changed files with 713 additions and 140 deletions

View File

@ -442,7 +442,7 @@
value="Local variable name ''{0}'' must match pattern ''{1}''."/> value="Local variable name ''{0}'' must match pattern ''{1}''."/>
</module> </module>
<module name="MemberName"> <module name="MemberName">
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/> <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$|^[A-Z][A-Z0-9_]*$"/>
<message key="name.invalidPattern" <message key="name.invalidPattern"
value="Member name ''{0}'' must match pattern ''{1}''."/> value="Member name ''{0}'' must match pattern ''{1}''."/>
</module> </module>

View File

@ -18,6 +18,9 @@ import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
/**
* Extension of {@link MultiverseWorld} that represents a world that is currently loaded with bukkit world object.
*/
public class LoadedMultiverseWorld extends MultiverseWorld { public class LoadedMultiverseWorld extends MultiverseWorld {
private static final int SPAWN_LOCATION_SEARCH_TOLERANCE = 16; private static final int SPAWN_LOCATION_SEARCH_TOLERANCE = 16;
private static final int SPAWN_LOCATION_SEARCH_RADIUS = 16; private static final int SPAWN_LOCATION_SEARCH_RADIUS = 16;
@ -25,19 +28,19 @@ public class LoadedMultiverseWorld extends MultiverseWorld {
private final UUID worldUid; private final UUID worldUid;
private final BlockSafety blockSafety; private final BlockSafety blockSafety;
private final SafeTTeleporter safeTTeleporter; private final SafeTTeleporter safetyTeleporter;
private final LocationManipulation locationManipulation; private final LocationManipulation locationManipulation;
LoadedMultiverseWorld( LoadedMultiverseWorld(
@NotNull World world, @NotNull World world,
@NotNull WorldConfig worldConfig, @NotNull WorldConfig worldConfig,
@NotNull BlockSafety blockSafety, @NotNull BlockSafety blockSafety,
@NotNull SafeTTeleporter safeTTeleporter, @NotNull SafeTTeleporter safetyTeleporter,
@NotNull LocationManipulation locationManipulation) { @NotNull LocationManipulation locationManipulation) {
super(world.getName(), worldConfig); super(world.getName(), worldConfig);
this.worldUid = world.getUID(); this.worldUid = world.getUID();
this.blockSafety = blockSafety; this.blockSafety = blockSafety;
this.safeTTeleporter = safeTTeleporter; this.safetyTeleporter = safetyTeleporter;
this.locationManipulation = locationManipulation; this.locationManipulation = locationManipulation;
setupWorldConfig(world); setupWorldConfig(world);
@ -78,7 +81,7 @@ public class LoadedMultiverseWorld extends MultiverseWorld {
// The location is not safe, so we need to find a better one. // The location is not safe, so we need to find a better one.
Logging.warning("Spawn location from world.dat file was unsafe. Adjusting..."); Logging.warning("Spawn location from world.dat file was unsafe. Adjusting...");
Logging.warning("Original Location: " + locationManipulation.strCoordsRaw(location)); Logging.warning("Original Location: " + locationManipulation.strCoordsRaw(location));
Location newSpawn = safeTTeleporter.getSafeLocation(location, Location newSpawn = safetyTeleporter.getSafeLocation(location,
SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS); SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS);
// I think we could also do this, as I think this is what Notch does. // I think we could also do this, as I think this is what Notch does.
// Not sure how it will work in the nether... // Not sure how it will work in the nether...
@ -103,18 +106,39 @@ public class LoadedMultiverseWorld extends MultiverseWorld {
return location; return location;
} }
/**
* Gets the Bukkit world object that this world describes.
*
* @return Bukkit world object.
*/
public Option<World> getBukkitWorld() { public Option<World> getBukkitWorld() {
return Option.of(Bukkit.getWorld(worldUid)); return Option.of(Bukkit.getWorld(worldUid));
} }
/**
* Gets the type of this world.
*
* @return Type of this world.
*/
public Option<WorldType> getWorldType() { public Option<WorldType> getWorldType() {
//noinspection deprecation
return getBukkitWorld().map(World::getWorldType); return getBukkitWorld().map(World::getWorldType);
} }
/**
* Gets whether or not structures are being generated.
*
* @return True if structures are being generated.
*/
public Option<Boolean> canGenerateStructures() { public Option<Boolean> canGenerateStructures() {
return getBukkitWorld().map(World::canGenerateStructures); return getBukkitWorld().map(World::canGenerateStructures);
} }
/**
* Get a list of all players in this World.
*
* @return A list of all Players currently residing in this world
*/
public Option<List<Player>> getPlayers() { public Option<List<Player>> getPlayers() {
return getBukkitWorld().map(World::getPlayers); return getBukkitWorld().map(World::getPlayers);
} }

View File

@ -15,6 +15,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
/**
* Represents a world handled by Multiverse which has all the custom properties provided by Multiverse.
*/
public class MultiverseWorld { public class MultiverseWorld {
protected final String worldName; protected final String worldName;
@ -25,10 +28,23 @@ public class MultiverseWorld {
this.worldConfig = worldConfig; this.worldConfig = worldConfig;
} }
/**
* Gets the name of this world. The name cannot be changed.
* <br/>
* Note for plugin developers: Usually {@link #getAlias()}
* is what you want to use instead of this method.
*
* @return The name of the world as a String.
*/
public String getName() { public String getName() {
return worldName; return worldName;
} }
/**
* Gets whether this world is loaded.
*
* @return True if the world is loaded, else false.
*/
public boolean isLoaded() { public boolean isLoaded() {
return worldConfig.hasMVWorld(); return worldConfig.hasMVWorld();
} }
@ -45,242 +61,581 @@ public class MultiverseWorld {
return worldConfig.setProperty(name, value); return worldConfig.setProperty(name, value);
} }
/**
* Gets whether or not Multiverse should auto-adjust the spawn for this world.
*
* @return True if Multiverse should adjust the spawn, false if not.
*/
public boolean getAdjustSpawn() { public boolean getAdjustSpawn() {
return worldConfig.getAdjustSpawn(); return worldConfig.getAdjustSpawn();
} }
/**
* Sets whether or not Multiverse should auto-adjust the spawn for this world.
*
* @param adjustSpawn True if multiverse should adjust the spawn, false if not.
*/
public Try<Void> setAdjustSpawn(boolean adjustSpawn) { public Try<Void> setAdjustSpawn(boolean adjustSpawn) {
return worldConfig.setAdjustSpawn(adjustSpawn); return worldConfig.setAdjustSpawn(adjustSpawn);
} }
/**
* Gets the alias of this world.
* <br/>
* This alias allows users to have a world named "world" but show up in the list as "FernIsland"
*
* @return The alias of the world as a String.
*/
public String getAlias() { public String getAlias() {
return Strings.isNullOrEmpty(worldConfig.getAlias()) ? worldName : worldConfig.getAlias(); return Strings.isNullOrEmpty(worldConfig.getAlias()) ? worldName : worldConfig.getAlias();
} }
/**
* Sets the alias of the world.
*
* @param alias A string that is the new alias.
*/
public Try<Void> setAlias(String alias) { public Try<Void> setAlias(String alias) {
return worldConfig.setAlias(alias); return worldConfig.setAlias(alias);
} }
/**
* Whether or not players are allowed to fly in this world.
*
* @return True if players allowed to fly in this world.
*/
public boolean getAllowFlight() { public boolean getAllowFlight() {
return worldConfig.getAllowFlight(); return worldConfig.getAllowFlight();
} }
/**
* Sets whether or not players are allowed to fly in this world.
*
* @param allowFlight True to allow flight in this world.
*/
public Try<Void> setAllowFlight(boolean allowFlight) { public Try<Void> setAllowFlight(boolean allowFlight) {
return worldConfig.setAllowFlight(allowFlight); return worldConfig.setAllowFlight(allowFlight);
} }
/**
* Gets whether weather is enabled in this world.
*
* @return True if weather events will occur, false if not.
*/
public boolean getAllowWeather() { public boolean getAllowWeather() {
return worldConfig.getAllowWeather(); return worldConfig.getAllowWeather();
} }
/**
* Sets whether or not there will be weather events in a given world.
* If set to false, Multiverse will disable the weather in the world immediately.
*
* @param allowWeather True if weather events should occur in a world, false if not.
*/
public Try<Void> setAllowWeather(boolean allowWeather) { public Try<Void> setAllowWeather(boolean allowWeather) {
return worldConfig.setAllowWeather(allowWeather); return worldConfig.setAllowWeather(allowWeather);
} }
/**
* Gets whether or not a world will auto-heal players if the difficulty is on peaceful.
*
* @return True if the world should heal (default), false if not.
*/
public boolean getAutoHeal() { public boolean getAutoHeal() {
return worldConfig.getAutoHeal(); return worldConfig.getAutoHeal();
} }
/**
* Sets whether or not a world will auto-heal players if the difficulty is on peaceful.
*
* @param autoHeal True if the world will heal.
*/
public Try<Void> setAutoHeal(boolean autoHeal) { public Try<Void> setAutoHeal(boolean autoHeal) {
return worldConfig.setAutoHeal(autoHeal); return worldConfig.setAutoHeal(autoHeal);
} }
/**
* Gets whether or not Multiverse should auto-load this world.
*
* @return True if Multiverse should auto-load this world.
*/
public boolean getAutoLoad() { public boolean getAutoLoad() {
return worldConfig.getAutoLoad(); return worldConfig.getAutoLoad();
} }
/**
* Sets whether or not Multiverse should auto-load this world.
* <br/>
* True is default.
*
* @param autoLoad True if multiverse should autoload this world the spawn, false if not.
*/
public Try<Void> setAutoLoad(boolean autoLoad) { public Try<Void> setAutoLoad(boolean autoLoad) {
return worldConfig.setAutoLoad(autoLoad); return worldConfig.setAutoLoad(autoLoad);
} }
/**
* Gets whether or not a player who dies in this world will respawn in their
* bed or follow the normal respawn pattern.
*
* @return True if players dying in this world should respawn at their bed.
*/
public boolean getBedRespawn() { public boolean getBedRespawn() {
return worldConfig.getBedRespawn(); return worldConfig.getBedRespawn();
} }
/**
* Sets whether or not a player who dies in this world will respawn in their
* bed or follow the normal respawn pattern.
* <br/>
* True is default.
*
* @param bedRespawn True if players dying in this world respawn at their bed.
*/
public Try<Void> setBedRespawn(boolean bedRespawn) { public Try<Void> setBedRespawn(boolean bedRespawn) {
return worldConfig.setBedRespawn(bedRespawn); return worldConfig.setBedRespawn(bedRespawn);
} }
/**
* Gets the type of currency that will be used when users enter this world. A value of null indicates a non-item
* based currency is used.
*
* @return The type of currency that will be used when users enter this world.
*/
public Material getCurrency() { public Material getCurrency() {
return worldConfig.getEntryFeeCurrency(); return worldConfig.getEntryFeeCurrency();
} }
/**
* Sets the type of item that will be required given the price is not 0.
* Use a value of null to specify a non-item based currency.
*
* @param currency The Type of currency that will be used when users enter this world.
*/
public Try<Void> setCurrency(Material currency) { public Try<Void> setCurrency(Material currency) {
return worldConfig.setEntryFeeCurrency(currency); return worldConfig.setEntryFeeCurrency(currency);
} }
/**
* Gets the difficulty of this world.
*
* @return The difficulty of this world.
*/
public Difficulty getDifficulty() { public Difficulty getDifficulty() {
return worldConfig.getDifficulty(); return worldConfig.getDifficulty();
} }
/**
* Sets the difficulty of this world and returns {@code true} on success.
* Valid string values are either an integer of difficulty(0-3) or
* the name that resides in the Bukkit enum, ex. PEACEFUL
*
* @param difficulty The new difficulty.
*/
public Try<Void> setDifficulty(Difficulty difficulty) { public Try<Void> setDifficulty(Difficulty difficulty) {
return worldConfig.setDifficulty(difficulty); return worldConfig.setDifficulty(difficulty);
} }
/**
* Gets the environment of this world. You cannot change this after world creation.
*
* @return A {@link World.Environment}.
*/
public World.Environment getEnvironment() { public World.Environment getEnvironment() {
return worldConfig.getEnvironment(); return worldConfig.getEnvironment();
} }
/**
* Gets the GameMode of this world.
*
* @return The GameMode of this world.
*/
public GameMode getGameMode() { public GameMode getGameMode() {
return worldConfig.getGameMode(); return worldConfig.getGameMode();
} }
/**
* Sets the game mode of this world.
*
* @param gameMode The new {@link GameMode}.
*/
public Try<Void> setGameMode(GameMode gameMode) { public Try<Void> setGameMode(GameMode gameMode) {
return worldConfig.setGameMode(gameMode); return worldConfig.setGameMode(gameMode);
} }
/**
* Gets the generator string of this world. You cannot change this after world creation.
*
* @return The name of the generator.
*/
public String getGenerator() { public String getGenerator() {
return worldConfig.getGenerator(); return worldConfig.getGenerator();
} }
/**
* Gets whether or not this world will display in chat, mvw and mvl regardless if a user has the
* access permissions to go to this world.
*
* @return True if the world will be hidden, false if not.
*/
public boolean isHidden() { public boolean isHidden() {
return worldConfig.isHidden(); return worldConfig.isHidden();
} }
/**
* Sets whether or not this world will display in chat, mvw and mvl regardless if a user has the
* access permissions to go to this world.
*
* @param hidden True if the world should be hidden, false if not.
*/
public Try<Void> setHidden(boolean hidden) { public Try<Void> setHidden(boolean hidden) {
return worldConfig.setHidden(hidden); return worldConfig.setHidden(hidden);
} }
/**
* Gets whether or not the hunger level of players will go down in a world.
*
* @return True if it will go down, false if it will remain steady.
*/
public boolean getHunger() { public boolean getHunger() {
return worldConfig.getHunger(); return worldConfig.getHunger();
} }
/**
* Sets whether or not the hunger level of players will go down in a world.
*
* @param hunger True if hunger will go down, false to keep it at the level they entered a world with.
*/
public Try<Void> setHunger(boolean hunger) { public Try<Void> setHunger(boolean hunger) {
return worldConfig.setHunger(hunger); return worldConfig.setHunger(hunger);
} }
/**
* Gets whether or not CraftBukkit is keeping the chunks for this world in memory.
*
* @return True if CraftBukkit is keeping spawn chunks in memory.
*/
public boolean getKeepSpawnInMemory() { public boolean getKeepSpawnInMemory() {
return worldConfig.getKeepSpawnInMemory(); return worldConfig.getKeepSpawnInMemory();
} }
/**
* If true, tells Craftbukkit to keep a worlds spawn chunks loaded in memory (default: true)
* If not, CraftBukkit will attempt to free memory when players have not used that world.
* This will not happen immediately.
*
* @param keepSpawnInMemory If true, CraftBukkit will keep the spawn chunks loaded in memory.
*/
public Try<Void> setKeepSpawnInMemory(boolean keepSpawnInMemory) { public Try<Void> setKeepSpawnInMemory(boolean keepSpawnInMemory) {
return worldConfig.setKeepSpawnInMemory(keepSpawnInMemory); return worldConfig.setKeepSpawnInMemory(keepSpawnInMemory);
} }
/**
* Gets the player limit for this world after which players without an override
* permission node will not be allowed in. A value of -1 or less signifies no limit
*
* @return The player limit
*/
public int getPlayerLimit() { public int getPlayerLimit() {
return worldConfig.getPlayerLimit(); return worldConfig.getPlayerLimit();
} }
/**
* Sets the player limit for this world after which players without an override
* permission node will not be allowed in. A value of -1 or less signifies no limit
*
* @param playerLimit The new limit
*/
public Try<Void> setPlayerLimit(int playerLimit) { public Try<Void> setPlayerLimit(int playerLimit) {
return worldConfig.setPlayerLimit(playerLimit); return worldConfig.setPlayerLimit(playerLimit);
} }
/**
* Gets which type(s) of portals are allowed to be constructed in this world.
*
* @return The type of portals that are allowed.
*/
public AllowedPortalType getPortalForm() { public AllowedPortalType getPortalForm() {
return worldConfig.getPortalForm(); return worldConfig.getPortalForm();
} }
/**
* Sets The types of portals that are allowed in this world.
*
* @param portalForm The type of portals allowed in this world.
*/
public Try<Void> setPortalForm(AllowedPortalType portalForm) { public Try<Void> setPortalForm(AllowedPortalType portalForm) {
return worldConfig.setPortalForm(portalForm); return worldConfig.setPortalForm(portalForm);
} }
/**
* Gets the amount of currency it requires to enter this world.
*
* @return The amount it costs to enter this world.
*/
public double getPrice() { public double getPrice() {
return worldConfig.getEntryFeeAmount(); return worldConfig.getEntryFeeAmount();
} }
/**
* Sets the price for entry to this world.
* You can think of this like an amount.
* The type can be set with {@link #setCurrency(Material)}
*
* @param price The Amount of money/item to enter the world.
*/
public Try<Void> setPrice(double price) { public Try<Void> setPrice(double price) {
return worldConfig.setEntryFeeAmount(price); return worldConfig.setEntryFeeAmount(price);
} }
/**
* Gets whether or not PVP is enabled in this world in some form (fake or not).
*
* @return True if players can take damage from other players.
*/
public boolean getPvp() { public boolean getPvp() {
return worldConfig.getPvp(); return worldConfig.getPvp();
} }
/**
* Turn pvp on or off. This setting is used to set the world's PVP mode.
*
* @param pvp True to enable PVP damage, false to disable it.
*/
public Try<Void> setPvp(boolean pvp) { public Try<Void> setPvp(boolean pvp) {
return worldConfig.setPvp(pvp); return worldConfig.setPvp(pvp);
} }
/**
* Gets the world name players will respawn in if they die in this one.
*
* @return A world name that exists on the server.
*/
public String getRespawnWorldName() { public String getRespawnWorldName() {
return worldConfig.getRespawnWorld(); return worldConfig.getRespawnWorld();
} }
/**
* Gets the world players will respawn in if they die in this one.
*
* @return A world that exists on the server.
*/
public @Nullable World getRespawnWorld() { public @Nullable World getRespawnWorld() {
return Bukkit.getWorld(worldConfig.getRespawnWorld()); return Bukkit.getWorld(worldConfig.getRespawnWorld());
} }
/**
* Sets the world players will respawn in if they die in this one.
* Returns true upon success, false upon failure.
*
* @param respawnWorld The name of a world that exists on the server.
*/
public Try<Void> setRespawnWorld(World respawnWorld) { public Try<Void> setRespawnWorld(World respawnWorld) {
return worldConfig.setRespawnWorld(respawnWorld.getName()); return worldConfig.setRespawnWorld(respawnWorld.getName());
} }
/**
* Sets the world players will respawn in if they die in this one.
* Returns true upon success, false upon failure.
*
* @param respawnWorld The name of a world that exists on the server.
*/
public Try<Void> setRespawnWorld(MultiverseWorld respawnWorld) { public Try<Void> setRespawnWorld(MultiverseWorld respawnWorld) {
return worldConfig.setRespawnWorld(respawnWorld.getName()); return worldConfig.setRespawnWorld(respawnWorld.getName());
} }
/**
* Sets the world players will respawn in if they die in this one.
* Returns true upon success, false upon failure.
*
* @param respawnWorld The name of a world that exists on the server.
*/
public Try<Void> setRespawnWorld(String respawnWorld) { public Try<Void> setRespawnWorld(String respawnWorld) {
return worldConfig.setRespawnWorld(respawnWorld); return worldConfig.setRespawnWorld(respawnWorld);
} }
/**
* Gets the scaling value of this world.Really only has an effect if you use
* Multiverse-NetherPortals.
*
* @return This world's non-negative, non-zero scale.
*/
public double getScale() { public double getScale() {
return worldConfig.getScale(); return worldConfig.getScale();
} }
/**
* Sets the scale of this world. Really only has an effect if you use
* Multiverse-NetherPortals. TODO: we are removing mvnp.
*
* @param scale A scaling value, cannot be negative or 0.
*/
public Try<Void> setScale(double scale) { public Try<Void> setScale(double scale) {
return worldConfig.setScale(scale); return worldConfig.setScale(scale);
} }
/**
* Gets the world seed of this world. This cannot be changed after world creation.
*
* @return The Long version of the seed.
*/
public long getSeed() { public long getSeed() {
return worldConfig.getSeed(); return worldConfig.getSeed();
} }
/**
* Gets the spawn location of this world.
*
* @return The spawn location of this world.
*/
public Location getSpawnLocation() { public Location getSpawnLocation() {
return worldConfig.getSpawnLocation(); return worldConfig.getSpawnLocation();
} }
/**
* Sets the spawn location for a world.
*
* @param spawnLocation The spawn location for a world.
*/
public Try<Void> setSpawnLocation(Location spawnLocation) { public Try<Void> setSpawnLocation(Location spawnLocation) {
return worldConfig.setSpawnLocation(spawnLocation); return worldConfig.setSpawnLocation(spawnLocation);
} }
/**
* Gets whether or not animals are allowed to spawn in this world.
*
* @return True if ANY animal can, false if no animals can spawn.
*/
public boolean getSpawningAnimals() { public boolean getSpawningAnimals() {
return worldConfig.getSpawningAnimals(); return worldConfig.getSpawningAnimals();
} }
/**
* Sets whether or not animals can spawn.
* <br/>
* If there are values in {@link #getSpawningAnimalsExceptions()} and this is false,
* those animals become the exceptions, and will spawn
*
* @param spawningAnimals True to allow spawning of monsters, false to prevent.
*/
public Try<Void> setSpawningAnimals(boolean spawningAnimals) { public Try<Void> setSpawningAnimals(boolean spawningAnimals) {
return worldConfig.setSpawningAnimals(spawningAnimals); return worldConfig.setSpawningAnimals(spawningAnimals);
} }
/**
* Gets the amount of ticks between animal spawns.
*
* @return The amount of ticks between animal spawns.
*/
public int getSpawningAnimalsTicks() { public int getSpawningAnimalsTicks() {
return worldConfig.getSpawningAnimalsTicks(); return worldConfig.getSpawningAnimalsTicks();
} }
/**
* Sets the amount of ticks between animal spawns. Set to -1 to use bukkit default.
*
* @param spawningAnimalsAmount The amount of ticks between animal spawns.
* @return Result of setting property.
*/
public Try<Void> setSpawningAnimalsTicks(int spawningAnimalsAmount) { public Try<Void> setSpawningAnimalsTicks(int spawningAnimalsAmount) {
return worldConfig.setSpawningAnimalsTicks(spawningAnimalsAmount); return worldConfig.setSpawningAnimalsTicks(spawningAnimalsAmount);
} }
/**
* Returns a list of animals. This list always negates the {@link #getSpawningAnimals()} result.
*
* @return A list of animals that will spawn if {@link #getSpawningAnimals()} is false.
*/
public List<String> getSpawningAnimalsExceptions() { public List<String> getSpawningAnimalsExceptions() {
return worldConfig.getSpawningAnimalsExceptions(); return worldConfig.getSpawningAnimalsExceptions();
} }
/**
* Sets the list of animals that will spawn if {@link #getSpawningAnimals()} is false.
*
* @param spawningAnimalsExceptions The list of animals that will spawn if {@link #getSpawningAnimals()} is false.
* @return Result of setting property.
*/
public Try<Void> setSpawningAnimalsExceptions(List<String> spawningAnimalsExceptions) { public Try<Void> setSpawningAnimalsExceptions(List<String> spawningAnimalsExceptions) {
return worldConfig.setSpawningAnimalsExceptions(spawningAnimalsExceptions); return worldConfig.setSpawningAnimalsExceptions(spawningAnimalsExceptions);
} }
/**
* Gets whether or not monsters are allowed to spawn in this world.
*
* @return True if ANY monster can, false if no monsters can spawn.
*/
public boolean getSpawningMonsters() { public boolean getSpawningMonsters() {
return worldConfig.getSpawningMonsters(); return worldConfig.getSpawningMonsters();
} }
/**
* Sets whether or not monsters can spawn.
* If there are values in {@link #getSpawningMonstersExceptions()} and this is false,
* those monsters become the exceptions, and will spawn
*
* @param spawningMonsters True to allow spawning of monsters, false to prevent.
* @return Result of setting property.
*/
public Try<Void> setSpawningMonsters(boolean spawningMonsters) { public Try<Void> setSpawningMonsters(boolean spawningMonsters) {
return worldConfig.setSpawningMonsters(spawningMonsters); return worldConfig.setSpawningMonsters(spawningMonsters);
} }
/**
* Gets the amount of ticks between monster spawns.
*
* @return The amount of ticks between monster spawns.
*/
public int getSpawningMonstersTicks() { public int getSpawningMonstersTicks() {
return worldConfig.getSpawningMonstersTicks(); return worldConfig.getSpawningMonstersTicks();
} }
/**
* Sets the amount of ticks between monster spawns. Set to -1 to use bukkit default.
*
* @param spawningMonstersAmount The amount of ticks between monster spawns.
* @return Result of setting property.
*/
public Try<Void> setSpawningMonstersTicks(int spawningMonstersAmount) { public Try<Void> setSpawningMonstersTicks(int spawningMonstersAmount) {
return worldConfig.setSpawningMonstersTicks(spawningMonstersAmount); return worldConfig.setSpawningMonstersTicks(spawningMonstersAmount);
} }
/**
* Returns a list of monsters. This list always negates the {@link #getSpawningMonsters()} result.
*
* @return A list of monsters that will spawn if {@link #getSpawningMonsters()} is false.
*/
public List<String> getSpawningMonstersExceptions() { public List<String> getSpawningMonstersExceptions() {
return worldConfig.getSpawningMonstersExceptions(); return worldConfig.getSpawningMonstersExceptions();
} }
/**
* Sets the list of monsters that will spawn if {@link #getSpawningMonsters()} is false.
*
* @param spawningMonstersExceptions The list of monsters that will spawn if {@link #getSpawningMonsters()}
* is false.
* @return Result of setting property.
*/
public Try<Void> setSpawningMonstersExceptions(List<String> spawningMonstersExceptions) { public Try<Void> setSpawningMonstersExceptions(List<String> spawningMonstersExceptions) {
return worldConfig.setSpawningMonstersExceptions(spawningMonstersExceptions); return worldConfig.setSpawningMonstersExceptions(spawningMonstersExceptions);
} }
/**
* Gets a list of all the worlds that players CANNOT travel to from this world,regardless of their access
* permissions.
*
* @return A List of world names.
*/
public List<String> getWorldBlacklist() { public List<String> getWorldBlacklist() {
return worldConfig.getWorldBlacklist(); return worldConfig.getWorldBlacklist();
} }
/**
* Sets the list of worlds that players CANNOT travel to from this world, regardless of their access permissions.
*
* @param worldBlacklist A List of world names.
* @return Result of setting property.
*/
public Try<Void> setWorldBlacklist(List<String> worldBlacklist) { public Try<Void> setWorldBlacklist(List<String> worldBlacklist) {
return worldConfig.setWorldBlacklist(worldBlacklist); return worldConfig.setWorldBlacklist(worldBlacklist);
} }

View File

@ -14,7 +14,18 @@ import java.util.Map;
*/ */
@SerializableAs("MVNullLocation (It's a bug if you see this in your config file)") @SerializableAs("MVNullLocation (It's a bug if you see this in your config file)")
public final class NullLocation extends SpawnLocation { public final class NullLocation extends SpawnLocation {
public NullLocation() { private static final NullLocation INSTANCE = new NullLocation();
/**
* Get the default null location instance.
*
* @return The instance.
*/
public static NullLocation get() {
return INSTANCE;
}
private NullLocation() {
super(0, -1, 0); super(0, -1, 0);
} }
@ -48,6 +59,11 @@ public final class NullLocation extends SpawnLocation {
return -1; return -1;
} }
@Override
public boolean equals(Object obj) {
return false;
}
@Override @Override
public String toString() { public String toString() {
return "Location{null}"; return "Location{null}";

View File

@ -1,10 +1,5 @@
package com.onarandombox.MultiverseCore.worldnew.config; package com.onarandombox.MultiverseCore.worldnew.config;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -13,6 +8,11 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.configuration.serialization.SerializableAs;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
/** /**
* Just like a regular {@link Location}, however {@code world} is usually {@code null} * Just like a regular {@link Location}, however {@code world} is usually {@code null}
* or just a weak reference and it implements {@link ConfigurationSerializable}. * or just a weak reference and it implements {@link ConfigurationSerializable}.
@ -21,14 +21,35 @@ import org.jetbrains.annotations.NotNull;
public class SpawnLocation extends Location implements ConfigurationSerializable { public class SpawnLocation extends Location implements ConfigurationSerializable {
private Reference<World> worldRef; private Reference<World> worldRef;
/**
* Constructs a new Location with the given coordinates.
*
* @param x The x-coordinate of this new location
* @param y The y-coordinate of this new location
* @param z The z-coordinate of this new location
*/
public SpawnLocation(double x, double y, double z) { public SpawnLocation(double x, double y, double z) {
super(null, x, y, z); super(null, x, y, z);
} }
/**
* Constructs a new Location with the given coordinates and direction.
*
* @param x The x-coordinate of this new location
* @param y The y-coordinate of this new location
* @param z The z-coordinate of this new location
* @param yaw The absolute rotation on the x-plane, in degrees
* @param pitch The absolute rotation on the y-plane, in degrees
*/
public SpawnLocation(double x, double y, double z, float yaw, float pitch) { public SpawnLocation(double x, double y, double z, float yaw, float pitch) {
super(null, x, y, z, yaw, pitch); super(null, x, y, z, yaw, pitch);
} }
/**
* Constructs a new Location from an existing Location.
*
* @param loc The location to clone.
*/
public SpawnLocation(Location loc) { public SpawnLocation(Location loc) {
this(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); this(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
} }
@ -54,8 +75,9 @@ public class SpawnLocation extends Location implements ConfigurationSerializable
*/ */
@Override @Override
public @NotNull Chunk getChunk() { public @NotNull Chunk getChunk() {
if (this.worldRef != null && this.worldRef.get() != null) { World world = this.worldRef != null ? this.worldRef.get() : null;
return this.worldRef.get().getChunkAt(this); if (world != null) {
return world.getChunkAt(this);
} }
throw new IllegalStateException("World is null"); throw new IllegalStateException("World is null");
} }
@ -64,9 +86,10 @@ public class SpawnLocation extends Location implements ConfigurationSerializable
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public Block getBlock() { public @NotNull Block getBlock() {
if (this.worldRef != null && this.worldRef.get() != null) { World world = this.worldRef != null ? this.worldRef.get() : null;
return this.worldRef.get().getBlockAt(this); if (world != null) {
return world.getBlockAt(this);
} }
throw new IllegalStateException("World is null"); throw new IllegalStateException("World is null");
} }

View File

@ -33,7 +33,7 @@ public final class WorldConfig {
private final WorldConfigNodes configNodes; private final WorldConfigNodes configNodes;
private final ConfigurationSectionHandle configHandle; private final ConfigurationSectionHandle configHandle;
public WorldConfig(@NotNull String worldName, @NotNull final ConfigurationSection configSection) { WorldConfig(@NotNull String worldName, @NotNull final ConfigurationSection configSection) {
this.worldName = worldName; this.worldName = worldName;
this.configNodes = new WorldConfigNodes(); this.configNodes = new WorldConfigNodes();
this.configHandle = ConfigurationSectionHandle.builder(configSection) this.configHandle = ConfigurationSectionHandle.builder(configSection)

View File

@ -155,7 +155,7 @@ public class WorldConfigNodes {
.build()); .build());
final ConfigNode<Location> SPAWN_LOCATION = node(ConfigNode.builder("spawn-location", Location.class) final ConfigNode<Location> SPAWN_LOCATION = node(ConfigNode.builder("spawn-location", Location.class)
.defaultValue(new NullLocation()) .defaultValue(NullLocation.get())
.name(null) .name(null)
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) return; if (world == null) return;

View File

@ -200,7 +200,7 @@ public final class WorldsConfigManager {
? worldsConfig.getConfigurationSection(worldName) : worldsConfig.createSection(worldName); ? worldsConfig.getConfigurationSection(worldName) : worldsConfig.createSection(worldName);
} }
private final class ConfigMigratedException extends RuntimeException { private static final class ConfigMigratedException extends RuntimeException {
private ConfigMigratedException() { private ConfigMigratedException() {
super("Config migrated"); super("Config migrated");
} }

View File

@ -6,13 +6,22 @@ import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason; import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason; import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/**
* Result of a world blacklist check.
*/
public class BlacklistResult { public class BlacklistResult {
/**
* Success reasons for a blacklist check.
*/
public enum Success implements SuccessReason { public enum Success implements SuccessReason {
UNKNOWN_FROM_WORLD, UNKNOWN_FROM_WORLD,
BYPASSED_BLACKLISTED, BYPASSED_BLACKLISTED,
NOT_BLACKLISTED NOT_BLACKLISTED
} }
/**
* Failure reasons for a blacklist check.
*/
public enum Failure implements FailureReason { public enum Failure implements FailureReason {
BLACKLISTED(MVCorei18n.ENTRYCHECK_BLACKLISTED); BLACKLISTED(MVCorei18n.ENTRYCHECK_BLACKLISTED);

View File

@ -1,13 +1,18 @@
package com.onarandombox.MultiverseCore.worldnew.entrycheck; package com.onarandombox.MultiverseCore.worldnew.entrycheck;
import co.aikar.locales.MessageKey; import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider; import co.aikar.locales.MessageKeyProvider;
import com.onarandombox.MultiverseCore.utils.MVCorei18n; import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason; import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason; import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/**
* Result of a world entry fee check.
*/
public class EntryFeeResult { public class EntryFeeResult {
/**
* Success reasons for an entry fee check.
*/
public enum Success implements SuccessReason { public enum Success implements SuccessReason {
FREE_ENTRY, FREE_ENTRY,
ENOUGH_MONEY, ENOUGH_MONEY,
@ -15,6 +20,9 @@ public class EntryFeeResult {
CONSOLE_OR_BLOCK_COMMAND_SENDER CONSOLE_OR_BLOCK_COMMAND_SENDER
} }
/**
* Failure reasons for an entry fee check.
*/
public enum Failure implements FailureReason { public enum Failure implements FailureReason {
NOT_ENOUGH_MONEY(MVCorei18n.ENTRYCHECK_NOTENOUGHMONEY), NOT_ENOUGH_MONEY(MVCorei18n.ENTRYCHECK_NOTENOUGHMONEY),
CANNOT_PAY_ENTRY_FEE(MVCorei18n.ENTRYCHECK_CANNOTPAYENTRYFEE); CANNOT_PAY_ENTRY_FEE(MVCorei18n.ENTRYCHECK_CANNOTPAYENTRYFEE);

View File

@ -6,13 +6,22 @@ import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason; import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason; import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/**
* Result of a world player limit check.
*/
public class PlayerLimitResult { public class PlayerLimitResult {
/**
* Success reasons for a player limit check.
*/
public enum Success implements SuccessReason { public enum Success implements SuccessReason {
NO_PLAYERLIMIT, NO_PLAYERLIMIT,
WITHIN_PLAYERLIMIT, WITHIN_PLAYERLIMIT,
BYPASS_PLAYERLIMIT BYPASS_PLAYERLIMIT
} }
/**
* Failure reasons for a player limit check.
*/
public enum Failure implements FailureReason { public enum Failure implements FailureReason {
EXCEED_PLAYERLIMIT(MVCorei18n.ENTRYCHECK_EXCEEDPLAYERLIMIT); EXCEED_PLAYERLIMIT(MVCorei18n.ENTRYCHECK_EXCEEDPLAYERLIMIT);

View File

@ -6,12 +6,21 @@ import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason; import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason; import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/**
* Result of a world access check.
*/
public class WorldAccessResult { public class WorldAccessResult {
/**
* Success reasons for a world access check.
*/
public enum Success implements SuccessReason { public enum Success implements SuccessReason {
NO_ENFORCE_WORLD_ACCESS, NO_ENFORCE_WORLD_ACCESS,
HAS_WORLD_ACCESS HAS_WORLD_ACCESS
} }
/**
* Failure reasons for a world access check.
*/
public enum Failure implements FailureReason { public enum Failure implements FailureReason {
NO_WORLD_ACCESS(MVCorei18n.ENTRYCHECK_NOWORLDACCESS); NO_WORLD_ACCESS(MVCorei18n.ENTRYCHECK_NOWORLDACCESS);

View File

@ -9,6 +9,7 @@ import com.onarandombox.MultiverseCore.world.configuration.EntryFee;
import com.onarandombox.MultiverseCore.worldnew.LoadedMultiverseWorld; import com.onarandombox.MultiverseCore.worldnew.LoadedMultiverseWorld;
import com.onarandombox.MultiverseCore.worldnew.MultiverseWorld; import com.onarandombox.MultiverseCore.worldnew.MultiverseWorld;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.BlockCommandSender; import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
@ -16,8 +17,13 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import static com.onarandombox.MultiverseCore.utils.message.MessageReplacement.replace; import static com.onarandombox.MultiverseCore.utils.message.MessageReplacement.replace;
/**
* Checks if a player can enter a world.
*/
public class WorldEntryChecker { public class WorldEntryChecker {
private final @NotNull MVCoreConfig config; private final @NotNull MVCoreConfig config;
private final @NotNull MVEconomist economist; private final @NotNull MVEconomist economist;
@ -25,23 +31,39 @@ public class WorldEntryChecker {
private final @NotNull CommandSender sender; private final @NotNull CommandSender sender;
public WorldEntryChecker( WorldEntryChecker(
@NotNull MVCoreConfig config, @NotNull MVCoreConfig config,
@NotNull CorePermissionsChecker permissionsChecker, @NotNull CorePermissionsChecker permissionsChecker,
@NotNull MVEconomist economist, @NotNull MVEconomist economist,
@NotNull CommandSender sender @NotNull CommandSender sender) {
) {
this.config = config; this.config = config;
this.permissionsChecker = permissionsChecker; this.permissionsChecker = permissionsChecker;
this.economist = economist; this.economist = economist;
this.sender = sender; this.sender = sender;
} }
/**
* Checks if the sender have access to be in the world.
*
* @param world The world to check.
* @return The result of the check.
*/
public ResultChain canStayInWorld(@NotNull LoadedMultiverseWorld world) { public ResultChain canStayInWorld(@NotNull LoadedMultiverseWorld world) {
return canEnterWorld(null, world); return ResultChain.builder()
.then(() -> canAccessWorld(world))
.then(() -> isWithinPlayerLimit(world))
.build();
} }
public ResultChain canEnterWorld(@Nullable LoadedMultiverseWorld fromWorld, @NotNull LoadedMultiverseWorld toWorld) { /**
* Checks if the sender can enter the given world.
*
* @param fromWorld The world the sender is coming from.
* @param toWorld The world the sender is going to.
* @return The result of the check.
*/
public ResultChain canEnterWorld(
@Nullable LoadedMultiverseWorld fromWorld, @NotNull LoadedMultiverseWorld toWorld) {
return ResultChain.builder() return ResultChain.builder()
.then(() -> canAccessWorld(toWorld)) .then(() -> canAccessWorld(toWorld))
.then(() -> isWithinPlayerLimit(toWorld)) .then(() -> isWithinPlayerLimit(toWorld))
@ -50,6 +72,12 @@ public class WorldEntryChecker {
.build(); .build();
} }
/**
* Checks if the sender can access the given world.
*
* @param world The world to check.
* @return The result of the check.
*/
public Result<WorldAccessResult.Success, WorldAccessResult.Failure> canAccessWorld(@NotNull MultiverseWorld world) { public Result<WorldAccessResult.Success, WorldAccessResult.Failure> canAccessWorld(@NotNull MultiverseWorld world) {
if (!config.getEnforceAccess()) { if (!config.getEnforceAccess()) {
return Result.success(WorldAccessResult.Success.NO_ENFORCE_WORLD_ACCESS); return Result.success(WorldAccessResult.Success.NO_ENFORCE_WORLD_ACCESS);
@ -59,7 +87,14 @@ public class WorldEntryChecker {
: Result.failure(WorldAccessResult.Failure.NO_WORLD_ACCESS); : Result.failure(WorldAccessResult.Failure.NO_WORLD_ACCESS);
} }
public Result<PlayerLimitResult.Success, PlayerLimitResult.Failure> isWithinPlayerLimit(@NotNull LoadedMultiverseWorld world) { /**
* Checks if the sender is within the player limit of the given world.
*
* @param world The world to check.
* @return The result of the check.
*/
public Result<PlayerLimitResult.Success, PlayerLimitResult.Failure> isWithinPlayerLimit(
@NotNull LoadedMultiverseWorld world) {
final int playerLimit = world.getPlayerLimit(); final int playerLimit = world.getPlayerLimit();
if (playerLimit <= -1) { if (playerLimit <= -1) {
return Result.success(PlayerLimitResult.Success.NO_PLAYERLIMIT); return Result.success(PlayerLimitResult.Success.NO_PLAYERLIMIT);
@ -67,12 +102,23 @@ public class WorldEntryChecker {
if (permissionsChecker.hasPlayerLimitBypassPermission(sender, world)) { if (permissionsChecker.hasPlayerLimitBypassPermission(sender, world)) {
return Result.success(PlayerLimitResult.Success.BYPASS_PLAYERLIMIT); return Result.success(PlayerLimitResult.Success.BYPASS_PLAYERLIMIT);
} }
return playerLimit > world.getBukkitWorld().map(org.bukkit.World::getPlayers).map(java.util.Collection::size).getOrElse(0) int numberOfPlayersInWorld = world.getBukkitWorld().map(World::getPlayers)
.map(Collection::size)
.getOrElse(0);
return playerLimit > numberOfPlayersInWorld
? Result.success(PlayerLimitResult.Success.WITHIN_PLAYERLIMIT) ? Result.success(PlayerLimitResult.Success.WITHIN_PLAYERLIMIT)
: Result.failure(PlayerLimitResult.Failure.EXCEED_PLAYERLIMIT); : Result.failure(PlayerLimitResult.Failure.EXCEED_PLAYERLIMIT);
} }
public Result<BlacklistResult.Success, BlacklistResult.Failure> isNotBlacklisted(@Nullable LoadedMultiverseWorld fromWorld, @NotNull LoadedMultiverseWorld toWorld) { /**
* Checks if the sender is not blacklisted from the given world.
*
* @param fromWorld The world the sender is coming from.
* @param toWorld The world the sender is going to.
* @return The result of the check.
*/
public Result<BlacklistResult.Success, BlacklistResult.Failure> isNotBlacklisted(
@Nullable LoadedMultiverseWorld fromWorld, @NotNull LoadedMultiverseWorld toWorld) {
if (fromWorld == null) { if (fromWorld == null) {
return Result.success(BlacklistResult.Success.UNKNOWN_FROM_WORLD); return Result.success(BlacklistResult.Success.UNKNOWN_FROM_WORLD);
} }
@ -81,6 +127,12 @@ public class WorldEntryChecker {
: Result.success(BlacklistResult.Success.NOT_BLACKLISTED); : Result.success(BlacklistResult.Success.NOT_BLACKLISTED);
} }
/**
* Checks if the sender can pay the entry fee for the given world.
*
* @param world The world to check.
* @return The result of the check.
*/
public Result<EntryFeeResult.Success, EntryFeeResult.Failure> canPayEntryFee(LoadedMultiverseWorld world) { public Result<EntryFeeResult.Success, EntryFeeResult.Failure> canPayEntryFee(LoadedMultiverseWorld world) {
double price = world.getPrice(); double price = world.getPrice();
Material currency = world.getCurrency(); Material currency = world.getCurrency();
@ -98,6 +150,8 @@ public class WorldEntryChecker {
} }
return economist.isPlayerWealthyEnough(player, price, currency) return economist.isPlayerWealthyEnough(player, price, currency)
? Result.success(EntryFeeResult.Success.ENOUGH_MONEY) ? Result.success(EntryFeeResult.Success.ENOUGH_MONEY)
: Result.failure(EntryFeeResult.Failure.NOT_ENOUGH_MONEY, replace("{amount}").with("$##")); // TODO: Money formatting : Result.failure(EntryFeeResult.Failure.NOT_ENOUGH_MONEY,
replace("{amount}").with("$##"));
// TODO: Money formatting
} }
} }

View File

@ -19,8 +19,7 @@ public class WorldEntryCheckerProvider {
WorldEntryCheckerProvider( WorldEntryCheckerProvider(
@NotNull MVCoreConfig config, @NotNull MVCoreConfig config,
@NotNull MVEconomist economist, @NotNull MVEconomist economist,
@NotNull CorePermissionsChecker permissionsChecker @NotNull CorePermissionsChecker permissionsChecker) {
) {
this.config = config; this.config = config;
this.economist = economist; this.economist = economist;
this.permissionsChecker = permissionsChecker; this.permissionsChecker = permissionsChecker;

View File

@ -2,6 +2,7 @@ package com.onarandombox.MultiverseCore.worldnew.generators;
import com.dumptruckman.minecraft.util.Logging; import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.MultiverseCore;
import io.vavr.control.Try;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
@ -84,16 +85,14 @@ public class GeneratorProvider implements Listener {
*/ */
private boolean testIsGeneratorPlugin(Plugin plugin) { private boolean testIsGeneratorPlugin(Plugin plugin) {
String worldName = Bukkit.getWorlds().stream().findFirst().map(World::getName).orElse("world"); String worldName = Bukkit.getWorlds().stream().findFirst().map(World::getName).orElse("world");
try { return Try.of(() -> plugin.getDefaultWorldGenerator(worldName, "") != null)
return plugin.getDefaultWorldGenerator(worldName, "") != null; .recover(IllegalArgumentException.class, true)
} catch (IllegalArgumentException e) { .recover(throwable -> {
Logging.fine("Testing id is wrong, but it is probably a generator plugin: %s", plugin.getName()); Logging.warning("Plugin %s threw an exception when testing if it is a generator plugin!",
return true; plugin.getName());
} catch (Throwable t) { throwable.printStackTrace();
Logging.warning("Plugin %s threw an exception when testing if it is a generator plugin!", plugin.getName()); return false;
t.printStackTrace(); }).getOrElse(false);
return false;
}
} }
/** /**

View File

@ -2,6 +2,7 @@ package com.onarandombox.MultiverseCore.worldnew.helpers;
import com.dumptruckman.minecraft.util.Logging; import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.worldnew.LoadedMultiverseWorld; import com.onarandombox.MultiverseCore.worldnew.LoadedMultiverseWorld;
import io.vavr.control.Try;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.bukkit.World; import org.bukkit.World;
import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.annotations.Service;
@ -62,23 +63,17 @@ public interface DataStore<T> {
if (gameRuleMap == null) { if (gameRuleMap == null) {
return this; return this;
} }
world.getBukkitWorld().peek(bukkitWorld -> { world.getBukkitWorld().peek(bukkitWorld -> gameRuleMap.forEach((gameRule, value) -> {
gameRuleMap.forEach((gameRule, value) -> { setGameRuleValue(bukkitWorld, gameRule, value).onFailure(e -> {
if (!setGameRuleValue(bukkitWorld, gameRule, value)) { Logging.warning("Failed to set game rule " + gameRule.getName() + " to " + value);
Logging.warning("Failed to set game rule " + gameRule.getName() + " to " + value); e.printStackTrace();
}
}); });
}); }));
return this; return this;
} }
private <T> boolean setGameRuleValue(World world, GameRule<T> gameRule, Object value) { private <T> Try<Void> setGameRuleValue(World world, GameRule<T> gameRule, Object value) {
try { return Try.run(() -> world.setGameRule(gameRule, (T) value));
return world.setGameRule(gameRule, (T) value);
} catch (Exception e) {
Logging.fine(e.getMessage());
return false;
}
} }
} }
@ -94,11 +89,11 @@ public interface DataStore<T> {
@Override @Override
public WorldConfigStore copyFrom(LoadedMultiverseWorld world) { public WorldConfigStore copyFrom(LoadedMultiverseWorld world) {
this.configMap = new HashMap<>(); this.configMap = new HashMap<>();
world.getConfigurablePropertyNames().forEach(name -> { world.getConfigurablePropertyNames().forEach(name -> world.getProperty(name)
world.getProperty(name).peek(value -> configMap.put(name, value)).onFailure(e -> { .peek(value -> configMap.put(name, value)).onFailure(e -> {
Logging.warning("Failed to get property " + name + " from world " + world.getName() + ": " + e.getMessage()); Logging.warning("Failed to get property " + name + " from world "
}); + world.getName() + ": " + e.getMessage());
}); }));
return this; return this;
} }

View File

@ -22,6 +22,7 @@ public class DataTransfer<T> {
* Adds a {@link DataStore} to this {@link DataTransfer} instance. * Adds a {@link DataStore} to this {@link DataTransfer} instance.
* *
* @param dataStore The {@link DataStore} to add. * @param dataStore The {@link DataStore} to add.
* @param object The object to copy data from.
* @return This {@link DataTransfer} instance. * @return This {@link DataTransfer} instance.
*/ */
public DataTransfer<T> addDataStore(DataStore<T> dataStore, T object) { public DataTransfer<T> addDataStore(DataStore<T> dataStore, T object) {

View File

@ -19,13 +19,30 @@ import java.util.stream.Stream;
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES; import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
/**
* A helper class for manipulating files and folders.
*/
@Service @Service
public class FilesManipulator { public class FilesManipulator {
/**
* Deletes the given folder completely.
*
* @param file The folder to delete.
* @return A {@link Try} that will contain {@code null} if the folder was deleted successfully, or an exception if
* the folder could not be deleted.
*/
public Try<Void> deleteFolder(File file) { public Try<Void> deleteFolder(File file) {
return deleteFolder(file.toPath()); return deleteFolder(file.toPath());
} }
/**
* Deletes the given folder completely.
*
* @param path The folder to delete.
* @return A {@link Try} that will contain {@code null} if the folder was deleted successfully, or an exception if
* the folder could not be deleted.
*/
public Try<Void> deleteFolder(Path path) { public Try<Void> deleteFolder(Path path) {
try (Stream<Path> files = Files.walk(path)) { try (Stream<Path> files = Files.walk(path)) {
files.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); files.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
@ -37,27 +54,58 @@ public class FilesManipulator {
} }
} }
/**
* Copies all the content of the given folder to the given target folder.
*
* @param sourceDir The folder to copy.
* @param targetDir The target folder to copy to.
* @return A {@link Try} that will contain {@code null} if the folder was copied successfully, or an exception if
* the folder could not be copied.
*/
public Try<Void> copyFolder(File sourceDir, File targetDir) { public Try<Void> copyFolder(File sourceDir, File targetDir) {
return copyFolder(sourceDir.toPath(), targetDir.toPath(), Collections.emptyList()); return copyFolder(sourceDir.toPath(), targetDir.toPath(), Collections.emptyList());
} }
/**
* Copies most of the content of the given folder to the given target folder, except the list of excluded files
* specified.
*
* @param sourceDir The folder to copy.
* @param targetDir The target folder to copy to.
* @param excludeFiles The list of files to exclude from copying.
* @return A {@link Try} that will contain {@code null} if the folder was copied successfully, or an exception if
*/
public Try<Void> copyFolder(File sourceDir, File targetDir, List<String> excludeFiles) { public Try<Void> copyFolder(File sourceDir, File targetDir, List<String> excludeFiles) {
return copyFolder(sourceDir.toPath(), targetDir.toPath(), excludeFiles); return copyFolder(sourceDir.toPath(), targetDir.toPath(), excludeFiles);
} }
/**
* Copies all the content of the given folder to the given target folder.
*
* @param sourceDir The folder to copy.
* @param targetDir The target folder to copy to.
* @return A {@link Try} that will contain {@code null} if the folder was copied successfully, or an exception if
* the folder could not be copied.
*/
public Try<Void> copyFolder(Path sourceDir, Path targetDir) { public Try<Void> copyFolder(Path sourceDir, Path targetDir) {
return copyFolder(sourceDir, targetDir, Collections.emptyList()); return copyFolder(sourceDir, targetDir, Collections.emptyList());
} }
/**
* Copies most of the content of the given folder to the given target folder, except the list of excluded files
* specified.
*
* @param sourceDir The folder to copy.
* @param targetDir The target folder to copy to.
* @param excludeFiles The list of files to exclude from copying.
* @return A {@link Try} that will contain {@code null} if the folder was copied successfully, or an exception if
*/
public Try<Void> copyFolder(Path sourceDir, Path targetDir, List<String> excludeFiles) { public Try<Void> copyFolder(Path sourceDir, Path targetDir, List<String> excludeFiles) {
try { return Try.run(() -> Files.walkFileTree(sourceDir, new CopyDirFileVisitor(sourceDir, targetDir, excludeFiles)))
Files.walkFileTree(sourceDir, new CopyDirFileVisitor(sourceDir, targetDir, excludeFiles)); .onFailure(e -> {
return Try.success(null); Logging.severe("Failed to copy folder: " + sourceDir.toAbsolutePath());
} catch (IOException e) { e.printStackTrace();
Logging.severe("Failed to copy folder: " + sourceDir.toAbsolutePath()); });
e.printStackTrace();
return Try.failure(e);
}
} }
private static final class CopyDirFileVisitor extends SimpleFileVisitor<Path> { private static final class CopyDirFileVisitor extends SimpleFileVisitor<Path> {

View File

@ -52,12 +52,12 @@ public final class CloneWorldOptions implements KeepWorldSettingsOptions {
/** /**
* Sets whether to keep the game rule of the world during cloning. * Sets whether to keep the game rule of the world during cloning.
* *
* @param keepGameRule Whether to keep the game rule of the world during cloning. * @param keepGameRuleInput Whether to keep the game rule of the world during cloning.
* @return This {@link CloneWorldOptions} instance. * @return This {@link CloneWorldOptions} instance.
*/ */
@Override @Override
public @NotNull CloneWorldOptions keepGameRule(boolean keepGameRule) { public @NotNull CloneWorldOptions keepGameRule(boolean keepGameRuleInput) {
this.keepGameRule = keepGameRule; this.keepGameRule = keepGameRuleInput;
return this; return this;
} }
@ -71,9 +71,15 @@ public final class CloneWorldOptions implements KeepWorldSettingsOptions {
return keepGameRule; return keepGameRule;
} }
/**
* Sets whether to keep the world config of the world during cloning.
*
* @param keepWorldConfigInput Whether to keep the world config of the world.
* @return This {@link CloneWorldOptions} instance.
*/
@Override @Override
public @NotNull CloneWorldOptions keepWorldConfig(boolean keepWorldConfig) { public @NotNull CloneWorldOptions keepWorldConfig(boolean keepWorldConfigInput) {
this.keepWorldConfig = keepWorldConfig; this.keepWorldConfig = keepWorldConfigInput;
return this; return this;
} }
@ -87,9 +93,16 @@ public final class CloneWorldOptions implements KeepWorldSettingsOptions {
return keepWorldConfig; return keepWorldConfig;
} }
/**
* Sets whether to keep the world border of the world during cloning.
*
* @param keepWorldBorderInput Whether to keep the world border of the world.
* @return This {@link CloneWorldOptions} instance.
*/
@Override @Override
public @NotNull CloneWorldOptions keepWorldBorder(boolean keepWorldBorder) { public @NotNull CloneWorldOptions keepWorldBorder(boolean keepWorldBorderInput) {
this.keepWorldBorder = keepWorldBorder; this.keepWorldBorder = keepWorldBorderInput;
return this; return this;
} }

View File

@ -52,11 +52,11 @@ public class CreateWorldOptions {
/** /**
* Sets the environment of the world to create. * Sets the environment of the world to create.
* *
* @param environment The environment of the world to create. * @param environmentInput The environment of the world to create.
* @return This {@link CreateWorldOptions} instance. * @return This {@link CreateWorldOptions} instance.
*/ */
public @NotNull CreateWorldOptions environment(@NotNull World.Environment environment) { public @NotNull CreateWorldOptions environment(@NotNull World.Environment environmentInput) {
this.environment = environment; this.environment = environmentInput;
return this; return this;
} }
@ -72,11 +72,11 @@ public class CreateWorldOptions {
/** /**
* Sets whether structures such as NPC villages should be generated. * Sets whether structures such as NPC villages should be generated.
* *
* @param generateStructures Whether structures such as NPC villages should be generated. * @param generateStructuresInput Whether structures such as NPC villages should be generated.
* @return This {@link CreateWorldOptions} instance. * @return This {@link CreateWorldOptions} instance.
*/ */
public @NotNull CreateWorldOptions generateStructures(boolean generateStructures) { public @NotNull CreateWorldOptions generateStructures(boolean generateStructuresInput) {
this.generateStructures = generateStructures; this.generateStructures = generateStructuresInput;
return this; return this;
} }
@ -92,11 +92,11 @@ public class CreateWorldOptions {
/** /**
* Sets the custom generator plugin and its parameters. * Sets the custom generator plugin and its parameters.
* *
* @param generator The custom generator plugin and its parameters. * @param generatorInput The custom generator plugin and its parameters.
* @return This {@link CreateWorldOptions} instance. * @return This {@link CreateWorldOptions} instance.
*/ */
public @NotNull CreateWorldOptions generator(@Nullable String generator) { public @NotNull CreateWorldOptions generator(@Nullable String generatorInput) {
this.generator = generator; this.generator = generatorInput;
return this; return this;
} }
@ -113,17 +113,17 @@ public class CreateWorldOptions {
* Sets the seed of the world to create. If the seed is a number, it will be parsed as a long. Otherwise, it will be * Sets the seed of the world to create. If the seed is a number, it will be parsed as a long. Otherwise, it will be
* hashed. * hashed.
* *
* @param seed The seed of the world to create. * @param seedInput The seed of the world to create.
* @return This {@link CreateWorldOptions} instance. * @return This {@link CreateWorldOptions} instance.
*/ */
public @NotNull CreateWorldOptions seed(@Nullable String seed) { public @NotNull CreateWorldOptions seed(@Nullable String seedInput) {
if (seed == null) { if (seedInput == null) {
return this; return this;
} }
try { try {
this.seed = Long.parseLong(seed); this.seed = Long.parseLong(seedInput);
} catch (NumberFormatException numberformatexception) { } catch (NumberFormatException numberformatexception) {
this.seed = seed.hashCode(); this.seed = seedInput.hashCode();
} }
return this; return this;
} }
@ -131,11 +131,11 @@ public class CreateWorldOptions {
/** /**
* Sets the seed of the world to create. * Sets the seed of the world to create.
* *
* @param seed The seed of the world to create. * @param seedInput The seed of the world to create.
* @return This {@link CreateWorldOptions} instance. * @return This {@link CreateWorldOptions} instance.
*/ */
public @NotNull CreateWorldOptions seed(long seed) { public @NotNull CreateWorldOptions seed(long seedInput) {
this.seed = seed; this.seed = seedInput;
return this; return this;
} }
@ -151,11 +151,11 @@ public class CreateWorldOptions {
/** /**
* Sets whether multiverse will search for a safe spawn location. * Sets whether multiverse will search for a safe spawn location.
* *
* @param useSpawnAdjust Whether multiverse will search for a safe spawn location. * @param useSpawnAdjustInput Whether multiverse will search for a safe spawn location.
* @return This {@link CreateWorldOptions} instance. * @return This {@link CreateWorldOptions} instance.
*/ */
public @NotNull CreateWorldOptions useSpawnAdjust(boolean useSpawnAdjust) { public @NotNull CreateWorldOptions useSpawnAdjust(boolean useSpawnAdjustInput) {
this.useSpawnAdjust = useSpawnAdjust; this.useSpawnAdjust = useSpawnAdjustInput;
return this; return this;
} }
@ -171,11 +171,11 @@ public class CreateWorldOptions {
/** /**
* Sets the world type. * Sets the world type.
* *
* @param worldType The world type. * @param worldTypeInput The world type.
* @return This {@link CreateWorldOptions} instance. * @return This {@link CreateWorldOptions} instance.
*/ */
public @NotNull CreateWorldOptions worldType(@NotNull WorldType worldType) { public @NotNull CreateWorldOptions worldType(@NotNull WorldType worldTypeInput) {
this.worldType = worldType; this.worldType = worldTypeInput;
return this; return this;
} }

View File

@ -40,11 +40,11 @@ public class ImportWorldOptions {
/** /**
* Sets the environment of the world to create. * Sets the environment of the world to create.
* *
* @param environment The environment of the world to create. * @param environmentInput The environment of the world to create.
* @return This {@link ImportWorldOptions} instance. * @return This {@link ImportWorldOptions} instance.
*/ */
public @NotNull ImportWorldOptions environment(@NotNull World.Environment environment) { public @NotNull ImportWorldOptions environment(@NotNull World.Environment environmentInput) {
this.environment = environment; this.environment = environmentInput;
return this; return this;
} }
@ -60,11 +60,11 @@ public class ImportWorldOptions {
/** /**
* Sets the custom generator plugin and its parameters. * Sets the custom generator plugin and its parameters.
* *
* @param generator The custom generator plugin and its parameters. * @param generatorInput The custom generator plugin and its parameters.
* @return This {@link ImportWorldOptions} instance. * @return This {@link ImportWorldOptions} instance.
*/ */
public @NotNull ImportWorldOptions generator(@Nullable String generator) { public @NotNull ImportWorldOptions generator(@Nullable String generatorInput) {
this.generator = generator; this.generator = generatorInput;
return this; return this;
} }
@ -80,11 +80,11 @@ public class ImportWorldOptions {
/** /**
* Sets whether multiverse will search for a safe spawn location. * Sets whether multiverse will search for a safe spawn location.
* *
* @param useSpawnAdjust Whether multiverse will search for a safe spawn location. * @param useSpawnAdjustInput Whether multiverse will search for a safe spawn location.
* @return This {@link ImportWorldOptions} instance. * @return This {@link ImportWorldOptions} instance.
*/ */
public @NotNull ImportWorldOptions useSpawnAdjust(boolean useSpawnAdjust) { public @NotNull ImportWorldOptions useSpawnAdjust(boolean useSpawnAdjustInput) {
this.useSpawnAdjust = useSpawnAdjust; this.useSpawnAdjust = useSpawnAdjustInput;
return this; return this;
} }

View File

@ -2,15 +2,18 @@ package com.onarandombox.MultiverseCore.worldnew.options;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/**
* Options for customizing the keeping of world settings. Used by clone and regen.
*/
public sealed interface KeepWorldSettingsOptions permits CloneWorldOptions, RegenWorldOptions { public sealed interface KeepWorldSettingsOptions permits CloneWorldOptions, RegenWorldOptions {
/** /**
* Sets whether to keep the game rule of the world. * Sets whether to keep the game rule of the world.
* *
* @param keepGameRule Whether to keep the game rule of the world. * @param keepGameRuleInput Whether to keep the game rule of the world.
* @return This {@link KeepWorldSettingsOptions} instance. * @return This {@link KeepWorldSettingsOptions} instance.
*/ */
@NotNull KeepWorldSettingsOptions keepGameRule(boolean keepGameRule); @NotNull KeepWorldSettingsOptions keepGameRule(boolean keepGameRuleInput);
/** /**
* Gets whether to keep the game rule of the world. * Gets whether to keep the game rule of the world.
@ -22,10 +25,10 @@ public sealed interface KeepWorldSettingsOptions permits CloneWorldOptions, Rege
/** /**
* Sets whether to keep the world config of the world. * Sets whether to keep the world config of the world.
* *
* @param keepWorldConfig Whether to keep the world config of the world. * @param keepWorldConfigInput Whether to keep the world config of the world.
* @return This {@link KeepWorldSettingsOptions} instance. * @return This {@link KeepWorldSettingsOptions} instance.
*/ */
@NotNull KeepWorldSettingsOptions keepWorldConfig(boolean keepWorldConfig); @NotNull KeepWorldSettingsOptions keepWorldConfig(boolean keepWorldConfigInput);
/** /**
* Gets whether to keep the world config of the world. * Gets whether to keep the world config of the world.
@ -37,10 +40,10 @@ public sealed interface KeepWorldSettingsOptions permits CloneWorldOptions, Rege
/** /**
* Sets whether to keep the world border of the world. * Sets whether to keep the world border of the world.
* *
* @param keepWorldBorder Whether to keep the world border of the world. * @param keepWorldBorderInput Whether to keep the world border of the world.
* @return This {@link KeepWorldSettingsOptions} instance. * @return This {@link KeepWorldSettingsOptions} instance.
*/ */
@NotNull KeepWorldSettingsOptions keepWorldBorder(boolean keepWorldBorder); @NotNull KeepWorldSettingsOptions keepWorldBorder(boolean keepWorldBorderInput);
/** /**
* Gets whether to keep the world border of the world. * Gets whether to keep the world border of the world.

View File

@ -45,12 +45,12 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
/** /**
* Sets whether to keep the game rule of the world during regeneration. * Sets whether to keep the game rule of the world during regeneration.
* *
* @param keepGameRule Whether to keep the game rule of the world during regeneration. * @param keepGameRuleInput Whether to keep the game rule of the world during regeneration.
* @return This {@link RegenWorldOptions} instance. * @return This {@link RegenWorldOptions} instance.
*/ */
@Override @Override
public @NotNull RegenWorldOptions keepGameRule(boolean keepGameRule) { public @NotNull RegenWorldOptions keepGameRule(boolean keepGameRuleInput) {
this.keepGameRule = keepGameRule; this.keepGameRule = keepGameRuleInput;
return this; return this;
} }
@ -67,12 +67,12 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
/** /**
* Sets whether to keep the world config of the world during regeneration. * Sets whether to keep the world config of the world during regeneration.
* *
* @param keepWorldConfig Whether to keep the world config of the world during regeneration. * @param keepWorldConfigInput Whether to keep the world config of the world during regeneration.
* @return This {@link RegenWorldOptions} instance. * @return This {@link RegenWorldOptions} instance.
*/ */
@Override @Override
public @NotNull RegenWorldOptions keepWorldConfig(boolean keepWorldConfig) { public @NotNull RegenWorldOptions keepWorldConfig(boolean keepWorldConfigInput) {
this.keepWorldConfig = keepWorldConfig; this.keepWorldConfig = keepWorldConfigInput;
return this; return this;
} }
@ -81,12 +81,20 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
* *
* @return Whether to keep the world config of the world during regeneration. * @return Whether to keep the world config of the world during regeneration.
*/ */
@Override
public boolean keepWorldConfig() { public boolean keepWorldConfig() {
return keepWorldConfig; return keepWorldConfig;
} }
public @NotNull RegenWorldOptions keepWorldBorder(boolean keepWorldBorder) { /**
this.keepWorldBorder = keepWorldBorder; * Sets whether to keep the world border of the world during regeneration.
*
* @param keepWorldBorderInput Whether to keep the world border of the world.
* @return This {@link RegenWorldOptions} instance.
*/
@Override
public @NotNull RegenWorldOptions keepWorldBorder(boolean keepWorldBorderInput) {
this.keepWorldBorder = keepWorldBorderInput;
return this; return this;
} }
@ -95,6 +103,7 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
* *
* @return Whether to keep the world border of the world during regeneration. * @return Whether to keep the world border of the world during regeneration.
*/ */
@Override
public boolean keepWorldBorder() { public boolean keepWorldBorder() {
return keepWorldBorder; return keepWorldBorder;
} }
@ -102,14 +111,14 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
/** /**
* Sets whether to use a random seed for the world to regenerate. Cannot be set to true when seed is set. * Sets whether to use a random seed for the world to regenerate. Cannot be set to true when seed is set.
* *
* @param randomSeed Whether to use a random seed for the world to regenerate. * @param randomSeedInput Whether to use a random seed for the world to regenerate.
* @return This {@link RegenWorldOptions} instance. * @return This {@link RegenWorldOptions} instance.
*/ */
public @NotNull RegenWorldOptions randomSeed(boolean randomSeed) { public @NotNull RegenWorldOptions randomSeed(boolean randomSeedInput) {
if (randomSeed && seed != Long.MIN_VALUE) { if (randomSeedInput && seed != Long.MIN_VALUE) {
throw new IllegalStateException("Cannot set randomSeed to true when seed is set"); throw new IllegalStateException("Cannot set randomSeed to true when seed is set");
} }
this.randomSeed = randomSeed; this.randomSeed = randomSeedInput;
return this; return this;
} }
@ -125,11 +134,11 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
/** /**
* Sets the seed for the world to regenerate. Random seed will be disabled. * Sets the seed for the world to regenerate. Random seed will be disabled.
* *
* @param seed The seed for the world to regenerate. * @param seedInput The seed for the world to regenerate.
* @return This {@link RegenWorldOptions} instance. * @return This {@link RegenWorldOptions} instance.
*/ */
public @NotNull RegenWorldOptions seed(@Nullable String seed) { public @NotNull RegenWorldOptions seed(@Nullable String seedInput) {
if (seed == null) { if (seedInput == null) {
this.seed = Long.MIN_VALUE; this.seed = Long.MIN_VALUE;
return this; return this;
} }
@ -137,9 +146,9 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
randomSeed(false); randomSeed(false);
} }
try { try {
this.seed = Long.parseLong(seed); this.seed = Long.parseLong(seedInput);
} catch (NumberFormatException numberformatexception) { } catch (NumberFormatException numberformatexception) {
this.seed = seed.hashCode(); this.seed = seedInput.hashCode();
} }
return this; return this;
} }
@ -147,11 +156,11 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
/** /**
* Sets the seed for the world to regenerate. Random seed will be disabled. * Sets the seed for the world to regenerate. Random seed will be disabled.
* *
* @param seed The seed for the world to regenerate. * @param seedInput The seed for the world to regenerate.
* @return This {@link RegenWorldOptions} instance. * @return This {@link RegenWorldOptions} instance.
*/ */
public @NotNull RegenWorldOptions seed(long seed) { public @NotNull RegenWorldOptions seed(long seedInput) {
this.seed = seed; this.seed = seedInput;
return this; return this;
} }
@ -163,8 +172,7 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
public long seed() { public long seed() {
if (randomSeed) { if (randomSeed) {
return new Random().nextLong(); return new Random().nextLong();
} } else if (seed == Long.MIN_VALUE) {
if (seed == Long.MIN_VALUE) {
return world.getSeed(); return world.getSeed();
} }
return seed; return seed;

View File

@ -37,11 +37,11 @@ public class UnloadWorldOptions {
/** /**
* Sets whether to teleport the players out from the world before unloading. * Sets whether to teleport the players out from the world before unloading.
* *
* @param removePlayers Whether to remove players from the world before unloading. * @param removePlayersInput Whether to remove players from the world before unloading.
* @return This {@link UnloadWorldOptions} instance. * @return This {@link UnloadWorldOptions} instance.
*/ */
public UnloadWorldOptions removePlayers(boolean removePlayers) { public UnloadWorldOptions removePlayers(boolean removePlayersInput) {
this.removePlayers = removePlayers; this.removePlayers = removePlayersInput;
return this; return this;
} }
@ -57,11 +57,11 @@ public class UnloadWorldOptions {
/** /**
* Sets whether to save the bukkit world before unloading. * Sets whether to save the bukkit world before unloading.
* *
* @param saveBukkitWorld Whether to save the bukkit world before unloading. * @param saveBukkitWorldInput Whether to save the bukkit world before unloading.
* @return This {@link UnloadWorldOptions} instance. * @return This {@link UnloadWorldOptions} instance.
*/ */
public UnloadWorldOptions saveBukkitWorld(boolean saveBukkitWorld) { public UnloadWorldOptions saveBukkitWorld(boolean saveBukkitWorldInput) {
this.saveBukkitWorld = saveBukkitWorld; this.saveBukkitWorld = saveBukkitWorldInput;
return this; return this;
} }