Refactor world results to remove success reason

This commit is contained in:
Ben Woo 2023-09-10 22:29:42 +08:00
parent 656d9ac208
commit 6f9f9085fd
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
19 changed files with 205 additions and 351 deletions

View File

@ -51,34 +51,35 @@ public class CloneCommand extends MultiverseCommand {
@CommandCompletion("@mvworlds:scope=both @empty") @CommandCompletion("@mvworlds:scope=both @empty")
@Syntax("<world> <new world name>") @Syntax("<world> <new world name>")
@Description("{@@mv-core.clone.description}") @Description("{@@mv-core.clone.description}")
public void onCloneCommand(MVCommandIssuer issuer, void onCloneCommand(
MVCommandIssuer issuer,
@Syntax("<world>") @Syntax("<world>")
@Description("{@@mv-core.clone.world.description}") @Description("{@@mv-core.clone.world.description}")
LoadedMultiverseWorld world, LoadedMultiverseWorld world,
@Syntax("<new world name>") @Syntax("<new world name>")
@Description("{@@mv-core.clone.newWorld.description}") @Description("{@@mv-core.clone.newWorld.description}")
String newWorldName, String newWorldName,
@Optional @Optional
@Syntax("") // TODO @Syntax("") // TODO
@Description("{@@mv-core.regen.other.description}") @Description("{@@mv-core.regen.other.description}")
String[] flags String[] flags) {
) {
ParsedCommandFlags parsedFlags = parseFlags(flags); ParsedCommandFlags parsedFlags = parseFlags(flags);
issuer.sendInfo(MVCorei18n.CLONE_CLONING, "{world}", world.getName(), "{newworld}", newWorldName); issuer.sendInfo(MVCorei18n.CLONE_CLONING, "{world}", world.getName(), "{newworld}", newWorldName);
worldManager.cloneWorld(CloneWorldOptions.fromTo(world, newWorldName) CloneWorldOptions cloneWorldOptions = CloneWorldOptions.fromTo(world, newWorldName)
.keepWorldConfig(!parsedFlags.hasFlag("--reset-world-config")) .keepWorldConfig(!parsedFlags.hasFlag("--reset-world-config"))
.keepGameRule(!parsedFlags.hasFlag("--reset-gamerules")) .keepGameRule(!parsedFlags.hasFlag("--reset-gamerules"))
.keepWorldBorder(!parsedFlags.hasFlag("--reset-world-border")) .keepWorldBorder(!parsedFlags.hasFlag("--reset-world-border"));
).onSuccess(newWorld -> { worldManager.cloneWorld(cloneWorldOptions)
Logging.fine("World clone success: " + newWorld); .onSuccess(newWorld -> {
issuer.sendInfo(MVCorei18n.CLONEWORLD_CLONED, "{world}", newWorld.getName()); Logging.fine("World clone success: " + newWorld);
}).onFailure(failure -> { issuer.sendInfo(MVCorei18n.CLONE_SUCCESS, "{world}", newWorld.getName());
Logging.fine("World clone failure: " + failure); }).onFailure(failure -> {
issuer.sendError(failure.getFailureMessage()); Logging.fine("World clone failure: " + failure);
}); issuer.sendError(failure.getFailureMessage());
});
} }
} }

View File

