From ffec23c9ed789a3e7dfc372386f6e1099a76b845 Mon Sep 17 00:00:00 2001
From: Ben Woo <30431861+benwoo1110@users.noreply.github.com>
Date: Mon, 11 Sep 2023 21:52:16 +0800
Subject: [PATCH] Add docs and fix more checkstyles
---
config/mv_checks.xml | 2 +-
.../worldnew/LoadedMultiverseWorld.java | 32 +-
.../worldnew/MultiverseWorld.java | 355 ++++++++++++++++++
.../worldnew/config/NullLocation.java | 18 +-
.../worldnew/config/SpawnLocation.java | 43 ++-
.../worldnew/config/WorldConfig.java | 2 +-
.../worldnew/config/WorldConfigNodes.java | 2 +-
.../worldnew/config/WorldsConfigManager.java | 2 +-
.../worldnew/entrycheck/BlacklistResult.java | 9 +
.../worldnew/entrycheck/EntryFeeResult.java | 10 +-
.../entrycheck/PlayerLimitResult.java | 9 +
.../entrycheck/WorldAccessResult.java | 9 +
.../entrycheck/WorldEntryChecker.java | 72 +++-
.../entrycheck/WorldEntryCheckerProvider.java | 3 +-
.../generators/GeneratorProvider.java | 19 +-
.../worldnew/helpers/DataStore.java | 31 +-
.../worldnew/helpers/DataTransfer.java | 1 +
.../worldnew/helpers/FilesManipulator.java | 64 +++-
.../worldnew/options/CloneWorldOptions.java | 27 +-
.../worldnew/options/CreateWorldOptions.java | 46 +--
.../worldnew/options/ImportWorldOptions.java | 18 +-
.../options/KeepWorldSettingsOptions.java | 15 +-
.../worldnew/options/RegenWorldOptions.java | 52 +--
.../worldnew/options/UnloadWorldOptions.java | 12 +-
24 files changed, 713 insertions(+), 140 deletions(-)
diff --git a/config/mv_checks.xml b/config/mv_checks.xml
index 994e530d..11814481 100644
--- a/config/mv_checks.xml
+++ b/config/mv_checks.xml
@@ -442,7 +442,7 @@
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
-
+
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/LoadedMultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/LoadedMultiverseWorld.java
index a4d58c6c..1bf6f19e 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/LoadedMultiverseWorld.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/LoadedMultiverseWorld.java
@@ -18,6 +18,9 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
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 {
private static final int SPAWN_LOCATION_SEARCH_TOLERANCE = 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 BlockSafety blockSafety;
- private final SafeTTeleporter safeTTeleporter;
+ private final SafeTTeleporter safetyTeleporter;
private final LocationManipulation locationManipulation;
LoadedMultiverseWorld(
@NotNull World world,
@NotNull WorldConfig worldConfig,
@NotNull BlockSafety blockSafety,
- @NotNull SafeTTeleporter safeTTeleporter,
+ @NotNull SafeTTeleporter safetyTeleporter,
@NotNull LocationManipulation locationManipulation) {
super(world.getName(), worldConfig);
this.worldUid = world.getUID();
this.blockSafety = blockSafety;
- this.safeTTeleporter = safeTTeleporter;
+ this.safetyTeleporter = safetyTeleporter;
this.locationManipulation = locationManipulation;
setupWorldConfig(world);
@@ -78,7 +81,7 @@ public class LoadedMultiverseWorld extends MultiverseWorld {
// 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("Original Location: " + locationManipulation.strCoordsRaw(location));
- Location newSpawn = safeTTeleporter.getSafeLocation(location,
+ Location newSpawn = safetyTeleporter.getSafeLocation(location,
SPAWN_LOCATION_SEARCH_TOLERANCE, SPAWN_LOCATION_SEARCH_RADIUS);
// I think we could also do this, as I think this is what Notch does.
// Not sure how it will work in the nether...
@@ -103,18 +106,39 @@ public class LoadedMultiverseWorld extends MultiverseWorld {
return location;
}
+ /**
+ * Gets the Bukkit world object that this world describes.
+ *
+ * @return Bukkit world object.
+ */
public Option getBukkitWorld() {
return Option.of(Bukkit.getWorld(worldUid));
}
+ /**
+ * Gets the type of this world.
+ *
+ * @return Type of this world.
+ */
public Option getWorldType() {
+ //noinspection deprecation
return getBukkitWorld().map(World::getWorldType);
}
+ /**
+ * Gets whether or not structures are being generated.
+ *
+ * @return True if structures are being generated.
+ */
public Option 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> getPlayers() {
return getBukkitWorld().map(World::getPlayers);
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/MultiverseWorld.java
index b5ddc7df..4a7df261 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/MultiverseWorld.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/MultiverseWorld.java
@@ -15,6 +15,9 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
+/**
+ * Represents a world handled by Multiverse which has all the custom properties provided by Multiverse.
+ */
public class MultiverseWorld {
protected final String worldName;
@@ -25,10 +28,23 @@ public class MultiverseWorld {
this.worldConfig = worldConfig;
}
+ /**
+ * Gets the name of this world. The name cannot be changed.
+ *
+ * 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() {
return worldName;
}
+ /**
+ * Gets whether this world is loaded.
+ *
+ * @return True if the world is loaded, else false.
+ */
public boolean isLoaded() {
return worldConfig.hasMVWorld();
}
@@ -45,242 +61,581 @@ public class MultiverseWorld {
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() {
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 setAdjustSpawn(boolean adjustSpawn) {
return worldConfig.setAdjustSpawn(adjustSpawn);
}
+ /**
+ * Gets the alias of this world.
+ *
+ * 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() {
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 setAlias(String 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() {
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 setAllowFlight(boolean 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() {
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 setAllowWeather(boolean 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() {
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 setAutoHeal(boolean 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() {
return worldConfig.getAutoLoad();
}
+ /**
+ * Sets whether or not Multiverse should auto-load this world.
+ *
+ * True is default.
+ *
+ * @param autoLoad True if multiverse should autoload this world the spawn, false if not.
+ */
public Try setAutoLoad(boolean 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() {
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.
+ *
+ * True is default.
+ *
+ * @param bedRespawn True if players dying in this world respawn at their bed.
+ */
public Try setBedRespawn(boolean 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() {
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 setCurrency(Material currency) {
return worldConfig.setEntryFeeCurrency(currency);
}
+ /**
+ * Gets the difficulty of this world.
+ *
+ * @return The difficulty of this world.
+ */
public Difficulty 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 setDifficulty(Difficulty 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() {
return worldConfig.getEnvironment();
}
+ /**
+ * Gets the GameMode of this world.
+ *
+ * @return The GameMode of this world.
+ */
public GameMode getGameMode() {
return worldConfig.getGameMode();
}
+ /**
+ * Sets the game mode of this world.
+ *
+ * @param gameMode The new {@link GameMode}.
+ */
public Try setGameMode(GameMode 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() {
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() {
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 setHidden(boolean 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() {
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 setHunger(boolean 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() {
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 setKeepSpawnInMemory(boolean 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() {
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 setPlayerLimit(int 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() {
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 setPortalForm(AllowedPortalType 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() {
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 setPrice(double 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() {
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 setPvp(boolean 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() {
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() {
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 setRespawnWorld(World respawnWorld) {
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 setRespawnWorld(MultiverseWorld respawnWorld) {
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 setRespawnWorld(String 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() {
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 setScale(double 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() {
return worldConfig.getSeed();
}
+ /**
+ * Gets the spawn location of this world.
+ *
+ * @return The spawn location of this world.
+ */
public Location getSpawnLocation() {
return worldConfig.getSpawnLocation();
}
+ /**
+ * Sets the spawn location for a world.
+ *
+ * @param spawnLocation The spawn location for a world.
+ */
public Try setSpawnLocation(Location 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() {
return worldConfig.getSpawningAnimals();
}
+ /**
+ * Sets whether or not animals can spawn.
+ *
+ * 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 setSpawningAnimals(boolean spawningAnimals) {
return worldConfig.setSpawningAnimals(spawningAnimals);
}
+ /**
+ * Gets the amount of ticks between animal spawns.
+ *
+ * @return The amount of ticks between animal spawns.
+ */
public int 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 setSpawningAnimalsTicks(int 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 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 setSpawningAnimalsExceptions(List 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() {
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 setSpawningMonsters(boolean spawningMonsters) {
return worldConfig.setSpawningMonsters(spawningMonsters);
}
+ /**
+ * Gets the amount of ticks between monster spawns.
+ *
+ * @return The amount of ticks between monster spawns.
+ */
public int 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 setSpawningMonstersTicks(int 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 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 setSpawningMonstersExceptions(List 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 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 setWorldBlacklist(List worldBlacklist) {
return worldConfig.setWorldBlacklist(worldBlacklist);
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/NullLocation.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/NullLocation.java
index 8b20e0a0..ffba0b0f 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/NullLocation.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/NullLocation.java
@@ -14,7 +14,18 @@ import java.util.Map;
*/
@SerializableAs("MVNullLocation (It's a bug if you see this in your config file)")
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);
}
@@ -48,6 +59,11 @@ public final class NullLocation extends SpawnLocation {
return -1;
}
+ @Override
+ public boolean equals(Object obj) {
+ return false;
+ }
+
@Override
public String toString() {
return "Location{null}";
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/SpawnLocation.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/SpawnLocation.java
index 4e418f1c..cf8f087a 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/SpawnLocation.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/SpawnLocation.java
@@ -1,10 +1,5 @@
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.Location;
import org.bukkit.World;
@@ -13,6 +8,11 @@ import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs;
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}
* 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 {
private Reference 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) {
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) {
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) {
this(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
}
@@ -54,8 +75,9 @@ public class SpawnLocation extends Location implements ConfigurationSerializable
*/
@Override
public @NotNull Chunk getChunk() {
- if (this.worldRef != null && this.worldRef.get() != null) {
- return this.worldRef.get().getChunkAt(this);
+ World world = this.worldRef != null ? this.worldRef.get() : null;
+ if (world != null) {
+ return world.getChunkAt(this);
}
throw new IllegalStateException("World is null");
}
@@ -64,9 +86,10 @@ public class SpawnLocation extends Location implements ConfigurationSerializable
* {@inheritDoc}
*/
@Override
- public Block getBlock() {
- if (this.worldRef != null && this.worldRef.get() != null) {
- return this.worldRef.get().getBlockAt(this);
+ public @NotNull Block getBlock() {
+ World world = this.worldRef != null ? this.worldRef.get() : null;
+ if (world != null) {
+ return world.getBlockAt(this);
}
throw new IllegalStateException("World is null");
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java
index f587140b..f8569c1c 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfig.java
@@ -33,7 +33,7 @@ public final class WorldConfig {
private final WorldConfigNodes configNodes;
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.configNodes = new WorldConfigNodes();
this.configHandle = ConfigurationSectionHandle.builder(configSection)
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java
index 364c76e0..9930767c 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldConfigNodes.java
@@ -155,7 +155,7 @@ public class WorldConfigNodes {
.build());
final ConfigNode SPAWN_LOCATION = node(ConfigNode.builder("spawn-location", Location.class)
- .defaultValue(new NullLocation())
+ .defaultValue(NullLocation.get())
.name(null)
.onSetValue((oldValue, newValue) -> {
if (world == null) return;
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigManager.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigManager.java
index 521b3d2a..8c815db5 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigManager.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/config/WorldsConfigManager.java
@@ -200,7 +200,7 @@ public final class WorldsConfigManager {
? worldsConfig.getConfigurationSection(worldName) : worldsConfig.createSection(worldName);
}
- private final class ConfigMigratedException extends RuntimeException {
+ private static final class ConfigMigratedException extends RuntimeException {
private ConfigMigratedException() {
super("Config migrated");
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/BlacklistResult.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/BlacklistResult.java
index 8ec65fed..78bb25ec 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/BlacklistResult.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/BlacklistResult.java
@@ -6,13 +6,22 @@ import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
+/**
+ * Result of a world blacklist check.
+ */
public class BlacklistResult {
+ /**
+ * Success reasons for a blacklist check.
+ */
public enum Success implements SuccessReason {
UNKNOWN_FROM_WORLD,
BYPASSED_BLACKLISTED,
NOT_BLACKLISTED
}
+ /**
+ * Failure reasons for a blacklist check.
+ */
public enum Failure implements FailureReason {
BLACKLISTED(MVCorei18n.ENTRYCHECK_BLACKLISTED);
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/EntryFeeResult.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/EntryFeeResult.java
index 663c599a..d81bb700 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/EntryFeeResult.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/EntryFeeResult.java
@@ -1,13 +1,18 @@
package com.onarandombox.MultiverseCore.worldnew.entrycheck;
-
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
+/**
+ * Result of a world entry fee check.
+ */
public class EntryFeeResult {
+ /**
+ * Success reasons for an entry fee check.
+ */
public enum Success implements SuccessReason {
FREE_ENTRY,
ENOUGH_MONEY,
@@ -15,6 +20,9 @@ public class EntryFeeResult {
CONSOLE_OR_BLOCK_COMMAND_SENDER
}
+ /**
+ * Failure reasons for an entry fee check.
+ */
public enum Failure implements FailureReason {
NOT_ENOUGH_MONEY(MVCorei18n.ENTRYCHECK_NOTENOUGHMONEY),
CANNOT_PAY_ENTRY_FEE(MVCorei18n.ENTRYCHECK_CANNOTPAYENTRYFEE);
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/PlayerLimitResult.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/PlayerLimitResult.java
index 54305f99..a76be05f 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/PlayerLimitResult.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/PlayerLimitResult.java
@@ -6,13 +6,22 @@ import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
+/**
+ * Result of a world player limit check.
+ */
public class PlayerLimitResult {
+ /**
+ * Success reasons for a player limit check.
+ */
public enum Success implements SuccessReason {
NO_PLAYERLIMIT,
WITHIN_PLAYERLIMIT,
BYPASS_PLAYERLIMIT
}
+ /**
+ * Failure reasons for a player limit check.
+ */
public enum Failure implements FailureReason {
EXCEED_PLAYERLIMIT(MVCorei18n.ENTRYCHECK_EXCEEDPLAYERLIMIT);
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldAccessResult.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldAccessResult.java
index e140aba2..b765ac9b 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldAccessResult.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldAccessResult.java
@@ -6,12 +6,21 @@ import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
+/**
+ * Result of a world access check.
+ */
public class WorldAccessResult {
+ /**
+ * Success reasons for a world access check.
+ */
public enum Success implements SuccessReason {
NO_ENFORCE_WORLD_ACCESS,
HAS_WORLD_ACCESS
}
+ /**
+ * Failure reasons for a world access check.
+ */
public enum Failure implements FailureReason {
NO_WORLD_ACCESS(MVCorei18n.ENTRYCHECK_NOWORLDACCESS);
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldEntryChecker.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldEntryChecker.java
index 47b7faae..0c82c11c 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldEntryChecker.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldEntryChecker.java
@@ -9,6 +9,7 @@ import com.onarandombox.MultiverseCore.world.configuration.EntryFee;
import com.onarandombox.MultiverseCore.worldnew.LoadedMultiverseWorld;
import com.onarandombox.MultiverseCore.worldnew.MultiverseWorld;
import org.bukkit.Material;
+import org.bukkit.World;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
@@ -16,8 +17,13 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.Collection;
+
import static com.onarandombox.MultiverseCore.utils.message.MessageReplacement.replace;
+/**
+ * Checks if a player can enter a world.
+ */
public class WorldEntryChecker {
private final @NotNull MVCoreConfig config;
private final @NotNull MVEconomist economist;
@@ -25,23 +31,39 @@ public class WorldEntryChecker {
private final @NotNull CommandSender sender;
- public WorldEntryChecker(
+ WorldEntryChecker(
@NotNull MVCoreConfig config,
@NotNull CorePermissionsChecker permissionsChecker,
@NotNull MVEconomist economist,
- @NotNull CommandSender sender
- ) {
+ @NotNull CommandSender sender) {
this.config = config;
this.permissionsChecker = permissionsChecker;
this.economist = economist;
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) {
- 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()
.then(() -> canAccessWorld(toWorld))
.then(() -> isWithinPlayerLimit(toWorld))
@@ -50,6 +72,12 @@ public class WorldEntryChecker {
.build();
}
+ /**
+ * Checks if the sender can access the given world.
+ *
+ * @param world The world to check.
+ * @return The result of the check.
+ */
public Result canAccessWorld(@NotNull MultiverseWorld world) {
if (!config.getEnforceAccess()) {
return Result.success(WorldAccessResult.Success.NO_ENFORCE_WORLD_ACCESS);
@@ -59,7 +87,14 @@ public class WorldEntryChecker {
: Result.failure(WorldAccessResult.Failure.NO_WORLD_ACCESS);
}
- public Result 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 isWithinPlayerLimit(
+ @NotNull LoadedMultiverseWorld world) {
final int playerLimit = world.getPlayerLimit();
if (playerLimit <= -1) {
return Result.success(PlayerLimitResult.Success.NO_PLAYERLIMIT);
@@ -67,12 +102,23 @@ public class WorldEntryChecker {
if (permissionsChecker.hasPlayerLimitBypassPermission(sender, world)) {
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.failure(PlayerLimitResult.Failure.EXCEED_PLAYERLIMIT);
}
- public Result 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 isNotBlacklisted(
+ @Nullable LoadedMultiverseWorld fromWorld, @NotNull LoadedMultiverseWorld toWorld) {
if (fromWorld == null) {
return Result.success(BlacklistResult.Success.UNKNOWN_FROM_WORLD);
}
@@ -81,6 +127,12 @@ public class WorldEntryChecker {
: 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 canPayEntryFee(LoadedMultiverseWorld world) {
double price = world.getPrice();
Material currency = world.getCurrency();
@@ -98,6 +150,8 @@ public class WorldEntryChecker {
}
return economist.isPlayerWealthyEnough(player, price, currency)
? 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
}
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldEntryCheckerProvider.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldEntryCheckerProvider.java
index 5fbcc25c..e95693a9 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldEntryCheckerProvider.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/entrycheck/WorldEntryCheckerProvider.java
@@ -19,8 +19,7 @@ public class WorldEntryCheckerProvider {
WorldEntryCheckerProvider(
@NotNull MVCoreConfig config,
@NotNull MVEconomist economist,
- @NotNull CorePermissionsChecker permissionsChecker
- ) {
+ @NotNull CorePermissionsChecker permissionsChecker) {
this.config = config;
this.economist = economist;
this.permissionsChecker = permissionsChecker;
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/generators/GeneratorProvider.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/generators/GeneratorProvider.java
index 93274aa9..1f282666 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/generators/GeneratorProvider.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/generators/GeneratorProvider.java
@@ -2,6 +2,7 @@ package com.onarandombox.MultiverseCore.worldnew.generators;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;
+import io.vavr.control.Try;
import jakarta.inject.Inject;
import org.bukkit.Bukkit;
import org.bukkit.World;
@@ -84,16 +85,14 @@ public class GeneratorProvider implements Listener {
*/
private boolean testIsGeneratorPlugin(Plugin plugin) {
String worldName = Bukkit.getWorlds().stream().findFirst().map(World::getName).orElse("world");
- try {
- return plugin.getDefaultWorldGenerator(worldName, "") != null;
- } catch (IllegalArgumentException e) {
- Logging.fine("Testing id is wrong, but it is probably a generator plugin: %s", plugin.getName());
- return true;
- } catch (Throwable t) {
- Logging.warning("Plugin %s threw an exception when testing if it is a generator plugin!", plugin.getName());
- t.printStackTrace();
- return false;
- }
+ return Try.of(() -> plugin.getDefaultWorldGenerator(worldName, "") != null)
+ .recover(IllegalArgumentException.class, true)
+ .recover(throwable -> {
+ Logging.warning("Plugin %s threw an exception when testing if it is a generator plugin!",
+ plugin.getName());
+ throwable.printStackTrace();
+ return false;
+ }).getOrElse(false);
}
/**
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/DataStore.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/DataStore.java
index 7eb334de..bd65e57c 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/DataStore.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/DataStore.java
@@ -2,6 +2,7 @@ package com.onarandombox.MultiverseCore.worldnew.helpers;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.worldnew.LoadedMultiverseWorld;
+import io.vavr.control.Try;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.jvnet.hk2.annotations.Service;
@@ -62,23 +63,17 @@ public interface DataStore {
if (gameRuleMap == null) {
return this;
}
- world.getBukkitWorld().peek(bukkitWorld -> {
- gameRuleMap.forEach((gameRule, value) -> {
- if (!setGameRuleValue(bukkitWorld, gameRule, value)) {
- Logging.warning("Failed to set game rule " + gameRule.getName() + " to " + value);
- }
+ world.getBukkitWorld().peek(bukkitWorld -> gameRuleMap.forEach((gameRule, value) -> {
+ setGameRuleValue(bukkitWorld, gameRule, value).onFailure(e -> {
+ Logging.warning("Failed to set game rule " + gameRule.getName() + " to " + value);
+ e.printStackTrace();
});
- });
+ }));
return this;
}
- private boolean setGameRuleValue(World world, GameRule gameRule, Object value) {
- try {
- return world.setGameRule(gameRule, (T) value);
- } catch (Exception e) {
- Logging.fine(e.getMessage());
- return false;
- }
+ private Try setGameRuleValue(World world, GameRule gameRule, Object value) {
+ return Try.run(() -> world.setGameRule(gameRule, (T) value));
}
}
@@ -94,11 +89,11 @@ public interface DataStore {
@Override
public WorldConfigStore copyFrom(LoadedMultiverseWorld world) {
this.configMap = new HashMap<>();
- world.getConfigurablePropertyNames().forEach(name -> {
- world.getProperty(name).peek(value -> configMap.put(name, value)).onFailure(e -> {
- Logging.warning("Failed to get property " + name + " from world " + world.getName() + ": " + e.getMessage());
- });
- });
+ world.getConfigurablePropertyNames().forEach(name -> world.getProperty(name)
+ .peek(value -> configMap.put(name, value)).onFailure(e -> {
+ Logging.warning("Failed to get property " + name + " from world "
+ + world.getName() + ": " + e.getMessage());
+ }));
return this;
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/DataTransfer.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/DataTransfer.java
index 00671003..d033ccc4 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/DataTransfer.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/DataTransfer.java
@@ -22,6 +22,7 @@ public class DataTransfer {
* Adds a {@link DataStore} to this {@link DataTransfer} instance.
*
* @param dataStore The {@link DataStore} to add.
+ * @param object The object to copy data from.
* @return This {@link DataTransfer} instance.
*/
public DataTransfer addDataStore(DataStore dataStore, T object) {
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/FilesManipulator.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/FilesManipulator.java
index 28dcf4fc..6661ae22 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/FilesManipulator.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/helpers/FilesManipulator.java
@@ -19,13 +19,30 @@ import java.util.stream.Stream;
import static java.nio.file.StandardCopyOption.COPY_ATTRIBUTES;
+/**
+ * A helper class for manipulating files and folders.
+ */
@Service
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 deleteFolder(File file) {
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 deleteFolder(Path path) {
try (Stream files = Files.walk(path)) {
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 copyFolder(File sourceDir, File targetDir) {
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 copyFolder(File sourceDir, File targetDir, List 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 copyFolder(Path sourceDir, Path targetDir) {
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 copyFolder(Path sourceDir, Path targetDir, List excludeFiles) {
- try {
- Files.walkFileTree(sourceDir, new CopyDirFileVisitor(sourceDir, targetDir, excludeFiles));
- return Try.success(null);
- } catch (IOException e) {
- Logging.severe("Failed to copy folder: " + sourceDir.toAbsolutePath());
- e.printStackTrace();
- return Try.failure(e);
- }
+ return Try.run(() -> Files.walkFileTree(sourceDir, new CopyDirFileVisitor(sourceDir, targetDir, excludeFiles)))
+ .onFailure(e -> {
+ Logging.severe("Failed to copy folder: " + sourceDir.toAbsolutePath());
+ e.printStackTrace();
+ });
}
private static final class CopyDirFileVisitor extends SimpleFileVisitor {
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/CloneWorldOptions.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/CloneWorldOptions.java
index 153e2dd1..d99d14eb 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/CloneWorldOptions.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/CloneWorldOptions.java
@@ -52,12 +52,12 @@ public final class CloneWorldOptions implements KeepWorldSettingsOptions {
/**
* 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.
*/
@Override
- public @NotNull CloneWorldOptions keepGameRule(boolean keepGameRule) {
- this.keepGameRule = keepGameRule;
+ public @NotNull CloneWorldOptions keepGameRule(boolean keepGameRuleInput) {
+ this.keepGameRule = keepGameRuleInput;
return this;
}
@@ -71,9 +71,15 @@ public final class CloneWorldOptions implements KeepWorldSettingsOptions {
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
- public @NotNull CloneWorldOptions keepWorldConfig(boolean keepWorldConfig) {
- this.keepWorldConfig = keepWorldConfig;
+ public @NotNull CloneWorldOptions keepWorldConfig(boolean keepWorldConfigInput) {
+ this.keepWorldConfig = keepWorldConfigInput;
return this;
}
@@ -87,9 +93,16 @@ public final class CloneWorldOptions implements KeepWorldSettingsOptions {
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
- public @NotNull CloneWorldOptions keepWorldBorder(boolean keepWorldBorder) {
- this.keepWorldBorder = keepWorldBorder;
+ public @NotNull CloneWorldOptions keepWorldBorder(boolean keepWorldBorderInput) {
+ this.keepWorldBorder = keepWorldBorderInput;
return this;
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/CreateWorldOptions.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/CreateWorldOptions.java
index 114b9c1a..9da8f633 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/CreateWorldOptions.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/CreateWorldOptions.java
@@ -52,11 +52,11 @@ public class CreateWorldOptions {
/**
* 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.
*/
- public @NotNull CreateWorldOptions environment(@NotNull World.Environment environment) {
- this.environment = environment;
+ public @NotNull CreateWorldOptions environment(@NotNull World.Environment environmentInput) {
+ this.environment = environmentInput;
return this;
}
@@ -72,11 +72,11 @@ public class CreateWorldOptions {
/**
* 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.
*/
- public @NotNull CreateWorldOptions generateStructures(boolean generateStructures) {
- this.generateStructures = generateStructures;
+ public @NotNull CreateWorldOptions generateStructures(boolean generateStructuresInput) {
+ this.generateStructures = generateStructuresInput;
return this;
}
@@ -92,11 +92,11 @@ public class CreateWorldOptions {
/**
* 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.
*/
- public @NotNull CreateWorldOptions generator(@Nullable String generator) {
- this.generator = generator;
+ public @NotNull CreateWorldOptions generator(@Nullable String generatorInput) {
+ this.generator = generatorInput;
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
* hashed.
*
- * @param seed The seed of the world to create.
+ * @param seedInput The seed of the world to create.
* @return This {@link CreateWorldOptions} instance.
*/
- public @NotNull CreateWorldOptions seed(@Nullable String seed) {
- if (seed == null) {
+ public @NotNull CreateWorldOptions seed(@Nullable String seedInput) {
+ if (seedInput == null) {
return this;
}
try {
- this.seed = Long.parseLong(seed);
+ this.seed = Long.parseLong(seedInput);
} catch (NumberFormatException numberformatexception) {
- this.seed = seed.hashCode();
+ this.seed = seedInput.hashCode();
}
return this;
}
@@ -131,11 +131,11 @@ public class CreateWorldOptions {
/**
* 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.
*/
- public @NotNull CreateWorldOptions seed(long seed) {
- this.seed = seed;
+ public @NotNull CreateWorldOptions seed(long seedInput) {
+ this.seed = seedInput;
return this;
}
@@ -151,11 +151,11 @@ public class CreateWorldOptions {
/**
* 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.
*/
- public @NotNull CreateWorldOptions useSpawnAdjust(boolean useSpawnAdjust) {
- this.useSpawnAdjust = useSpawnAdjust;
+ public @NotNull CreateWorldOptions useSpawnAdjust(boolean useSpawnAdjustInput) {
+ this.useSpawnAdjust = useSpawnAdjustInput;
return this;
}
@@ -171,11 +171,11 @@ public class CreateWorldOptions {
/**
* Sets the world type.
*
- * @param worldType The world type.
+ * @param worldTypeInput The world type.
* @return This {@link CreateWorldOptions} instance.
*/
- public @NotNull CreateWorldOptions worldType(@NotNull WorldType worldType) {
- this.worldType = worldType;
+ public @NotNull CreateWorldOptions worldType(@NotNull WorldType worldTypeInput) {
+ this.worldType = worldTypeInput;
return this;
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/ImportWorldOptions.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/ImportWorldOptions.java
index 4c092443..24d4883e 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/ImportWorldOptions.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/ImportWorldOptions.java
@@ -40,11 +40,11 @@ public class ImportWorldOptions {
/**
* 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.
*/
- public @NotNull ImportWorldOptions environment(@NotNull World.Environment environment) {
- this.environment = environment;
+ public @NotNull ImportWorldOptions environment(@NotNull World.Environment environmentInput) {
+ this.environment = environmentInput;
return this;
}
@@ -60,11 +60,11 @@ public class ImportWorldOptions {
/**
* 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.
*/
- public @NotNull ImportWorldOptions generator(@Nullable String generator) {
- this.generator = generator;
+ public @NotNull ImportWorldOptions generator(@Nullable String generatorInput) {
+ this.generator = generatorInput;
return this;
}
@@ -80,11 +80,11 @@ public class ImportWorldOptions {
/**
* 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.
*/
- public @NotNull ImportWorldOptions useSpawnAdjust(boolean useSpawnAdjust) {
- this.useSpawnAdjust = useSpawnAdjust;
+ public @NotNull ImportWorldOptions useSpawnAdjust(boolean useSpawnAdjustInput) {
+ this.useSpawnAdjust = useSpawnAdjustInput;
return this;
}
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/KeepWorldSettingsOptions.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/KeepWorldSettingsOptions.java
index 51a6bb94..181771af 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/KeepWorldSettingsOptions.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/KeepWorldSettingsOptions.java
@@ -2,15 +2,18 @@ package com.onarandombox.MultiverseCore.worldnew.options;
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 {
/**
* 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.
*/
- @NotNull KeepWorldSettingsOptions keepGameRule(boolean keepGameRule);
+ @NotNull KeepWorldSettingsOptions keepGameRule(boolean keepGameRuleInput);
/**
* 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.
*
- * @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.
*/
- @NotNull KeepWorldSettingsOptions keepWorldConfig(boolean keepWorldConfig);
+ @NotNull KeepWorldSettingsOptions keepWorldConfig(boolean keepWorldConfigInput);
/**
* 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.
*
- * @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.
*/
- @NotNull KeepWorldSettingsOptions keepWorldBorder(boolean keepWorldBorder);
+ @NotNull KeepWorldSettingsOptions keepWorldBorder(boolean keepWorldBorderInput);
/**
* Gets whether to keep the world border of the world.
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/RegenWorldOptions.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/RegenWorldOptions.java
index 00ed0476..35167bf7 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/RegenWorldOptions.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/RegenWorldOptions.java
@@ -45,12 +45,12 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
/**
* 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.
*/
@Override
- public @NotNull RegenWorldOptions keepGameRule(boolean keepGameRule) {
- this.keepGameRule = keepGameRule;
+ public @NotNull RegenWorldOptions keepGameRule(boolean keepGameRuleInput) {
+ this.keepGameRule = keepGameRuleInput;
return this;
}
@@ -67,12 +67,12 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
/**
* 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.
*/
@Override
- public @NotNull RegenWorldOptions keepWorldConfig(boolean keepWorldConfig) {
- this.keepWorldConfig = keepWorldConfig;
+ public @NotNull RegenWorldOptions keepWorldConfig(boolean keepWorldConfigInput) {
+ this.keepWorldConfig = keepWorldConfigInput;
return this;
}
@@ -81,12 +81,20 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
*
* @return Whether to keep the world config of the world during regeneration.
*/
+ @Override
public boolean 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;
}
@@ -95,6 +103,7 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
*
* @return Whether to keep the world border of the world during regeneration.
*/
+ @Override
public boolean 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.
*
- * @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.
*/
- public @NotNull RegenWorldOptions randomSeed(boolean randomSeed) {
- if (randomSeed && seed != Long.MIN_VALUE) {
+ public @NotNull RegenWorldOptions randomSeed(boolean randomSeedInput) {
+ if (randomSeedInput && seed != Long.MIN_VALUE) {
throw new IllegalStateException("Cannot set randomSeed to true when seed is set");
}
- this.randomSeed = randomSeed;
+ this.randomSeed = randomSeedInput;
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.
*
- * @param seed The seed for the world to regenerate.
+ * @param seedInput The seed for the world to regenerate.
* @return This {@link RegenWorldOptions} instance.
*/
- public @NotNull RegenWorldOptions seed(@Nullable String seed) {
- if (seed == null) {
+ public @NotNull RegenWorldOptions seed(@Nullable String seedInput) {
+ if (seedInput == null) {
this.seed = Long.MIN_VALUE;
return this;
}
@@ -137,9 +146,9 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
randomSeed(false);
}
try {
- this.seed = Long.parseLong(seed);
+ this.seed = Long.parseLong(seedInput);
} catch (NumberFormatException numberformatexception) {
- this.seed = seed.hashCode();
+ this.seed = seedInput.hashCode();
}
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.
*
- * @param seed The seed for the world to regenerate.
+ * @param seedInput The seed for the world to regenerate.
* @return This {@link RegenWorldOptions} instance.
*/
- public @NotNull RegenWorldOptions seed(long seed) {
- this.seed = seed;
+ public @NotNull RegenWorldOptions seed(long seedInput) {
+ this.seed = seedInput;
return this;
}
@@ -163,8 +172,7 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions {
public long seed() {
if (randomSeed) {
return new Random().nextLong();
- }
- if (seed == Long.MIN_VALUE) {
+ } else if (seed == Long.MIN_VALUE) {
return world.getSeed();
}
return seed;
diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/UnloadWorldOptions.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/UnloadWorldOptions.java
index 0856ab34..d30513d1 100644
--- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/UnloadWorldOptions.java
+++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/options/UnloadWorldOptions.java
@@ -37,11 +37,11 @@ public class UnloadWorldOptions {
/**
* 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.
*/
- public UnloadWorldOptions removePlayers(boolean removePlayers) {
- this.removePlayers = removePlayers;
+ public UnloadWorldOptions removePlayers(boolean removePlayersInput) {
+ this.removePlayers = removePlayersInput;
return this;
}
@@ -57,11 +57,11 @@ public class UnloadWorldOptions {
/**
* 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.
*/
- public UnloadWorldOptions saveBukkitWorld(boolean saveBukkitWorld) {
- this.saveBukkitWorld = saveBukkitWorld;
+ public UnloadWorldOptions saveBukkitWorld(boolean saveBukkitWorldInput) {
+ this.saveBukkitWorld = saveBukkitWorldInput;
return this;
}