Refactor world results and add docs

This commit is contained in:
Ben Woo 2023-09-11 14:35:56 +08:00
parent 7490996ecb
commit d8334ad71a
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
13 changed files with 250 additions and 126 deletions

View File

@ -10,8 +10,8 @@ package com.onarandombox.MultiverseCore.listeners;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.inject.InjectableListener;
import com.onarandombox.MultiverseCore.worldnew.WorldManager;
import com.onarandombox.MultiverseCore.worldnew.results.LoadWorldResult;
import com.onarandombox.MultiverseCore.worldnew.results.UnloadWorldResult;
import com.onarandombox.MultiverseCore.worldnew.reasons.LoadFailureReason;
import com.onarandombox.MultiverseCore.worldnew.reasons.UnloadFailureReason;
import jakarta.inject.Inject;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -43,7 +43,7 @@ public class MVWorldListener implements InjectableListener {
return;
}
worldManager.unloadWorld(event.getWorld()).onFailure(failure -> {
if (failure.getFailureReason() != UnloadWorldResult.WORLD_ALREADY_UNLOADING) {
if (failure.getFailureReason() != UnloadFailureReason.WORLD_ALREADY_UNLOADING) {
Logging.severe("Failed to unload world: " + failure);
}
});
@ -60,7 +60,7 @@ public class MVWorldListener implements InjectableListener {
.peek(world -> {
Logging.fine("Loading world: " + world.getName());
worldManager.loadWorld(world).onFailure(failure -> {
if (failure.getFailureReason() != LoadWorldResult.WORLD_ALREADY_LOADING) {
if (failure.getFailureReason() != LoadFailureReason.WORLD_ALREADY_LOADING) {
Logging.severe("Failed to load world: " + failure);
}
});

View File

@ -19,14 +19,14 @@ import com.onarandombox.MultiverseCore.worldnew.options.CreateWorldOptions;
import com.onarandombox.MultiverseCore.worldnew.options.ImportWorldOptions;
import com.onarandombox.MultiverseCore.worldnew.options.KeepWorldSettingsOptions;
import com.onarandombox.MultiverseCore.worldnew.options.RegenWorldOptions;
import com.onarandombox.MultiverseCore.worldnew.results.CloneWorldResult;
import com.onarandombox.MultiverseCore.worldnew.results.CreateWorldResult;
import com.onarandombox.MultiverseCore.worldnew.results.DeleteWorldResult;
import com.onarandombox.MultiverseCore.worldnew.results.ImportWorldResult;
import com.onarandombox.MultiverseCore.worldnew.results.LoadWorldResult;
import com.onarandombox.MultiverseCore.worldnew.results.RegenWorldResult;
import com.onarandombox.MultiverseCore.worldnew.results.RemoveWorldResult;
import com.onarandombox.MultiverseCore.worldnew.results.UnloadWorldResult;
import com.onarandombox.MultiverseCore.worldnew.reasons.CloneFailureReason;
import com.onarandombox.MultiverseCore.worldnew.reasons.CreateFailureReason;
import com.onarandombox.MultiverseCore.worldnew.reasons.DeleteFailureReason;
import com.onarandombox.MultiverseCore.worldnew.reasons.ImportFailureReason;
import com.onarandombox.MultiverseCore.worldnew.reasons.LoadFailureReason;
import com.onarandombox.MultiverseCore.worldnew.reasons.RegenFailureReason;
import com.onarandombox.MultiverseCore.worldnew.reasons.RemoveFailureReason;
import com.onarandombox.MultiverseCore.worldnew.reasons.UnloadFailureReason;
import io.vavr.control.Option;
import io.vavr.control.Try;
import jakarta.inject.Inject;
@ -169,20 +169,20 @@ public class WorldManager {
* @param options The options for customizing the creation of a new world.
* @return The result of the creation.
*/
public Attempt<LoadedMultiverseWorld, CreateWorldResult> createWorld(CreateWorldOptions options) {
public Attempt<LoadedMultiverseWorld, CreateFailureReason> createWorld(CreateWorldOptions options) {
return validateCreateWorldOptions(options).mapAttempt(this::createValidatedWorld);
}
private Attempt<CreateWorldOptions, CreateWorldResult> validateCreateWorldOptions(
private Attempt<CreateWorldOptions, CreateFailureReason> validateCreateWorldOptions(
CreateWorldOptions options) {
if (!worldNameChecker.isValidWorldName(options.worldName())) {
return worldActionResult(CreateWorldResult.INVALID_WORLDNAME, options.worldName());
return worldActionResult(CreateFailureReason.INVALID_WORLDNAME, options.worldName());
} else if (getLoadedWorld(options.worldName()).isDefined()) {
return worldActionResult(CreateWorldResult.WORLD_EXIST_LOADED, options.worldName());
return worldActionResult(CreateFailureReason.WORLD_EXIST_LOADED, options.worldName());
} else if (getWorld(options.worldName()).isDefined()) {
return worldActionResult(CreateWorldResult.WORLD_EXIST_UNLOADED, options.worldName());
return worldActionResult(CreateFailureReason.WORLD_EXIST_UNLOADED, options.worldName());
} else if (hasWorldFolder(options.worldName())) {
return worldActionResult(CreateWorldResult.WORLD_EXIST_FOLDER, options.worldName());
return worldActionResult(CreateFailureReason.WORLD_EXIST_FOLDER, options.worldName());
}
return worldActionResult(options);
}
@ -192,7 +192,7 @@ public class WorldManager {
return worldFolder.exists();
}
private Attempt<LoadedMultiverseWorld, CreateWorldResult> createValidatedWorld(
private Attempt<LoadedMultiverseWorld, CreateFailureReason> createValidatedWorld(
CreateWorldOptions options) {
String parsedGenerator = parseGenerator(options.worldName(), options.generator());
WorldCreator worldCreator = WorldCreator.name(options.worldName())
@ -202,7 +202,7 @@ public class WorldManager {
.seed(options.seed())
.type(options.worldType());
return createBukkitWorld(worldCreator).fold(
exception -> worldActionResult(CreateWorldResult.BUKKIT_CREATION_FAILED,
exception -> worldActionResult(CreateFailureReason.BUKKIT_CREATION_FAILED,
options.worldName(), exception),
world -> {
LoadedMultiverseWorld loadedWorld = newLoadedMultiverseWorld(
@ -219,34 +219,34 @@ public class WorldManager {
* @param options The options for customizing the import of an existing world folder.
* @return The result of the import.
*/
public Attempt<LoadedMultiverseWorld, ImportWorldResult> importWorld(
public Attempt<LoadedMultiverseWorld, ImportFailureReason> importWorld(
ImportWorldOptions options) {
return validateImportWorldOptions(options).mapAttempt(this::doImportWorld);
}
private Attempt<ImportWorldOptions, ImportWorldResult> validateImportWorldOptions(
private Attempt<ImportWorldOptions, ImportFailureReason> validateImportWorldOptions(
ImportWorldOptions options) {
String worldName = options.worldName();
if (!worldNameChecker.isValidWorldName(worldName)) {
return worldActionResult(ImportWorldResult.INVALID_WORLDNAME, worldName);
return worldActionResult(ImportFailureReason.INVALID_WORLDNAME, worldName);
} else if (!worldNameChecker.isValidWorldFolder(worldName)) {
return worldActionResult(ImportWorldResult.WORLD_FOLDER_INVALID, worldName);
return worldActionResult(ImportFailureReason.WORLD_FOLDER_INVALID, worldName);
} else if (isLoadedWorld(worldName)) {
return worldActionResult(ImportWorldResult.WORLD_EXIST_LOADED, worldName);
return worldActionResult(ImportFailureReason.WORLD_EXIST_LOADED, worldName);
} else if (isWorld(worldName)) {
return worldActionResult(ImportWorldResult.WORLD_EXIST_UNLOADED, worldName);
return worldActionResult(ImportFailureReason.WORLD_EXIST_UNLOADED, worldName);
}
return worldActionResult(options);
}
private Attempt<LoadedMultiverseWorld, ImportWorldResult> doImportWorld(
private Attempt<LoadedMultiverseWorld, ImportFailureReason> doImportWorld(
ImportWorldOptions options) {
String parsedGenerator = parseGenerator(options.worldName(), options.generator());
WorldCreator worldCreator = WorldCreator.name(options.worldName())
.environment(options.environment())
.generator(parsedGenerator);
return createBukkitWorld(worldCreator).fold(
exception -> worldActionResult(ImportWorldResult.BUKKIT_CREATION_FAILED,
exception -> worldActionResult(ImportFailureReason.BUKKIT_CREATION_FAILED,
options.worldName(), exception),
world -> {
LoadedMultiverseWorld loadedWorld = newLoadedMultiverseWorld(world,
@ -302,12 +302,12 @@ public class WorldManager {
* @param worldName The name of the world to load.
* @return The result of the load.
*/
public Attempt<LoadedMultiverseWorld, LoadWorldResult> loadWorld(@NotNull String worldName) {
public Attempt<LoadedMultiverseWorld, LoadFailureReason> loadWorld(@NotNull String worldName) {
return getWorld(worldName)
.map(this::loadWorld)
.getOrElse(() -> worldNameChecker.isValidWorldFolder(worldName)
? worldActionResult(LoadWorldResult.WORLD_EXIST_FOLDER, worldName)
: worldActionResult(LoadWorldResult.WORLD_NON_EXISTENT, worldName));
? worldActionResult(LoadFailureReason.WORLD_EXIST_FOLDER, worldName)
: worldActionResult(LoadFailureReason.WORLD_NON_EXISTENT, worldName));
}
/**
@ -316,29 +316,29 @@ public class WorldManager {
* @param world The world to load.
* @return The result of the load.
*/
public Attempt<LoadedMultiverseWorld, LoadWorldResult> loadWorld(@NotNull MultiverseWorld world) {
public Attempt<LoadedMultiverseWorld, LoadFailureReason> loadWorld(@NotNull MultiverseWorld world) {
return validateWorldToLoad(world).mapAttempt(this::doLoadWorld);
}
private Attempt<MultiverseWorld, LoadWorldResult> validateWorldToLoad(
private Attempt<MultiverseWorld, LoadFailureReason> validateWorldToLoad(
@NotNull MultiverseWorld mvWorld) {
if (loadTracker.contains(mvWorld.getName())) {
// This is to prevent recursive calls by WorldLoadEvent
Logging.fine("World already loading: " + mvWorld.getName());
return worldActionResult(LoadWorldResult.WORLD_ALREADY_LOADING, mvWorld.getName());
return worldActionResult(LoadFailureReason.WORLD_ALREADY_LOADING, mvWorld.getName());
} else if (isLoadedWorld(mvWorld)) {
Logging.severe("World already loaded: " + mvWorld.getName());
return worldActionResult(LoadWorldResult.WORLD_EXIST_LOADED, mvWorld.getName());
return worldActionResult(LoadFailureReason.WORLD_EXIST_LOADED, mvWorld.getName());
}
return worldActionResult(mvWorld);
}
private Attempt<LoadedMultiverseWorld, LoadWorldResult> doLoadWorld(@NotNull MultiverseWorld mvWorld) {
private Attempt<LoadedMultiverseWorld, LoadFailureReason> doLoadWorld(@NotNull MultiverseWorld mvWorld) {
return createBukkitWorld(WorldCreator.name(mvWorld.getName())
.environment(mvWorld.getEnvironment())
.generator(Strings.isNullOrEmpty(mvWorld.getGenerator()) ? null : mvWorld.getGenerator())
.seed(mvWorld.getSeed())).fold(
exception -> worldActionResult(LoadWorldResult.BUKKIT_CREATION_FAILED,
exception -> worldActionResult(LoadFailureReason.BUKKIT_CREATION_FAILED,
mvWorld.getName(), exception),
world -> {
WorldConfig worldConfig = worldsConfigManager.getWorldConfig(mvWorld.getName()).get();
@ -360,7 +360,7 @@ public class WorldManager {
* @param world The bukkit world to unload.
* @return The result of the unload action.
*/
public Attempt<MultiverseWorld, UnloadWorldResult> unloadWorld(@NotNull World world) {
public Attempt<MultiverseWorld, UnloadFailureReason> unloadWorld(@NotNull World world) {
return unloadWorld(world.getName());
}
@ -370,12 +370,12 @@ public class WorldManager {
* @param worldName The name of the world to unload.
* @return The result of the unload action.
*/
public Attempt<MultiverseWorld, UnloadWorldResult> unloadWorld(@NotNull String worldName) {
public Attempt<MultiverseWorld, UnloadFailureReason> unloadWorld(@NotNull String worldName) {
return getLoadedWorld(worldName)
.map(this::unloadWorld)
.getOrElse(() -> isUnloadedWorld(worldName)
? worldActionResult(UnloadWorldResult.WORLD_UNLOADED, worldName)
: worldActionResult(UnloadWorldResult.WORLD_NON_EXISTENT, worldName));
? worldActionResult(UnloadFailureReason.WORLD_UNLOADED, worldName)
: worldActionResult(UnloadFailureReason.WORLD_NON_EXISTENT, worldName));
}
/**
@ -384,23 +384,23 @@ public class WorldManager {
* @param world The multiverse world to unload.
* @return The result of the unload action.
*/
public Attempt<MultiverseWorld, UnloadWorldResult> unloadWorld(
public Attempt<MultiverseWorld, UnloadFailureReason> unloadWorld(
@NotNull LoadedMultiverseWorld world) {
if (unloadTracker.contains(world.getName())) {
// This is to prevent recursive calls by WorldUnloadEvent
Logging.fine("World already unloading: " + world.getName());
return worldActionResult(UnloadWorldResult.WORLD_ALREADY_UNLOADING, world.getName());
return worldActionResult(UnloadFailureReason.WORLD_ALREADY_UNLOADING, world.getName());
}
// TODO: removePlayersFromWorld?
return unloadBukkitWorld(world.getBukkitWorld().getOrNull()).fold(
exception -> worldActionResult(UnloadWorldResult.BUKKIT_UNLOAD_FAILED,
exception -> worldActionResult(UnloadFailureReason.BUKKIT_UNLOAD_FAILED,
world.getName(), exception),
success -> Option.of(loadedWorldsMap.remove(world.getName())).fold(
() -> {
Logging.severe("Failed to remove world from map: " + world.getName());
return worldActionResult(UnloadWorldResult.WORLD_NON_EXISTENT, world.getName());
return worldActionResult(UnloadFailureReason.WORLD_NON_EXISTENT, world.getName());
},
mvWorld -> {
Logging.fine("Removed MultiverseWorld from map: " + world.getName());
@ -416,11 +416,11 @@ public class WorldManager {
* @param worldName The name of the world to remove.
* @return The result of the remove.
*/
public Attempt<String, RemoveWorldResult> removeWorld(
public Attempt<String, RemoveFailureReason> removeWorld(
@NotNull String worldName) {
return getWorld(worldName)
.map(this::removeWorld)
.getOrElse(() -> worldActionResult(RemoveWorldResult.WORLD_NON_EXISTENT, worldName));
.getOrElse(() -> worldActionResult(RemoveFailureReason.WORLD_NON_EXISTENT, worldName));
}
/**
@ -430,7 +430,7 @@ public class WorldManager {
* @param world The multiverse world to remove.
* @return The result of the remove.
*/
public Attempt<String, RemoveWorldResult> removeWorld(@NotNull MultiverseWorld world) {
public Attempt<String, RemoveFailureReason> removeWorld(@NotNull MultiverseWorld world) {
return getLoadedWorld(world).fold(
() -> removeWorldFromConfig(world),
this::removeWorld);
@ -443,9 +443,9 @@ public class WorldManager {
* @param loadedWorld The multiverse world to remove.
* @return The result of the remove.
*/
public Attempt<String, RemoveWorldResult> removeWorld(@NotNull LoadedMultiverseWorld loadedWorld) {
public Attempt<String, RemoveFailureReason> removeWorld(@NotNull LoadedMultiverseWorld loadedWorld) {
return unloadWorld(loadedWorld)
.transform(RemoveWorldResult.UNLOAD_FAILED)
.transform(RemoveFailureReason.UNLOAD_FAILED)
.mapAttempt(this::removeWorldFromConfig);
}
@ -455,7 +455,7 @@ public class WorldManager {
* @param world The multiverse world to remove.
* @return The result of the remove.
*/
private Attempt<String, RemoveWorldResult> removeWorldFromConfig(@NotNull MultiverseWorld world) {
private Attempt<String, RemoveFailureReason> removeWorldFromConfig(@NotNull MultiverseWorld world) {
// Remove world from config
worldsMap.remove(world.getName());
worldsConfigManager.deleteWorldConfig(world.getName());
@ -471,10 +471,10 @@ public class WorldManager {
* @param worldName The name of the world to delete.
* @return The result of the delete action.
*/
public Attempt<String, DeleteWorldResult> deleteWorld(@NotNull String worldName) {
public Attempt<String, DeleteFailureReason> deleteWorld(@NotNull String worldName) {
return getWorld(worldName)
.map(this::deleteWorld)
.getOrElse(() -> worldActionResult(DeleteWorldResult.WORLD_NON_EXISTENT, worldName));
.getOrElse(() -> worldActionResult(DeleteFailureReason.WORLD_NON_EXISTENT, worldName));
}
/**
@ -484,10 +484,10 @@ public class WorldManager {
* @param world The world to delete.
* @return The result of the delete action.
*/
public Attempt<String, DeleteWorldResult> deleteWorld(@NotNull MultiverseWorld world) {
public Attempt<String, DeleteFailureReason> deleteWorld(@NotNull MultiverseWorld world) {
return getLoadedWorld(world).fold(
() -> loadWorld(world)
.transform(DeleteWorldResult.LOAD_FAILED)
.transform(DeleteFailureReason.LOAD_FAILED)
.mapAttempt(this::deleteWorld),
this::deleteWorld);
}
@ -498,24 +498,24 @@ public class WorldManager {
* @param world The multiverse world to delete.
* @return The result of the delete action.
*/
public Attempt<String, DeleteWorldResult> deleteWorld(@NotNull LoadedMultiverseWorld world) {
public Attempt<String, DeleteFailureReason> deleteWorld(@NotNull LoadedMultiverseWorld world) {
// TODO: Possible config options to keep certain files
AtomicReference<File> worldFolder = new AtomicReference<>();
return validateWorldToDelete(world)
.peek(worldFolder::set)
.mapAttempt(() -> removeWorld(world).transform(DeleteWorldResult.REMOVE_FAILED))
.mapAttempt(() -> removeWorld(world).transform(DeleteFailureReason.REMOVE_FAILED))
.mapAttempt(() -> filesManipulator.deleteFolder(worldFolder.get()).fold(
exception -> worldActionResult(DeleteWorldResult.FAILED_TO_DELETE_FOLDER,
exception -> worldActionResult(DeleteFailureReason.FAILED_TO_DELETE_FOLDER,
world.getName(), exception),
success -> worldActionResult(world.getName())));
}
private Attempt<File, DeleteWorldResult> validateWorldToDelete(
private Attempt<File, DeleteFailureReason> validateWorldToDelete(
@NotNull LoadedMultiverseWorld world) {
File worldFolder = world.getBukkitWorld().map(World::getWorldFolder).getOrNull();
if (worldFolder == null || !worldNameChecker.isValidWorldFolder(worldFolder)) {
Logging.severe("Failed to get world folder for world: " + world.getName());
return worldActionResult(DeleteWorldResult.WORLD_FOLDER_NOT_FOUND, world.getName());
return worldActionResult(DeleteFailureReason.WORLD_FOLDER_NOT_FOUND, world.getName());
}
return worldActionResult(worldFolder);
}
@ -526,7 +526,7 @@ public class WorldManager {
* @param options The options for customizing the cloning of a world.
* @return The result of the clone.
*/
public Attempt<LoadedMultiverseWorld, CloneWorldResult> cloneWorld(@NotNull CloneWorldOptions options) {
public Attempt<LoadedMultiverseWorld, CloneFailureReason> cloneWorld(@NotNull CloneWorldOptions options) {
return cloneWorldValidateWorld(options)
.mapAttempt(this::cloneWorldCopyFolder)
.mapAttempt(validatedOptions -> {
@ -534,7 +534,7 @@ public class WorldManager {
.worldName(validatedOptions.newWorldName())
.environment(validatedOptions.world().getEnvironment())
.generator(validatedOptions.world().getGenerator());
return importWorld(importWorldOptions).transform(CloneWorldResult.IMPORT_FAILED);
return importWorld(importWorldOptions).transform(CloneFailureReason.IMPORT_FAILED);
})
.onSuccess(newWorld -> {
cloneWorldTransferData(options, newWorld);
@ -542,34 +542,34 @@ public class WorldManager {
});
}
private Attempt<CloneWorldOptions, CloneWorldResult> cloneWorldValidateWorld(
private Attempt<CloneWorldOptions, CloneFailureReason> cloneWorldValidateWorld(
@NotNull CloneWorldOptions options) {
String newWorldName = options.newWorldName();
if (!worldNameChecker.isValidWorldName(newWorldName)) {
Logging.severe("Invalid world name: " + newWorldName);
return worldActionResult(CloneWorldResult.INVALID_WORLDNAME, newWorldName);
return worldActionResult(CloneFailureReason.INVALID_WORLDNAME, newWorldName);
}
if (worldNameChecker.isValidWorldFolder(newWorldName)) {
return worldActionResult(CloneWorldResult.WORLD_EXIST_FOLDER, newWorldName);
return worldActionResult(CloneFailureReason.WORLD_EXIST_FOLDER, newWorldName);
}
if (isLoadedWorld(newWorldName)) {
Logging.severe("World already loaded when attempting to clone: " + newWorldName);
return worldActionResult(CloneWorldResult.WORLD_EXIST_LOADED, newWorldName);
return worldActionResult(CloneFailureReason.WORLD_EXIST_LOADED, newWorldName);
}
if (isWorld(newWorldName)) {
Logging.severe("World already exist unloaded: " + newWorldName);
return worldActionResult(CloneWorldResult.WORLD_EXIST_UNLOADED, newWorldName);
return worldActionResult(CloneFailureReason.WORLD_EXIST_UNLOADED, newWorldName);
}
return worldActionResult(options);
}
private Attempt<CloneWorldOptions, CloneWorldResult> cloneWorldCopyFolder(
private Attempt<CloneWorldOptions, CloneFailureReason> cloneWorldCopyFolder(
@NotNull CloneWorldOptions options) {
// TODO: Check null?
File worldFolder = options.world().getBukkitWorld().map(World::getWorldFolder).getOrNull();
File newWorldFolder = new File(Bukkit.getWorldContainer(), options.newWorldName());
return filesManipulator.copyFolder(worldFolder, newWorldFolder, CLONE_IGNORE_FILES).fold(
exception -> worldActionResult(CloneWorldResult.COPY_FAILED,
exception -> worldActionResult(CloneFailureReason.COPY_FAILED,
options.world().getName(), exception),
success -> worldActionResult(options));
}
@ -602,7 +602,7 @@ public class WorldManager {
* @param options The options for customizing the regeneration of a world.
* @return The result of the regeneration.
*/
public Attempt<LoadedMultiverseWorld, RegenWorldResult> regenWorld(@NotNull RegenWorldOptions options) {
public Attempt<LoadedMultiverseWorld, RegenFailureReason> regenWorld(@NotNull RegenWorldOptions options) {
// TODO: Teleport players out of world, and back in after regen
LoadedMultiverseWorld world = options.world();
@ -615,8 +615,8 @@ public class WorldManager {
.worldType(world.getWorldType().getOrElse(WorldType.NORMAL));
return deleteWorld(world)
.transform(RegenWorldResult.DELETE_FAILED)
.mapAttempt(() -> createWorld(createWorldOptions).transform(RegenWorldResult.CREATE_FAILED))
.transform(RegenFailureReason.DELETE_FAILED)
.mapAttempt(() -> createWorld(createWorldOptions).transform(RegenFailureReason.CREATE_FAILED))
.onSuccess(newWorld -> {
dataTransfer.pasteAllTo(newWorld);
saveWorldsConfig();

View File

@ -1,27 +1,47 @@
package com.onarandombox.MultiverseCore.worldnew.results;
package com.onarandombox.MultiverseCore.worldnew.reasons;
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 clone operation.
*/
public enum CloneWorldResult implements FailureReason {
public enum CloneFailureReason implements FailureReason {
/**
* The world name is invalid.
*/
INVALID_WORLDNAME(MVCorei18n.CLONEWORLD_INVALIDWORLDNAME),
/**
* The target new world folder already exists.
*/
WORLD_EXIST_FOLDER(MVCorei18n.CLONEWORLD_WORLDEXISTFOLDER),
/**
* The target new world is already exist but unloaded.
*/
WORLD_EXIST_UNLOADED(MVCorei18n.CLONEWORLD_WORLDEXISTUNLOADED),
/**
* The target new world is already loaded.
*/
WORLD_EXIST_LOADED(MVCorei18n.CLONEWORLD_WORLDEXISTLOADED),
/**
* Failed to copy the world folder contents.
*/
COPY_FAILED(MVCorei18n.CLONEWORLD_COPYFAILED),
IMPORT_FAILED(null),
MV_WORLD_FAILED(null), // TODO
;
/**
* Failed to import the new world.
*/
IMPORT_FAILED(MVCorei18n.GENERIC_FAILURE);
private final MessageKeyProvider message;
CloneWorldResult(MessageKeyProvider message) {
CloneFailureReason(MessageKeyProvider message) {
this.message = message;
}

View File

@ -1,24 +1,42 @@
package com.onarandombox.MultiverseCore.worldnew.results;
package com.onarandombox.MultiverseCore.worldnew.reasons;
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 creation operation.
*/
public enum CreateWorldResult implements FailureReason {
public enum CreateFailureReason implements FailureReason {
/**
* The world name is invalid.
*/
INVALID_WORLDNAME(MVCorei18n.CREATEWORLD_INVALIDWORLDNAME),
/**
* The target new world folder already exists.
*/
WORLD_EXIST_FOLDER(MVCorei18n.CREATEWORLD_WORLDEXISTFOLDER),
/**
* The target new world is already exist but unloaded.
*/
WORLD_EXIST_UNLOADED(MVCorei18n.CREATEWORLD_WORLDEXISTUNLOADED),
/**
* The target new world is already exist and loaded.
*/
WORLD_EXIST_LOADED(MVCorei18n.CREATEWORLD_WORLDEXISTLOADED),
/**
* Bukkit API failed to create the world.
*/
BUKKIT_CREATION_FAILED(MVCorei18n.CREATEWORLD_BUKKITCREATIONFAILED);
private final MessageKeyProvider message;
CreateWorldResult(MessageKeyProvider message) {
CreateFailureReason(MessageKeyProvider message) {
this.message = message;
}

View File

@ -1,24 +1,42 @@
package com.onarandombox.MultiverseCore.worldnew.results;
package com.onarandombox.MultiverseCore.worldnew.reasons;
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 deletion operation.
*/
public enum DeleteWorldResult implements FailureReason {
public enum DeleteFailureReason implements FailureReason {
/**
* The world does not exist.
*/
WORLD_NON_EXISTENT(MVCorei18n.DELETEWORLD_WORLDNONEXISTENT),
/**
* The world could not be loaded.
*/
LOAD_FAILED(MVCorei18n.DELETEWORLD_LOADFAILED),
/**
* The world could not be unloaded.
*/
WORLD_FOLDER_NOT_FOUND(MVCorei18n.DELETEWORLD_WORLDFOLDERNOTFOUND),
REMOVE_FAILED(null),
/**
* The world could not be removed.
*/
REMOVE_FAILED(MVCorei18n.GENERIC_FAILURE),
/**
* The world folder could not be deleted.
*/
FAILED_TO_DELETE_FOLDER(MVCorei18n.DELETEWORLD_FAILEDTODELETEFOLDER);
private final MessageKeyProvider message;
DeleteWorldResult(MessageKeyProvider message) {
DeleteFailureReason(MessageKeyProvider message) {
this.message = message;
}

View File

@ -1,4 +1,4 @@
package com.onarandombox.MultiverseCore.worldnew.results;
package com.onarandombox.MultiverseCore.worldnew.reasons;
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
@ -8,16 +8,35 @@ import com.onarandombox.MultiverseCore.utils.result.FailureReason;
/**
* Result of a world import operation.
*/
public enum ImportWorldResult implements FailureReason {
public enum ImportFailureReason implements FailureReason {
/**
* The world name is invalid.
*/
INVALID_WORLDNAME(MVCorei18n.IMPORTWORLD_INVALIDWORLDNAME),
/**
* The world folder is invalid.
*/
WORLD_FOLDER_INVALID(MVCorei18n.IMPORTWORLD_WORLDFOLDERINVALID),
/**
* The target world folder already exists. You should load it instead.
*/
WORLD_EXIST_UNLOADED(MVCorei18n.IMPORTWORLD_WORLDEXISTUNLOADED),
/**
* The target world is already exist and loaded.
*/
WORLD_EXIST_LOADED(MVCorei18n.IMPORTWORLD_WORLDEXISTLOADED),
/**
* Bukkit API failed to create the world.
*/
BUKKIT_CREATION_FAILED(MVCorei18n.IMPORTWORLD_BUKKITCREATIONFAILED);
private final MessageKeyProvider message;
ImportWorldResult(MessageKeyProvider message) {
ImportFailureReason(MessageKeyProvider message) {
this.message = message;
}

View File

@ -1,4 +1,4 @@
package com.onarandombox.MultiverseCore.worldnew.results;
package com.onarandombox.MultiverseCore.worldnew.reasons;
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
@ -8,16 +8,35 @@ import com.onarandombox.MultiverseCore.utils.result.FailureReason;
/**
* Result of a world loading operation.
*/
public enum LoadWorldResult implements FailureReason {
public enum LoadFailureReason implements FailureReason {
/**
* Loading operation is underway.
*/
WORLD_ALREADY_LOADING(MVCorei18n.LOADWORLD_WORLDALREADYLOADING),
/**
* The world does not exist.
*/
WORLD_NON_EXISTENT(MVCorei18n.LOADWORLD_WORLDNONEXISTENT),
/**
* The world folder exists but is not known to Multiverse.
*/
WORLD_EXIST_FOLDER(MVCorei18n.LOADWORLD_WORLDEXISTFOLDER),
/**
* The world is already loaded.
*/
WORLD_EXIST_LOADED(MVCorei18n.LOADWORLD_WORLDEXISTLOADED),
/**
* Bukkit API failed to create the world.
*/
BUKKIT_CREATION_FAILED(MVCorei18n.LOADWORLD_BUKKITCREATIONFAILED);
private final MessageKeyProvider message;
LoadWorldResult(MessageKeyProvider message) {
LoadFailureReason(MessageKeyProvider message) {
this.message = message;
}

View File

@ -0,0 +1,32 @@
package com.onarandombox.MultiverseCore.worldnew.reasons;
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason;
/**
* Result of a world regeneration operation.
*/
public enum RegenFailureReason implements FailureReason {
/**
* The world does not exist.
*/
DELETE_FAILED(MVCorei18n.GENERIC_FAILURE),
/**
* The new world could not be created.
*/
CREATE_FAILED(MVCorei18n.GENERIC_FAILURE);
private final MessageKeyProvider message;
RegenFailureReason(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
}

View File

@ -1,4 +1,4 @@
package com.onarandombox.MultiverseCore.worldnew.results;
package com.onarandombox.MultiverseCore.worldnew.reasons;
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
@ -8,13 +8,20 @@ import com.onarandombox.MultiverseCore.utils.result.FailureReason;
/**
* Result of a world removal operation.
*/
public enum RemoveWorldResult implements FailureReason {
public enum RemoveFailureReason implements FailureReason {
/**
* The world does not exist.
*/
WORLD_NON_EXISTENT(MVCorei18n.REMOVEWORLD_WORLDNONEXISTENT),
UNLOAD_FAILED(null);
/**
* The world could not be unloaded.
*/
UNLOAD_FAILED(MVCorei18n.GENERIC_FAILURE);
private final MessageKeyProvider message;
RemoveWorldResult(MessageKeyProvider message) {
RemoveFailureReason(MessageKeyProvider message) {
this.message = message;
}

View File

@ -1,4 +1,4 @@
package com.onarandombox.MultiverseCore.worldnew.results;
package com.onarandombox.MultiverseCore.worldnew.reasons;
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
@ -8,15 +8,30 @@ import com.onarandombox.MultiverseCore.utils.result.FailureReason;
/**
* Result of a world unloading operation.
*/
public enum UnloadWorldResult implements FailureReason {
public enum UnloadFailureReason implements FailureReason {
/**
* Unloading operation is underway.
*/
WORLD_ALREADY_UNLOADING(MVCorei18n.UNLOADWORLD_WORLDALREADYUNLOADING),
/**
* The world does not exist.
*/
WORLD_NON_EXISTENT(MVCorei18n.UNLOADWORLD_WORLDNONEXISTENT),
/**
* The world is already unloaded.
*/
WORLD_UNLOADED(MVCorei18n.UNLOADWORLD_WORLDUNLOADED),
/**
* Bukkit API failed to unload the world.
*/
BUKKIT_UNLOAD_FAILED(MVCorei18n.UNLOADWORLD_BUKKITUNLOADFAILED);
private final MessageKeyProvider message;
UnloadWorldResult(MessageKeyProvider message) {
UnloadFailureReason(MessageKeyProvider message) {
this.message = message;
}

View File

@ -0,0 +1 @@
package com.onarandombox.MultiverseCore.worldnew.reasons;

View File

@ -1,24 +0,0 @@
package com.onarandombox.MultiverseCore.worldnew.results;
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;
import com.onarandombox.MultiverseCore.utils.result.FailureReason;
/**
* Result of a world regeneration operation.
*/
public enum RegenWorldResult implements FailureReason {
DELETE_FAILED(null),
CREATE_FAILED(null);
private final MessageKeyProvider message;
RegenWorldResult(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
}

View File

@ -1 +0,0 @@
package com.onarandombox.MultiverseCore.worldnew.results;