@ -105,7 +105,7 @@ public class CreateCommand extends MultiverseCommand {
.generateStructures(!parsedFlags.hasFlag("--no-structures")) .generateStructures(!parsedFlags.hasFlag("--no-structures"))
).onSuccess(newWorld -> { ).onSuccess(newWorld -> {
Logging.fine("World create success: " + newWorld); Logging.fine("World create success: " + newWorld);
issuer.sendInfo(MVCorei18n.CREATEWORLD_CREATED, "{world}", newWorld.getName()); issuer.sendInfo(MVCorei18n.CREATE_SUCCESS, "{world}", newWorld.getName());
}).onFailure(failure -> { }).onFailure(failure -> {
Logging.fine("World create failure: " + failure); Logging.fine("World create failure: " + failure);
issuer.sendError(failure.getFailureMessage()); issuer.sendError(failure.getFailureMessage());

View File

@ -53,7 +53,7 @@ public class DeleteCommand extends MultiverseCommand {
worldManager.deleteWorld(worldName) worldManager.deleteWorld(worldName)
.onSuccess(deletedWorldName -> { .onSuccess(deletedWorldName -> {
Logging.fine("World delete success: " + deletedWorldName); Logging.fine("World delete success: " + deletedWorldName);
issuer.sendInfo(MVCorei18n.DELETEWORLD_DELETED, "{world}", deletedWorldName); issuer.sendInfo(MVCorei18n.DELETE_SUCCESS, "{world}", deletedWorldName);
}).onFailure(failure -> { }).onFailure(failure -> {
Logging.fine("World delete failure: " + failure); Logging.fine("World delete failure: " + failure);
issuer.sendError(failure.getFailureMessage()); issuer.sendError(failure.getFailureMessage());

View File

@ -81,7 +81,7 @@ public class ImportCommand extends MultiverseCommand {
.useSpawnAdjust(parsedFlags.hasFlag("--adjust-spawn")) .useSpawnAdjust(parsedFlags.hasFlag("--adjust-spawn"))
).onSuccess(newWorld -> { ).onSuccess(newWorld -> {
Logging.fine("World import success: " + newWorld); Logging.fine("World import success: " + newWorld);
issuer.sendInfo(MVCorei18n.IMPORTWORLD_IMPORTED, "{world}", newWorld.getName()); issuer.sendInfo(MVCorei18n.IMPORT_SUCCESS, "{world}", newWorld.getName());
}).onFailure(failure -> { }).onFailure(failure -> {
Logging.fine("World import failure: " + failure); Logging.fine("World import failure: " + failure);
issuer.sendError(failure.getFailureMessage()); issuer.sendError(failure.getFailureMessage());

View File

@ -47,7 +47,7 @@ public class LoadCommand extends MultiverseCommand {
worldManager.loadWorld(worldName) worldManager.loadWorld(worldName)
.onSuccess(newWorld -> { .onSuccess(newWorld -> {
Logging.fine("World load success: " + newWorld); Logging.fine("World load success: " + newWorld);
issuer.sendInfo(MVCorei18n.LOADWORLD_LOADED, "{world}", newWorld.getName()); issuer.sendInfo(MVCorei18n.LOAD_SUCCESS, "{world}", newWorld.getName());
}).onFailure(failure -> { }).onFailure(failure -> {
Logging.fine("World load failure: " + failure); Logging.fine("World load failure: " + failure);
issuer.sendError(failure.getFailureMessage()); issuer.sendError(failure.getFailureMessage());

View File

@ -87,7 +87,7 @@ public class RegenCommand extends MultiverseCommand {
.keepWorldBorder(!parsedFlags.hasFlag("--reset-world-border")) .keepWorldBorder(!parsedFlags.hasFlag("--reset-world-border"))
).onSuccess(newWorld -> { ).onSuccess(newWorld -> {
Logging.fine("World regen success: " + newWorld); Logging.fine("World regen success: " + newWorld);
issuer.sendInfo(MVCorei18n.REGENWORLD_REGENERATED, "{world}", newWorld.getName()); issuer.sendInfo(MVCorei18n.REGEN_SUCCESS, "{world}", newWorld.getName());
}).onFailure(failure -> { }).onFailure(failure -> {
Logging.fine("World regen failure: " + failure); Logging.fine("World regen failure: " + failure);
issuer.sendError(failure.getFailureMessage()); issuer.sendError(failure.getFailureMessage());

View File

@ -44,7 +44,7 @@ public class UnloadCommand extends MultiverseCommand {
worldManager.unloadWorld(world) worldManager.unloadWorld(world)
.onSuccess(loadedWorld -> { .onSuccess(loadedWorld -> {
Logging.fine("World unload success: " + loadedWorld); Logging.fine("World unload success: " + loadedWorld);
issuer.sendInfo(MVCorei18n.UNLOADWORLD_UNLOADED, "{world}", loadedWorld.getName()); issuer.sendInfo(MVCorei18n.UNLOAD_SUCCESS, "{world}", loadedWorld.getName());
}).onFailure(failure -> { }).onFailure(failure -> {
Logging.fine("World unload failure: " + failure); Logging.fine("World unload failure: " + failure);
issuer.sendError(failure.getFailureMessage()); issuer.sendError(failure.getFailureMessage());

View File

@ -16,6 +16,7 @@ public enum MVCorei18n implements MessageKeyProvider {
// clone command // clone command
CLONE_CLONING, CLONE_CLONING,
CLONE_SUCCESS,
// Coordinates command // Coordinates command
COORDINATES_INFO_TITLE, COORDINATES_INFO_TITLE,
@ -34,6 +35,7 @@ public enum MVCorei18n implements MessageKeyProvider {
CREATE_PROPERTIES_GENERATOR, CREATE_PROPERTIES_GENERATOR,
CREATE_PROPERTIES_STRUCTURES, CREATE_PROPERTIES_STRUCTURES,
CREATE_LOADING, CREATE_LOADING,
CREATE_SUCCESS,
// delete command // delete command
DELETE_DELETING, DELETE_DELETING,
@ -56,13 +58,16 @@ public enum MVCorei18n implements MessageKeyProvider {
// import command // import command
IMPORT_IMPORTING, IMPORT_IMPORTING,
IMPORT_SUCCESS,
// load command // load command
LOAD_LOADING, LOAD_LOADING,
LOAD_SUCCESS,
// regen command // regen command
REGEN_REGENERATING, REGEN_REGENERATING,
REGEN_PROMPT, REGEN_PROMPT,
REGEN_SUCCESS,
// reload command // reload command
RELOAD_RELOADING, RELOAD_RELOADING,
@ -77,6 +82,7 @@ public enum MVCorei18n implements MessageKeyProvider {
// unload command // unload command
UNLOAD_UNLOADING, UNLOAD_UNLOADING,
UNLOAD_SUCCESS,
// debug command // debug command
DEBUG_INFO_OFF, DEBUG_INFO_OFF,
@ -94,46 +100,39 @@ public enum MVCorei18n implements MessageKeyProvider {
ENTRYCHECK_NOWORLDACCESS, ENTRYCHECK_NOWORLDACCESS,
// world manager result // world manager result
CLONEWORLD_CLONED,
CLONEWORLD_INVALIDWORLDNAME, CLONEWORLD_INVALIDWORLDNAME,
CLONEWORLD_WORLDEXISTFOLDER, CLONEWORLD_WORLDEXISTFOLDER,
CLONEWORLD_WORLDEXISTUNLOADED, CLONEWORLD_WORLDEXISTUNLOADED,
CLONEWORLD_WORLDEXISTLOADED, CLONEWORLD_WORLDEXISTLOADED,
CLONEWORLD_COPYFAILED, CLONEWORLD_COPYFAILED,
CREATEWORLD_CREATED,
CREATEWORLD_INVALIDWORLDNAME, CREATEWORLD_INVALIDWORLDNAME,
CREATEWORLD_WORLDEXISTFOLDER, CREATEWORLD_WORLDEXISTFOLDER,
CREATEWORLD_WORLDEXISTUNLOADED, CREATEWORLD_WORLDEXISTUNLOADED,
CREATEWORLD_WORLDEXISTLOADED, CREATEWORLD_WORLDEXISTLOADED,
CREATEWORLD_BUKKITCREATIONFAILED, CREATEWORLD_BUKKITCREATIONFAILED,
DELETEWORLD_DELETED, DELETE_SUCCESS,
DELETEWORLD_WORLDNONEXISTENT, DELETEWORLD_WORLDNONEXISTENT,
DELETEWORLD_LOADFAILED, DELETEWORLD_LOADFAILED,
DELETEWORLD_WORLDFOLDERNOTFOUND, DELETEWORLD_WORLDFOLDERNOTFOUND,
DELETEWORLD_FAILEDTODELETEFOLDER, DELETEWORLD_FAILEDTODELETEFOLDER,
IMPORTWORLD_IMPORTED,
IMPORTWORLD_INVALIDWORLDNAME, IMPORTWORLD_INVALIDWORLDNAME,
IMPORTWORLD_WORLDFOLDERINVALID, IMPORTWORLD_WORLDFOLDERINVALID,
IMPORTWORLD_WORLDEXISTUNLOADED, IMPORTWORLD_WORLDEXISTUNLOADED,
IMPORTWORLD_WORLDEXISTLOADED, IMPORTWORLD_WORLDEXISTLOADED,
IMPORTWORLD_BUKKITCREATIONFAILED, IMPORTWORLD_BUKKITCREATIONFAILED,
LOADWORLD_LOADED,
LOADWORLD_WORLDALREADYLOADING, LOADWORLD_WORLDALREADYLOADING,
LOADWORLD_WORLDNONEXISTENT, LOADWORLD_WORLDNONEXISTENT,
LOADWORLD_WORLDEXISTFOLDER, LOADWORLD_WORLDEXISTFOLDER,
LOADWORLD_WORLDEXISTLOADED, LOADWORLD_WORLDEXISTLOADED,
LOADWORLD_BUKKITCREATIONFAILED, LOADWORLD_BUKKITCREATIONFAILED,
REGENWORLD_REGENERATED,
REMOVEWORLD_REMOVED, REMOVEWORLD_REMOVED,
REMOVEWORLD_WORLDNONEXISTENT, REMOVEWORLD_WORLDNONEXISTENT,
UNLOADWORLD_UNLOADED,
UNLOADWORLD_WORLDALREADYUNLOADING, UNLOADWORLD_WORLDALREADYUNLOADING,
UNLOADWORLD_WORLDNONEXISTENT, UNLOADWORLD_WORLDNONEXISTENT,
UNLOADWORLD_WORLDUNLOADED, UNLOADWORLD_WORLDUNLOADED,

View File

@ -6,8 +6,8 @@ import com.onarandombox.MultiverseCore.api.BlockSafety;
import com.onarandombox.MultiverseCore.api.LocationManipulation; import com.onarandombox.MultiverseCore.api.LocationManipulation;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter; import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.utils.message.MessageReplacement; import com.onarandombox.MultiverseCore.utils.message.MessageReplacement;
import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.Attempt; import com.onarandombox.MultiverseCore.utils.result.Attempt;
import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.worldnew.config.WorldConfig; import com.onarandombox.MultiverseCore.worldnew.config.WorldConfig;
import com.onarandombox.MultiverseCore.worldnew.config.WorldsConfigManager; import com.onarandombox.MultiverseCore.worldnew.config.WorldsConfigManager;
import com.onarandombox.MultiverseCore.worldnew.generators.GeneratorProvider; import com.onarandombox.MultiverseCore.worldnew.generators.GeneratorProvider;
@ -169,20 +169,20 @@ public class WorldManager {
* @param options The options for customizing the creation of a new world. * @param options The options for customizing the creation of a new world.
* @return The result of the creation. * @return The result of the creation.
*/ */
public Attempt<LoadedMultiverseWorld, CreateWorldResult.Failure> createWorld(CreateWorldOptions options) { public Attempt<LoadedMultiverseWorld, CreateWorldResult> createWorld(CreateWorldOptions options) {
return validateCreateWorldOptions(options).mapAttempt(this::createValidatedWorld); return validateCreateWorldOptions(options).mapAttempt(this::createValidatedWorld);
} }
private Attempt<CreateWorldOptions, CreateWorldResult.Failure> validateCreateWorldOptions( private Attempt<CreateWorldOptions, CreateWorldResult> validateCreateWorldOptions(
CreateWorldOptions options) { CreateWorldOptions options) {
if (!worldNameChecker.isValidWorldName(options.worldName())) { if (!worldNameChecker.isValidWorldName(options.worldName())) {
return worldActionResult(CreateWorldResult.Failure.INVALID_WORLDNAME, options.worldName()); return worldActionResult(CreateWorldResult.INVALID_WORLDNAME, options.worldName());
} else if (getLoadedWorld(options.worldName()).isDefined()) { } else if (getLoadedWorld(options.worldName()).isDefined()) {
return worldActionResult(CreateWorldResult.Failure.WORLD_EXIST_LOADED, options.worldName()); return worldActionResult(CreateWorldResult.WORLD_EXIST_LOADED, options.worldName());
} else if (getWorld(options.worldName()).isDefined()) { } else if (getWorld(options.worldName()).isDefined()) {
return worldActionResult(CreateWorldResult.Failure.WORLD_EXIST_UNLOADED, options.worldName()); return worldActionResult(CreateWorldResult.WORLD_EXIST_UNLOADED, options.worldName());
} else if (hasWorldFolder(options.worldName())) { } else if (hasWorldFolder(options.worldName())) {
return worldActionResult(CreateWorldResult.Failure.WORLD_EXIST_FOLDER, options.worldName()); return worldActionResult(CreateWorldResult.WORLD_EXIST_FOLDER, options.worldName());
} }
return worldActionResult(options); return worldActionResult(options);
} }
@ -192,7 +192,7 @@ public class WorldManager {
return worldFolder.exists(); return worldFolder.exists();
} }
private Attempt<LoadedMultiverseWorld, CreateWorldResult.Failure> createValidatedWorld( private Attempt<LoadedMultiverseWorld, CreateWorldResult> createValidatedWorld(
CreateWorldOptions options) { CreateWorldOptions options) {
String parsedGenerator = parseGenerator(options.worldName(), options.generator()); String parsedGenerator = parseGenerator(options.worldName(), options.generator());
WorldCreator worldCreator = WorldCreator.name(options.worldName()) WorldCreator worldCreator = WorldCreator.name(options.worldName())
@ -202,7 +202,7 @@ public class WorldManager {
.seed(options.seed()) .seed(options.seed())
.type(options.worldType()); .type(options.worldType());
return createBukkitWorld(worldCreator).fold( return createBukkitWorld(worldCreator).fold(
exception -> worldActionResult(CreateWorldResult.Failure.BUKKIT_CREATION_FAILED, exception -> worldActionResult(CreateWorldResult.BUKKIT_CREATION_FAILED,
options.worldName(), exception), options.worldName(), exception),
world -> { world -> {
LoadedMultiverseWorld loadedWorld = newLoadedMultiverseWorld( LoadedMultiverseWorld loadedWorld = newLoadedMultiverseWorld(
@ -219,34 +219,34 @@ public class WorldManager {
* @param options The options for customizing the import of an existing world folder. * @param options The options for customizing the import of an existing world folder.
* @return The result of the import. * @return The result of the import.
*/ */
public Attempt<LoadedMultiverseWorld, ImportWorldResult.Failure> importWorld( public Attempt<LoadedMultiverseWorld, ImportWorldResult> importWorld(
ImportWorldOptions options) { ImportWorldOptions options) {
return validateImportWorldOptions(options).mapAttempt(this::doImportWorld); return validateImportWorldOptions(options).mapAttempt(this::doImportWorld);
} }
private Attempt<ImportWorldOptions, ImportWorldResult.Failure> validateImportWorldOptions( private Attempt<ImportWorldOptions, ImportWorldResult> validateImportWorldOptions(
ImportWorldOptions options) { ImportWorldOptions options) {
String worldName = options.worldName(); String worldName = options.worldName();
if (!worldNameChecker.isValidWorldName(worldName)) { if (!worldNameChecker.isValidWorldName(worldName)) {
return worldActionResult(ImportWorldResult.Failure.INVALID_WORLDNAME, worldName); return worldActionResult(ImportWorldResult.INVALID_WORLDNAME, worldName);
} else if (!worldNameChecker.isValidWorldFolder(worldName)) { } else if (!worldNameChecker.isValidWorldFolder(worldName)) {
return worldActionResult(ImportWorldResult.Failure.WORLD_FOLDER_INVALID, worldName); return worldActionResult(ImportWorldResult.WORLD_FOLDER_INVALID, worldName);
} else if (isLoadedWorld(worldName)) { } else if (isLoadedWorld(worldName)) {
return worldActionResult(ImportWorldResult.Failure.WORLD_EXIST_LOADED, worldName); return worldActionResult(ImportWorldResult.WORLD_EXIST_LOADED, worldName);
} else if (isWorld(worldName)) { } else if (isWorld(worldName)) {
return worldActionResult(ImportWorldResult.Failure.WORLD_EXIST_UNLOADED, worldName); return worldActionResult(ImportWorldResult.WORLD_EXIST_UNLOADED, worldName);
} }
return worldActionResult(options); return worldActionResult(options);
} }
private Attempt<LoadedMultiverseWorld, ImportWorldResult.Failure> doImportWorld( private Attempt<LoadedMultiverseWorld, ImportWorldResult> doImportWorld(
ImportWorldOptions options) { ImportWorldOptions options) {
String parsedGenerator = parseGenerator(options.worldName(), options.generator()); String parsedGenerator = parseGenerator(options.worldName(), options.generator());
WorldCreator worldCreator = WorldCreator.name(options.worldName()) WorldCreator worldCreator = WorldCreator.name(options.worldName())
.environment(options.environment()) .environment(options.environment())
.generator(parsedGenerator); .generator(parsedGenerator);
return createBukkitWorld(worldCreator).fold( return createBukkitWorld(worldCreator).fold(
exception -> worldActionResult(ImportWorldResult.Failure.BUKKIT_CREATION_FAILED, exception -> worldActionResult(ImportWorldResult.BUKKIT_CREATION_FAILED,
options.worldName(), exception), options.worldName(), exception),
world -> { world -> {
LoadedMultiverseWorld loadedWorld = newLoadedMultiverseWorld(world, LoadedMultiverseWorld loadedWorld = newLoadedMultiverseWorld(world,
@ -302,12 +302,12 @@ public class WorldManager {
* @param worldName The name of the world to load. * @param worldName The name of the world to load.
* @return The result of the load. * @return The result of the load.
*/ */
public Attempt<LoadedMultiverseWorld, LoadWorldResult.Failure> loadWorld(@NotNull String worldName) { public Attempt<LoadedMultiverseWorld, LoadWorldResult> loadWorld(@NotNull String worldName) {
return getWorld(worldName) return getWorld(worldName)
.map(this::loadWorld) .map(this::loadWorld)
.getOrElse(() -> worldNameChecker.isValidWorldFolder(worldName) .getOrElse(() -> worldNameChecker.isValidWorldFolder(worldName)
? worldActionResult(LoadWorldResult.Failure.WORLD_EXIST_FOLDER, worldName) ? worldActionResult(LoadWorldResult.WORLD_EXIST_FOLDER, worldName)
: worldActionResult(LoadWorldResult.Failure.WORLD_NON_EXISTENT, worldName)); : worldActionResult(LoadWorldResult.WORLD_NON_EXISTENT, worldName));
} }
/** /**
@ -316,29 +316,29 @@ public class WorldManager {
* @param world The world to load. * @param world The world to load.
* @return The result of the load. * @return The result of the load.
*/ */
public Attempt<LoadedMultiverseWorld, LoadWorldResult.Failure> loadWorld(@NotNull MultiverseWorld world) { public Attempt<LoadedMultiverseWorld, LoadWorldResult> loadWorld(@NotNull MultiverseWorld world) {
return validateWorldToLoad(world).mapAttempt(this::doLoadWorld); return validateWorldToLoad(world).mapAttempt(this::doLoadWorld);
} }
private Attempt<MultiverseWorld, LoadWorldResult.Failure> validateWorldToLoad( private Attempt<MultiverseWorld, LoadWorldResult> validateWorldToLoad(
@NotNull MultiverseWorld mvWorld) { @NotNull MultiverseWorld mvWorld) {
if (loadTracker.contains(mvWorld.getName())) { if (loadTracker.contains(mvWorld.getName())) {
// This is to prevent recursive calls by WorldLoadEvent // This is to prevent recursive calls by WorldLoadEvent
Logging.fine("World already loading: " + mvWorld.getName()); Logging.fine("World already loading: " + mvWorld.getName());
return worldActionResult(LoadWorldResult.Failure.WORLD_ALREADY_LOADING, mvWorld.getName()); return worldActionResult(LoadWorldResult.WORLD_ALREADY_LOADING, mvWorld.getName());
} else if (isLoadedWorld(mvWorld)) { } else if (isLoadedWorld(mvWorld)) {
Logging.severe("World already loaded: " + mvWorld.getName()); Logging.severe("World already loaded: " + mvWorld.getName());
return worldActionResult(LoadWorldResult.Failure.WORLD_EXIST_LOADED, mvWorld.getName()); return worldActionResult(LoadWorldResult.WORLD_EXIST_LOADED, mvWorld.getName());
} }
return worldActionResult(mvWorld); return worldActionResult(mvWorld);
} }
private Attempt<LoadedMultiverseWorld, LoadWorldResult.Failure> doLoadWorld(@NotNull MultiverseWorld mvWorld) { private Attempt<LoadedMultiverseWorld, LoadWorldResult> doLoadWorld(@NotNull MultiverseWorld mvWorld) {
return createBukkitWorld(WorldCreator.name(mvWorld.getName()) return createBukkitWorld(WorldCreator.name(mvWorld.getName())
.environment(mvWorld.getEnvironment()) .environment(mvWorld.getEnvironment())
.generator(Strings.isNullOrEmpty(mvWorld.getGenerator()) ? null : mvWorld.getGenerator()) .generator(Strings.isNullOrEmpty(mvWorld.getGenerator()) ? null : mvWorld.getGenerator())
.seed(mvWorld.getSeed())).fold( .seed(mvWorld.getSeed())).fold(
exception -> worldActionResult(LoadWorldResult.Failure.BUKKIT_CREATION_FAILED, exception -> worldActionResult(LoadWorldResult.BUKKIT_CREATION_FAILED,
mvWorld.getName(), exception), mvWorld.getName(), exception),
world -> { world -> {
// TODO: Check worldConfig null // TODO: Check worldConfig null
@ -361,7 +361,7 @@ public class WorldManager {
* @param world The bukkit world to unload. * @param world The bukkit world to unload.
* @return The result of the unload action. * @return The result of the unload action.
*/ */
public Attempt<MultiverseWorld, UnloadWorldResult.Failure> unloadWorld(@NotNull World world) { public Attempt<MultiverseWorld, UnloadWorldResult> unloadWorld(@NotNull World world) {
return unloadWorld(world.getName()); return unloadWorld(world.getName());
} }
@ -371,12 +371,12 @@ public class WorldManager {
* @param worldName The name of the world to unload. * @param worldName The name of the world to unload.
* @return The result of the unload action. * @return The result of the unload action.
*/ */
public Attempt<MultiverseWorld, UnloadWorldResult.Failure> unloadWorld(@NotNull String worldName) { public Attempt<MultiverseWorld, UnloadWorldResult> unloadWorld(@NotNull String worldName) {
return getLoadedWorld(worldName) return getLoadedWorld(worldName)
.map(this::unloadWorld) .map(this::unloadWorld)
.getOrElse(() -> isUnloadedWorld(worldName) .getOrElse(() -> isUnloadedWorld(worldName)
? worldActionResult(UnloadWorldResult.Failure.WORLD_UNLOADED, worldName) ? worldActionResult(UnloadWorldResult.WORLD_UNLOADED, worldName)
: worldActionResult(UnloadWorldResult.Failure.WORLD_NON_EXISTENT, worldName)); : worldActionResult(UnloadWorldResult.WORLD_NON_EXISTENT, worldName));
} }
/** /**
@ -385,23 +385,23 @@ public class WorldManager {
* @param world The multiverse world to unload. * @param world The multiverse world to unload.
* @return The result of the unload action. * @return The result of the unload action.
*/ */
public Attempt<MultiverseWorld, UnloadWorldResult.Failure> unloadWorld( public Attempt<MultiverseWorld, UnloadWorldResult> unloadWorld(
@NotNull LoadedMultiverseWorld world) { @NotNull LoadedMultiverseWorld world) {
if (unloadTracker.contains(world.getName())) { if (unloadTracker.contains(world.getName())) {
// This is to prevent recursive calls by WorldUnloadEvent // This is to prevent recursive calls by WorldUnloadEvent
Logging.fine("World already unloading: " + world.getName()); Logging.fine("World already unloading: " + world.getName());
return worldActionResult(UnloadWorldResult.Failure.WORLD_ALREADY_UNLOADING, world.getName()); return worldActionResult(UnloadWorldResult.WORLD_ALREADY_UNLOADING, world.getName());
} }
// TODO: removePlayersFromWorld? // TODO: removePlayersFromWorld?
return unloadBukkitWorld(world.getBukkitWorld().getOrNull()).fold( return unloadBukkitWorld(world.getBukkitWorld().getOrNull()).fold(
exception -> worldActionResult(UnloadWorldResult.Failure.BUKKIT_UNLOAD_FAILED, exception -> worldActionResult(UnloadWorldResult.BUKKIT_UNLOAD_FAILED,
world.getName(), exception), world.getName(), exception),
success -> Option.of(loadedWorldsMap.remove(world.getName())).fold( success -> Option.of(loadedWorldsMap.remove(world.getName())).fold(
() -> { () -> {
Logging.severe("Failed to remove world from map: " + world.getName()); Logging.severe("Failed to remove world from map: " + world.getName());
return worldActionResult(UnloadWorldResult.Failure.WORLD_NON_EXISTENT, world.getName()); return worldActionResult(UnloadWorldResult.WORLD_NON_EXISTENT, world.getName());
}, },
mvWorld -> { mvWorld -> {
Logging.fine("Removed MultiverseWorld from map: " + world.getName()); Logging.fine("Removed MultiverseWorld from map: " + world.getName());
@ -417,11 +417,11 @@ public class WorldManager {
* @param worldName The name of the world to remove. * @param worldName The name of the world to remove.
* @return The result of the remove. * @return The result of the remove.
*/ */
public Attempt<String, RemoveWorldResult.Failure> removeWorld( public Attempt<String, RemoveWorldResult> removeWorld(
@NotNull String worldName) { @NotNull String worldName) {
return getWorld(worldName) return getWorld(worldName)
.map(this::removeWorld) .map(this::removeWorld)
.getOrElse(() -> worldActionResult(RemoveWorldResult.Failure.WORLD_NON_EXISTENT, worldName)); .getOrElse(() -> worldActionResult(RemoveWorldResult.WORLD_NON_EXISTENT, worldName));
} }
/** /**
@ -431,7 +431,7 @@ public class WorldManager {
* @param world The multiverse world to remove. * @param world The multiverse world to remove.
* @return The result of the remove. * @return The result of the remove.
*/ */
public Attempt<String, RemoveWorldResult.Failure> removeWorld(@NotNull MultiverseWorld world) { public Attempt<String, RemoveWorldResult> removeWorld(@NotNull MultiverseWorld world) {
return getLoadedWorld(world).fold( return getLoadedWorld(world).fold(
() -> removeWorldFromConfig(world), () -> removeWorldFromConfig(world),
this::removeWorld); this::removeWorld);
@ -444,13 +444,10 @@ public class WorldManager {
* @param loadedWorld The multiverse world to remove. * @param loadedWorld The multiverse world to remove.
* @return The result of the remove. * @return The result of the remove.
*/ */
public Attempt<String, RemoveWorldResult.Failure> removeWorld( public Attempt<String, RemoveWorldResult> removeWorld(@NotNull LoadedMultiverseWorld loadedWorld) {
@NotNull LoadedMultiverseWorld loadedWorld) { return unloadWorld(loadedWorld)
var result = unloadWorld(loadedWorld); .transform(RemoveWorldResult.UNLOAD_FAILED)
if (result.isFailure()) { .mapAttempt(this::removeWorldFromConfig);
return Attempt.failure(RemoveWorldResult.Failure.UNLOAD_FAILED, result.getFailureMessage());
}
return removeWorldFromConfig(loadedWorld);
} }
/** /**
@ -459,8 +456,7 @@ public class WorldManager {
* @param world The multiverse world to remove. * @param world The multiverse world to remove.
* @return The result of the remove. * @return The result of the remove.
*/ */
private Attempt<String, RemoveWorldResult.Failure> private Attempt<String, RemoveWorldResult> removeWorldFromConfig(@NotNull MultiverseWorld world) {
removeWorldFromConfig(@NotNull MultiverseWorld world) {
// Remove world from config // Remove world from config
worldsMap.remove(world.getName()); worldsMap.remove(world.getName());
worldsConfigManager.deleteWorldConfig(world.getName()); worldsConfigManager.deleteWorldConfig(world.getName());
@ -476,10 +472,10 @@ public class WorldManager {
* @param worldName The name of the world to delete. * @param worldName The name of the world to delete.
* @return The result of the delete action. * @return The result of the delete action.
*/ */
public Attempt<String, DeleteWorldResult.Failure> deleteWorld(@NotNull String worldName) { public Attempt<String, DeleteWorldResult> deleteWorld(@NotNull String worldName) {
return getWorld(worldName) return getWorld(worldName)
.map(this::deleteWorld) .map(this::deleteWorld)
.getOrElse(() -> worldActionResult(DeleteWorldResult.Failure.WORLD_NON_EXISTENT, worldName)); .getOrElse(() -> worldActionResult(DeleteWorldResult.WORLD_NON_EXISTENT, worldName));
} }
/** /**
@ -489,10 +485,10 @@ public class WorldManager {
* @param world The world to delete. * @param world The world to delete.
* @return The result of the delete action. * @return The result of the delete action.
*/ */
public Attempt<String, DeleteWorldResult.Failure> deleteWorld(@NotNull MultiverseWorld world) { public Attempt<String, DeleteWorldResult> deleteWorld(@NotNull MultiverseWorld world) {
return getLoadedWorld(world).fold( return getLoadedWorld(world).fold(
() -> loadWorld(world) () -> loadWorld(world)
.convertReason(DeleteWorldResult.Failure.LOAD_FAILED) .convertReason(DeleteWorldResult.LOAD_FAILED)
.mapAttempt(this::deleteWorld), .mapAttempt(this::deleteWorld),
this::deleteWorld); this::deleteWorld);
} }
@ -503,24 +499,24 @@ public class WorldManager {
* @param world The multiverse world to delete. * @param world The multiverse world to delete.
* @return The result of the delete action. * @return The result of the delete action.
*/ */
public Attempt<String, DeleteWorldResult.Failure> deleteWorld(@NotNull LoadedMultiverseWorld world) { public Attempt<String, DeleteWorldResult> deleteWorld(@NotNull LoadedMultiverseWorld world) {
// TODO: Possible config options to keep certain files // TODO: Possible config options to keep certain files
AtomicReference<File> worldFolder = new AtomicReference<>(); AtomicReference<File> worldFolder = new AtomicReference<>();
return validateWorldToDelete(world) return validateWorldToDelete(world)
.peek(worldFolder::set) .peek(worldFolder::set)
.mapAttempt(() -> removeWorld(world).transform(DeleteWorldResult.Failure.REMOVE_FAILED)) .mapAttempt(() -> removeWorld(world).transform(DeleteWorldResult.REMOVE_FAILED))
.mapAttempt(() -> filesManipulator.deleteFolder(worldFolder.get()).fold( .mapAttempt(() -> filesManipulator.deleteFolder(worldFolder.get()).fold(
exception -> worldActionResult(DeleteWorldResult.Failure.FAILED_TO_DELETE_FOLDER, exception -> worldActionResult(DeleteWorldResult.FAILED_TO_DELETE_FOLDER,
world.getName(), exception), world.getName(), exception),
success -> worldActionResult(world.getName()))); success -> worldActionResult(world.getName())));
} }
private Attempt<File, DeleteWorldResult.Failure> validateWorldToDelete( private Attempt<File, DeleteWorldResult> validateWorldToDelete(
@NotNull LoadedMultiverseWorld world) { @NotNull LoadedMultiverseWorld world) {
File worldFolder = world.getBukkitWorld().map(World::getWorldFolder).getOrNull(); File worldFolder = world.getBukkitWorld().map(World::getWorldFolder).getOrNull();
if (worldFolder == null || !worldNameChecker.isValidWorldFolder(worldFolder)) { if (worldFolder == null || !worldNameChecker.isValidWorldFolder(worldFolder)) {
Logging.severe("Failed to get world folder for world: " + world.getName()); Logging.severe("Failed to get world folder for world: " + world.getName());
return worldActionResult(DeleteWorldResult.Failure.WORLD_FOLDER_NOT_FOUND, world.getName()); return worldActionResult(DeleteWorldResult.WORLD_FOLDER_NOT_FOUND, world.getName());
} }
return worldActionResult(worldFolder); return worldActionResult(worldFolder);
} }
@ -531,14 +527,15 @@ public class WorldManager {
* @param options The options for customizing the cloning of a world. * @param options The options for customizing the cloning of a world.
* @return The result of the clone. * @return The result of the clone.
*/ */
public Attempt<LoadedMultiverseWorld, CloneWorldResult.Failure> cloneWorld(@NotNull CloneWorldOptions options) { public Attempt<LoadedMultiverseWorld, CloneWorldResult> cloneWorld(@NotNull CloneWorldOptions options) {
return cloneWorldValidateWorld(options) return cloneWorldValidateWorld(options)
.mapAttempt(this::cloneWorldCopyFolder) .mapAttempt(this::cloneWorldCopyFolder)
.mapAttempt(validatedOptions -> { .mapAttempt(validatedOptions -> {
ImportWorldOptions importWorldOptions = ImportWorldOptions.worldName(validatedOptions.newWorldName()) ImportWorldOptions importWorldOptions = ImportWorldOptions
.worldName(validatedOptions.newWorldName())
.environment(validatedOptions.world().getEnvironment()) .environment(validatedOptions.world().getEnvironment())
.generator(validatedOptions.world().getGenerator()); .generator(validatedOptions.world().getGenerator());
return importWorld(importWorldOptions).convertReason(CloneWorldResult.Failure.IMPORT_FAILED); return importWorld(importWorldOptions).convertReason(CloneWorldResult.IMPORT_FAILED);
}) })
.onSuccess(newWorld -> { .onSuccess(newWorld -> {
cloneWorldTransferData(options, newWorld); cloneWorldTransferData(options, newWorld);
@ -546,34 +543,34 @@ public class WorldManager {
}); });
} }
private Attempt<CloneWorldOptions, CloneWorldResult.Failure> cloneWorldValidateWorld( private Attempt<CloneWorldOptions, CloneWorldResult> cloneWorldValidateWorld(
@NotNull CloneWorldOptions options) { @NotNull CloneWorldOptions options) {
String newWorldName = options.newWorldName(); String newWorldName = options.newWorldName();
if (!worldNameChecker.isValidWorldName(newWorldName)) { if (!worldNameChecker.isValidWorldName(newWorldName)) {
Logging.severe("Invalid world name: " + newWorldName); Logging.severe("Invalid world name: " + newWorldName);
return worldActionResult(CloneWorldResult.Failure.INVALID_WORLDNAME, newWorldName); return worldActionResult(CloneWorldResult.INVALID_WORLDNAME, newWorldName);
} }
if (worldNameChecker.isValidWorldFolder(newWorldName)) { if (worldNameChecker.isValidWorldFolder(newWorldName)) {
return worldActionResult(CloneWorldResult.Failure.WORLD_EXIST_FOLDER, newWorldName); return worldActionResult(CloneWorldResult.WORLD_EXIST_FOLDER, newWorldName);
} }
if (isLoadedWorld(newWorldName)) { if (isLoadedWorld(newWorldName)) {
Logging.severe("World already loaded when attempting to clone: " + newWorldName); Logging.severe("World already loaded when attempting to clone: " + newWorldName);
return worldActionResult(CloneWorldResult.Failure.WORLD_EXIST_LOADED, newWorldName); return worldActionResult(CloneWorldResult.WORLD_EXIST_LOADED, newWorldName);
} }
if (isWorld(newWorldName)) { if (isWorld(newWorldName)) {
Logging.severe("World already exist unloaded: " + newWorldName); Logging.severe("World already exist unloaded: " + newWorldName);
return worldActionResult(CloneWorldResult.Failure.WORLD_EXIST_UNLOADED, newWorldName); return worldActionResult(CloneWorldResult.WORLD_EXIST_UNLOADED, newWorldName);
} }
return worldActionResult(options); return worldActionResult(options);
} }
private Attempt<CloneWorldOptions, CloneWorldResult.Failure> cloneWorldCopyFolder( private Attempt<CloneWorldOptions, CloneWorldResult> cloneWorldCopyFolder(
@NotNull CloneWorldOptions options) { @NotNull CloneWorldOptions options) {
// TODO: Check null? // TODO: Check null?
File worldFolder = options.world().getBukkitWorld().map(World::getWorldFolder).getOrNull(); File worldFolder = options.world().getBukkitWorld().map(World::getWorldFolder).getOrNull();
File newWorldFolder = new File(Bukkit.getWorldContainer(), options.newWorldName()); File newWorldFolder = new File(Bukkit.getWorldContainer(), options.newWorldName());
return filesManipulator.copyFolder(worldFolder, newWorldFolder, CLONE_IGNORE_FILES).fold( return filesManipulator.copyFolder(worldFolder, newWorldFolder, CLONE_IGNORE_FILES).fold(
exception -> worldActionResult(CloneWorldResult.Failure.COPY_FAILED, exception -> worldActionResult(CloneWorldResult.COPY_FAILED,
options.world().getName(), exception), options.world().getName(), exception),
success -> worldActionResult(options)); success -> worldActionResult(options));
} }
@ -606,7 +603,7 @@ public class WorldManager {
* @param options The options for customizing the regeneration of a world. * @param options The options for customizing the regeneration of a world.
* @return The result of the regeneration. * @return The result of the regeneration.
*/ */
public Attempt<LoadedMultiverseWorld, RegenWorldResult.Failure> regenWorld(@NotNull RegenWorldOptions options) { public Attempt<LoadedMultiverseWorld, RegenWorldResult> regenWorld(@NotNull RegenWorldOptions options) {
// TODO: Teleport players out of world, and back in after regen // TODO: Teleport players out of world, and back in after regen
LoadedMultiverseWorld world = options.world(); LoadedMultiverseWorld world = options.world();
@ -619,8 +616,8 @@ public class WorldManager {
.worldType(world.getWorldType().getOrElse(WorldType.NORMAL)); .worldType(world.getWorldType().getOrElse(WorldType.NORMAL));
return deleteWorld(world) return deleteWorld(world)
.convertReason(RegenWorldResult.Failure.DELETE_FAILED) .convertReason(RegenWorldResult.DELETE_FAILED)
.mapAttempt(() -> createWorld(createWorldOptions).convertReason(RegenWorldResult.Failure.CREATE_FAILED)) .mapAttempt(() -> createWorld(createWorldOptions).convertReason(RegenWorldResult.CREATE_FAILED))
.onSuccess(newWorld -> { .onSuccess(newWorld -> {
dataTransfer.pasteAllTo(newWorld); dataTransfer.pasteAllTo(newWorld);
saveWorldsConfig(); saveWorldsConfig();
@ -632,14 +629,14 @@ public class WorldManager {
} }
private <T, F extends FailureReason> Attempt<T, F> worldActionResult( private <T, F extends FailureReason> Attempt<T, F> worldActionResult(
@NotNull F messageKeyProvider, @NotNull String worldName) { @NotNull F failureReason, @NotNull String worldName) {
return Attempt.failure(messageKeyProvider, replaceWorldName(worldName)); return Attempt.failure(failureReason, replaceWorldName(worldName));
} }
private <T, F extends FailureReason> Attempt<T, F> worldActionResult( private <T, F extends FailureReason> Attempt<T, F> worldActionResult(
@NotNull F messageKeyProvider, @NotNull String worldName, @NotNull Throwable error) { @NotNull F failureReason, @NotNull String worldName, @NotNull Throwable error) {
// TODO: Localize error message if its a MultiverseException // TODO: Localize error message if its a MultiverseException
return Attempt.failure(messageKeyProvider, replaceWorldName(worldName), replaceError(error.getMessage())); return Attempt.failure(failureReason, replaceWorldName(worldName), replaceError(error.getMessage()));
} }
private MessageReplacement replaceWorldName(@NotNull String worldName) { private MessageReplacement replaceWorldName(@NotNull String worldName) {

View File

@ -9,41 +9,24 @@ import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/** /**
* Result of a world clone operation. * Result of a world clone operation.
*/ */
public class CloneWorldResult { public enum CloneWorldResult implements FailureReason {
public enum Success implements SuccessReason { INVALID_WORLDNAME(MVCorei18n.CLONEWORLD_INVALIDWORLDNAME),
CLONED(MVCorei18n.CLONEWORLD_CLONED); WORLD_EXIST_FOLDER(MVCorei18n.CLONEWORLD_WORLDEXISTFOLDER),
WORLD_EXIST_UNLOADED(MVCorei18n.CLONEWORLD_WORLDEXISTUNLOADED),
WORLD_EXIST_LOADED(MVCorei18n.CLONEWORLD_WORLDEXISTLOADED),
COPY_FAILED(MVCorei18n.CLONEWORLD_COPYFAILED),
IMPORT_FAILED(null),
MV_WORLD_FAILED(null), // TODO
;
private final MessageKeyProvider message; private final MessageKeyProvider message;
Success(MessageKeyProvider message) { CloneWorldResult(MessageKeyProvider message) {
this.message = message; this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
public enum Failure implements FailureReason { @Override
INVALID_WORLDNAME(MVCorei18n.CLONEWORLD_INVALIDWORLDNAME), public MessageKey getMessageKey() {
WORLD_EXIST_FOLDER(MVCorei18n.CLONEWORLD_WORLDEXISTFOLDER), return message.getMessageKey();
WORLD_EXIST_UNLOADED(MVCorei18n.CLONEWORLD_WORLDEXISTUNLOADED),
WORLD_EXIST_LOADED(MVCorei18n.CLONEWORLD_WORLDEXISTLOADED),
COPY_FAILED(MVCorei18n.CLONEWORLD_COPYFAILED),
IMPORT_FAILED(null),
MV_WORLD_FAILED(null), // TODO
;
private final MessageKeyProvider message;
Failure(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
} }

View File

@ -9,38 +9,21 @@ import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/** /**
* Result of a world creation operation. * Result of a world creation operation.
*/ */
public class CreateWorldResult { public enum CreateWorldResult implements FailureReason {
public enum Success implements SuccessReason { INVALID_WORLDNAME(MVCorei18n.CREATEWORLD_INVALIDWORLDNAME),
CREATED(MVCorei18n.CREATEWORLD_CREATED); WORLD_EXIST_FOLDER(MVCorei18n.CREATEWORLD_WORLDEXISTFOLDER),
WORLD_EXIST_UNLOADED(MVCorei18n.CREATEWORLD_WORLDEXISTUNLOADED),
WORLD_EXIST_LOADED(MVCorei18n.CREATEWORLD_WORLDEXISTLOADED),
BUKKIT_CREATION_FAILED(MVCorei18n.CREATEWORLD_BUKKITCREATIONFAILED);
private final MessageKeyProvider message; private final MessageKeyProvider message;
Success(MessageKeyProvider message) { CreateWorldResult(MessageKeyProvider message) {
this.message = message; this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
public enum Failure implements FailureReason { @Override
INVALID_WORLDNAME(MVCorei18n.CREATEWORLD_INVALIDWORLDNAME), public MessageKey getMessageKey() {
WORLD_EXIST_FOLDER(MVCorei18n.CREATEWORLD_WORLDEXISTFOLDER), return message.getMessageKey();
WORLD_EXIST_UNLOADED(MVCorei18n.CREATEWORLD_WORLDEXISTUNLOADED),
WORLD_EXIST_LOADED(MVCorei18n.CREATEWORLD_WORLDEXISTLOADED),
BUKKIT_CREATION_FAILED(MVCorei18n.CREATEWORLD_BUKKITCREATIONFAILED);
private final MessageKeyProvider message;
Failure(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
} }

View File

@ -9,38 +9,21 @@ import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/** /**
* Result of a world deletion operation. * Result of a world deletion operation.
*/ */
public class DeleteWorldResult { public enum DeleteWorldResult implements FailureReason {
public enum Success implements SuccessReason { WORLD_NON_EXISTENT(MVCorei18n.DELETEWORLD_WORLDNONEXISTENT),
DELETED(MVCorei18n.DELETEWORLD_DELETED); LOAD_FAILED(MVCorei18n.DELETEWORLD_LOADFAILED),
WORLD_FOLDER_NOT_FOUND(MVCorei18n.DELETEWORLD_WORLDFOLDERNOTFOUND),
REMOVE_FAILED(null),
FAILED_TO_DELETE_FOLDER(MVCorei18n.DELETEWORLD_FAILEDTODELETEFOLDER);
private final MessageKeyProvider message; private final MessageKeyProvider message;
Success(MessageKeyProvider message) { DeleteWorldResult(MessageKeyProvider message) {
this.message = message; this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
public enum Failure implements FailureReason { @Override
WORLD_NON_EXISTENT(MVCorei18n.DELETEWORLD_WORLDNONEXISTENT), public MessageKey getMessageKey() {
LOAD_FAILED(MVCorei18n.DELETEWORLD_LOADFAILED), return message.getMessageKey();
WORLD_FOLDER_NOT_FOUND(MVCorei18n.DELETEWORLD_WORLDFOLDERNOTFOUND),
REMOVE_FAILED(null),
FAILED_TO_DELETE_FOLDER(MVCorei18n.DELETEWORLD_FAILEDTODELETEFOLDER);
private final MessageKeyProvider message;
Failure(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
} }

View File

@ -4,43 +4,25 @@ import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider; import co.aikar.locales.MessageKeyProvider;
import com.onarandombox.MultiverseCore.utils.MVCorei18n; import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason; import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/** /**
* Result of a world import operation. * Result of a world import operation.
*/ */
public class ImportWorldResult { public enum ImportWorldResult implements FailureReason {
public enum Success implements SuccessReason { INVALID_WORLDNAME(MVCorei18n.IMPORTWORLD_INVALIDWORLDNAME),
IMPORTED(MVCorei18n.IMPORTWORLD_IMPORTED); WORLD_FOLDER_INVALID(MVCorei18n.IMPORTWORLD_WORLDFOLDERINVALID),
WORLD_EXIST_UNLOADED(MVCorei18n.IMPORTWORLD_WORLDEXISTUNLOADED),
WORLD_EXIST_LOADED(MVCorei18n.IMPORTWORLD_WORLDEXISTLOADED),
BUKKIT_CREATION_FAILED(MVCorei18n.IMPORTWORLD_BUKKITCREATIONFAILED);
private final MessageKeyProvider message; private final MessageKeyProvider message;
Success(MessageKeyProvider message) { ImportWorldResult(MessageKeyProvider message) {
this.message = message; this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
public enum Failure implements FailureReason { @Override
INVALID_WORLDNAME(MVCorei18n.IMPORTWORLD_INVALIDWORLDNAME), public MessageKey getMessageKey() {
WORLD_FOLDER_INVALID(MVCorei18n.IMPORTWORLD_WORLDFOLDERINVALID), return message.getMessageKey();
WORLD_EXIST_UNLOADED(MVCorei18n.IMPORTWORLD_WORLDEXISTUNLOADED),
WORLD_EXIST_LOADED(MVCorei18n.IMPORTWORLD_WORLDEXISTLOADED),
BUKKIT_CREATION_FAILED(MVCorei18n.IMPORTWORLD_BUKKITCREATIONFAILED);
private final MessageKeyProvider message;
Failure(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
} }

View File

@ -4,43 +4,25 @@ import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider; import co.aikar.locales.MessageKeyProvider;
import com.onarandombox.MultiverseCore.utils.MVCorei18n; import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason; import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/** /**
* Result of a world loading operation. * Result of a world loading operation.
*/ */
public class LoadWorldResult { public enum LoadWorldResult implements FailureReason {
public enum Success implements SuccessReason { WORLD_ALREADY_LOADING(MVCorei18n.LOADWORLD_WORLDALREADYLOADING),
LOADED(MVCorei18n.LOADWORLD_LOADED); WORLD_NON_EXISTENT(MVCorei18n.LOADWORLD_WORLDNONEXISTENT),
WORLD_EXIST_FOLDER(MVCorei18n.LOADWORLD_WORLDEXISTFOLDER),
WORLD_EXIST_LOADED(MVCorei18n.LOADWORLD_WORLDEXISTLOADED),
BUKKIT_CREATION_FAILED(MVCorei18n.LOADWORLD_BUKKITCREATIONFAILED);
private final MessageKeyProvider message; private final MessageKeyProvider message;
Success(MessageKeyProvider message) { LoadWorldResult(MessageKeyProvider message) {
this.message = message; this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
public enum Failure implements FailureReason { @Override
WORLD_ALREADY_LOADING(MVCorei18n.LOADWORLD_WORLDALREADYLOADING), public MessageKey getMessageKey() {
WORLD_NON_EXISTENT(MVCorei18n.LOADWORLD_WORLDNONEXISTENT), return message.getMessageKey();
WORLD_EXIST_FOLDER(MVCorei18n.LOADWORLD_WORLDEXISTFOLDER),
WORLD_EXIST_LOADED(MVCorei18n.LOADWORLD_WORLDEXISTLOADED),
BUKKIT_CREATION_FAILED(MVCorei18n.LOADWORLD_BUKKITCREATIONFAILED);
private final MessageKeyProvider message;
Failure(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
} }

View File

@ -2,42 +2,23 @@ package com.onarandombox.MultiverseCore.worldnew.results;
import co.aikar.locales.MessageKey; import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider; import co.aikar.locales.MessageKeyProvider;
import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason; import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/** /**
* Result of a world regeneration operation. * Result of a world regeneration operation.
*/ */
public class RegenWorldResult { public enum RegenWorldResult implements FailureReason {
public enum Success implements SuccessReason { DELETE_FAILED(null),
REGENERATED(MVCorei18n.REGENWORLD_REGENERATED); CREATE_FAILED(null);
private final MessageKeyProvider message; private final MessageKeyProvider message;
Success(MessageKeyProvider message) { RegenWorldResult(MessageKeyProvider message) {
this.message = message; this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
public enum Failure implements FailureReason { @Override
DELETE_FAILED(null), public MessageKey getMessageKey() {
CREATE_FAILED(null); return message.getMessageKey();
private final MessageKeyProvider message;
Failure(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
} }

View File

@ -4,40 +4,22 @@ import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider; import co.aikar.locales.MessageKeyProvider;
import com.onarandombox.MultiverseCore.utils.MVCorei18n; import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason; import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/** /**
* Result of a world removal operation. * Result of a world removal operation.
*/ */
public class RemoveWorldResult { public enum RemoveWorldResult implements FailureReason {
public enum Success implements SuccessReason { WORLD_NON_EXISTENT(MVCorei18n.REMOVEWORLD_WORLDNONEXISTENT),
REMOVED(MVCorei18n.REMOVEWORLD_REMOVED); UNLOAD_FAILED(null);
private final MessageKeyProvider message; private final MessageKeyProvider message;
Success(MessageKeyProvider message) { RemoveWorldResult(MessageKeyProvider message) {
this.message = message; this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
public enum Failure implements FailureReason { @Override
WORLD_NON_EXISTENT(MVCorei18n.REMOVEWORLD_WORLDNONEXISTENT), public MessageKey getMessageKey() {
UNLOAD_FAILED(null); return message.getMessageKey();
private final MessageKeyProvider message;
Failure(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
} }

View File

@ -4,42 +4,24 @@ import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider; import co.aikar.locales.MessageKeyProvider;
import com.onarandombox.MultiverseCore.utils.MVCorei18n; import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.utils.result.FailureReason; import com.onarandombox.MultiverseCore.utils.result.FailureReason;
import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
/** /**
* Result of a world unloading operation. * Result of a world unloading operation.
*/ */
public class UnloadWorldResult { public enum UnloadWorldResult implements FailureReason {
public enum Success implements SuccessReason { WORLD_ALREADY_UNLOADING(MVCorei18n.UNLOADWORLD_WORLDALREADYUNLOADING),
UNLOADED(MVCorei18n.UNLOADWORLD_UNLOADED); WORLD_NON_EXISTENT(MVCorei18n.UNLOADWORLD_WORLDNONEXISTENT),
WORLD_UNLOADED(MVCorei18n.UNLOADWORLD_WORLDUNLOADED),
BUKKIT_UNLOAD_FAILED(MVCorei18n.UNLOADWORLD_BUKKITUNLOADFAILED);
private final MessageKeyProvider message; private final MessageKeyProvider message;
Success(MessageKeyProvider message) { UnloadWorldResult(MessageKeyProvider message) {
this.message = message; this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
public enum Failure implements FailureReason { @Override
WORLD_ALREADY_UNLOADING(MVCorei18n.UNLOADWORLD_WORLDALREADYUNLOADING), public MessageKey getMessageKey() {
WORLD_NON_EXISTENT(MVCorei18n.UNLOADWORLD_WORLDNONEXISTENT), return message.getMessageKey();
WORLD_UNLOADED(MVCorei18n.UNLOADWORLD_WORLDUNLOADED),
BUKKIT_UNLOAD_FAILED(MVCorei18n.UNLOADWORLD_BUKKITUNLOADFAILED);
private final MessageKeyProvider message;
Failure(MessageKeyProvider message) {
this.message = message;
}
@Override
public MessageKey getMessageKey() {
return message.getMessageKey();
}
} }
} }

View File

@ -13,6 +13,7 @@ mv-core.clone.description=Clones a world.
mv-core.clone.world.description=The target world to clone. mv-core.clone.world.description=The target world to clone.
mv-core.clone.newWorld.description=The new cloned world name. mv-core.clone.newWorld.description=The new cloned world name.
mv-core.clone.cloning=Cloning world '{world}' to '{newworld}'... mv-core.clone.cloning=Cloning world '{world}' to '{newworld}'...
mv-core.clone.success=&aWorld cloned to '{world}'!
# /mv confirm # /mv confirm
mv-core.confirm.description=Confirms dangerous commands before executing them. mv-core.confirm.description=Confirms dangerous commands before executing them.
@ -39,6 +40,7 @@ mv-core.create.properties.adjustspawn=- Adjust Spawn: &f{adjustSpawn}
mv-core.create.properties.generator=- Generator: &f{generator} mv-core.create.properties.generator=- Generator: &f{generator}
mv-core.create.properties.structures=- Structures: &f{structures} mv-core.create.properties.structures=- Structures: &f{structures}
mv-core.create.loading=Creating world... mv-core.create.loading=Creating world...
mv-core.create.success=&aWorld '{world}' created!
# /mv debug # /mv debug
mv-core.debug.info.description=Show the current debug level. mv-core.debug.info.description=Show the current debug level.
@ -52,6 +54,7 @@ mv-core.debug.change.level.description=Debug level to set to.
mv-core.delete.description=Deletes a world on your server PERMANENTLY. mv-core.delete.description=Deletes a world on your server PERMANENTLY.
mv-core.delete.deleting=Deleting world '{world}'... mv-core.delete.deleting=Deleting world '{world}'...
mv-core.delete.prompt=Are you sure you want to delete world '{world}'? mv-core.delete.prompt=Are you sure you want to delete world '{world}'?
mv-core.delete.success=&aWorld '{world}' deleted!
# /mv dumps # /mv dumps
mv-core.dumps.description=Dumps version info to the console or paste services mv-core.dumps.description=Dumps version info to the console or paste services
@ -78,11 +81,13 @@ mv-core.import.name.description=Name of the world folder.
mv-core.import.env.description=The world's environment. See: /mv env mv-core.import.env.description=The world's environment. See: /mv env
mv-core.import.other.description=Other world settings. See: https://gg.gg/nn8c2 mv-core.import.other.description=Other world settings. See: https://gg.gg/nn8c2
mv-core.import.importing=Starting import of world '{world}'... mv-core.import.importing=Starting import of world '{world}'...
mv-core.import.success=&aWorld '{world}' imported!
# /mv load # /mv load
mv-core.load.description=Loads a world. World must be already in worlds.yml, else please use /mv import. mv-core.load.description=Loads a world. World must be already in worlds.yml, else please use /mv import.
mv-core.load.world.description=Name of world you want to load. mv-core.load.world.description=Name of world you want to load.
mv-core.load.loading=Loading world '{world}'... mv-core.load.loading=Loading world '{world}'...
mv-core.load.success=&aWorld '{world}' loaded!
# /mv regen # /mv regen
mv-core.regen.description=Regenerates a world on your server. The previous state will be lost PERMANENTLY. mv-core.regen.description=Regenerates a world on your server. The previous state will be lost PERMANENTLY.
@ -90,6 +95,7 @@ mv-core.regen.world.description=World that you want to regen.
mv-core.regen.other.description=Other world settings. See: http://gg.gg/nn8lk mv-core.regen.other.description=Other world settings. See: http://gg.gg/nn8lk
mv-core.regen.regenerating=Regenerating world '{world}'... mv-core.regen.regenerating=Regenerating world '{world}'...
mv-core.regen.prompt=Are you sure you want to regenerate world '{world}'? mv-core.regen.prompt=Are you sure you want to regenerate world '{world}'?
mv-core.regen.success=&aWorld '{world}' regenerated!
# /mv reload # /mv reload
mv-core.reload.description=Reloads config files for all Multiverse modules. mv-core.reload.description=Reloads config files for all Multiverse modules.
@ -99,6 +105,7 @@ mv-core.reload.success=&aReload complete!
# /mv remove # /mv remove
mv-core.remove.description=Unloads a world from Multiverse and removes it from worlds.yml. This does NOT delete the world folder. mv-core.remove.description=Unloads a world from Multiverse and removes it from worlds.yml. This does NOT delete the world folder.
mv-core.remove.world.description=World you want to remove from MV's knowledge. mv-core.remove.world.description=World you want to remove from MV's knowledge.
mv-core.remove.success=&aWorld '{world}' removed!
# /mv # /mv
mv-core.root.title=&a{name} version {version} mv-core.root.title=&a{name} version {version}
@ -114,6 +121,7 @@ mv-core.teleport.success=Teleporting {player} to {destination}...
mv-core.unload.description=Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file. mv-core.unload.description=Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file.
mv-core.unload.world.description=Name of the world you want to unload. mv-core.unload.world.description=Name of the world you want to unload.
mv-core.unload.unloading=Unloading world '{world}'... mv-core.unload.unloading=Unloading world '{world}'...
mv-core.unload.success=&aWorld '{world}' unloaded!
# /mv usage # /mv usage
mv-core.usage.description=Show Multiverse-Core command usage. mv-core.usage.description=Show Multiverse-Core command usage.
@ -130,46 +138,37 @@ mv-core.entrycheck.exceedplayerlimit=the world has reached its player limit.
mv-core.entrycheck.noworldaccess=you do not have permissions to access the world. mv-core.entrycheck.noworldaccess=you do not have permissions to access the world.
# world manager result # world manager result
mv-core.cloneworld.cloned=&aWorld cloned to '{world}'!
mv-core.cloneworld.invalidworldname=World '{world}' contains invalid characters! mv-core.cloneworld.invalidworldname=World '{world}' contains invalid characters!
mv-core.cloneworld.worldexistfolder=World '{world}' exists in server folders! You need to delete it first before cloning. mv-core.cloneworld.worldexistfolder=World '{world}' exists in server folders! You need to delete it first before cloning.
mv-core.cloneworld.worldexistunloaded=World '{world}' already exists and it's unloaded! You need to delete it first before cloning. mv-core.cloneworld.worldexistunloaded=World '{world}' already exists and it's unloaded! You need to delete it first before cloning.
mv-core.cloneworld.worldexistloaded=World '{world}' already exists! You need to delete it first before cloning. mv-core.cloneworld.worldexistloaded=World '{world}' already exists! You need to delete it first before cloning.
mv-core.cloneworld.copyfailed=Failed to copy world to '{world}': {error}\n&fSee console for more details. mv-core.cloneworld.copyfailed=Failed to copy world to '{world}': {error}\n&fSee console for more details.
mv-core.createworld.created=&aWorld '{world}' created!
mv-core.createworld.invalidworldname=World '{world}' contains invalid characters! mv-core.createworld.invalidworldname=World '{world}' contains invalid characters!
mv-core.createworld.worldexistfolder=World '{world}' already exists in server folders!&f Type '&a/mv import {world} <environment>&f' if you wish to import it. mv-core.createworld.worldexistfolder=World '{world}' already exists in server folders!&f Type '&a/mv import {world} <environment>&f' if you wish to import it.
mv-core.createworld.worldexistunloaded=World '{world}' already exists, but it's not loaded!&f Type '&a/mv load {world}&f' if you wish to load it. mv-core.createworld.worldexistunloaded=World '{world}' already exists, but it's not loaded!&f Type '&a/mv load {world}&f' if you wish to load it.
mv-core.createworld.worldexistloaded=World '{world}' already exists! mv-core.createworld.worldexistloaded=World '{world}' already exists!
mv-core.createworld.bukkitcreationfailed=Bukkit failed to create world '{world}': {error}\n&fSee console for more details. mv-core.createworld.bukkitcreationfailed=Bukkit failed to create world '{world}': {error}\n&fSee console for more details.
mv-core.deleteworld.deleted=&aWorld '{world}' deleted!
mv-core.deleteworld.worldnonexistent=World '{world}' not found! mv-core.deleteworld.worldnonexistent=World '{world}' not found!
mv-core.deleteworld.loadfailed=Unable to load world '{world}', does the world folder exist?&f You can run '&a/mv remove {world}&f' to remove it from Multiverse, or attempt to load again with '&a/mv load {world}&f'. mv-core.deleteworld.loadfailed=Unable to load world '{world}', does the world folder exist?&f You can run '&a/mv remove {world}&f' to remove it from Multiverse, or attempt to load again with '&a/mv load {world}&f'.
mv-core.deleteworld.worldfoldernotfound=World '{world}' folder not found! mv-core.deleteworld.worldfoldernotfound=World '{world}' folder not found!
mv-core.deleteworld.failedtodeletefolder=Failed to delete world folder '{world}': {error}\n&fSee console for more details. mv-core.deleteworld.failedtodeletefolder=Failed to delete world folder '{world}': {error}\n&fSee console for more details.
mv-core.importworld.imported=&aWorld '{world}' imported!
mv-core.importworld.invalidworldname=World '{world}' contains invalid characters! mv-core.importworld.invalidworldname=World '{world}' contains invalid characters!
mv-core.importworld.worldexistunloaded=World '{world}' already exists, but it's not loaded!&f Type '&a/mv load {world}&f' if you wish to load it. mv-core.importworld.worldexistunloaded=World '{world}' already exists, but it's not loaded!&f Type '&a/mv load {world}&f' if you wish to load it.
mv-core.importworld.worldexistloaded=World '{world}' already exists! mv-core.importworld.worldexistloaded=World '{world}' already exists!
mv-core.importworld.worldfolderinvalid=World '{world}' folder contents does not seem to be a valid world! mv-core.importworld.worldfolderinvalid=World '{world}' folder contents does not seem to be a valid world!
mv-core.importworld.bukkitcreationfailed=Bukkit failed to import world '{world}': {error}\n&fSee console for more details. mv-core.importworld.bukkitcreationfailed=Bukkit failed to import world '{world}': {error}\n&fSee console for more details.
mv-core.loadworld.loaded=&aWorld '{world}' loaded!
mv-core.loadworld.worldalreadyloading=World '{world}' is already loading! Please wait... mv-core.loadworld.worldalreadyloading=World '{world}' is already loading! Please wait...
mv-core.loadworld.worldnonexistent=World '{world}' not found! Use '&a/mv create {world} <environment>&f' to create it. mv-core.loadworld.worldnonexistent=World '{world}' not found! Use '&a/mv create {world} <environment>&f' to create it.
mv-core.loadworld.worldexistfolder=World '{world}' exists in server folders, but it's not known to Multiverse!&f Type '&a/mv import {world} <environment>&f' if you wish to import it. mv-core.loadworld.worldexistfolder=World '{world}' exists in server folders, but it's not known to Multiverse!&f Type '&a/mv import {world} <environment>&f' if you wish to import it.
mv-core.loadworld.worldexistloaded=World '{world}' is already loaded! mv-core.loadworld.worldexistloaded=World '{world}' is already loaded!
mv-core.loadworld.bukkitcreationfailed=Bukkit failed to load world '{world}': {error}\n&fSee console for more details. mv-core.loadworld.bukkitcreationfailed=Bukkit failed to load world '{world}': {error}\n&fSee console for more details.
mv-core.regenworld.regenerated=&aWorld '{world}' regenerated!
mv-core.removeworld.removed=&aWorld '{world}' removed!
mv-core.removeworld.worldnonexistent=World '{world}' not found! mv-core.removeworld.worldnonexistent=World '{world}' not found!
mv-core.unloadworld.unloaded=&aWorld '{world}' unloaded!
mv-core.unloadworld.worldalreadyunloading=World '{world}' is already unloading! Please wait... mv-core.unloadworld.worldalreadyunloading=World '{world}' is already unloading! Please wait...
mv-core.unloadworld.worldnonexistent=World '{world}' does not exist! mv-core.unloadworld.worldnonexistent=World '{world}' does not exist!
mv-core.unloadworld.worldunloaded=World '{world}' is already unloaded! mv-core.unloadworld.worldunloaded=World '{world}' is already unloaded!

View File

@ -202,7 +202,7 @@ class LocalizationTest : TestWithMockBukkit() {
private val messageString = "Hello $replacementKey!" private val messageString = "Hello $replacementKey!"
private val replacedMessageString = messageString.replace(replacementKey, replacementValue) private val replacedMessageString = messageString.replace(replacementKey, replacementValue)
private val message = MVCorei18n.CLONEWORLD_CLONED private val message = MVCorei18n.CLONE_SUCCESS
.bundle(messageString, replace(replacementKey).with(replacementValue)) .bundle(messageString, replace(replacementKey).with(replacementValue))
@Test @Test