From 6ebcd40a5009764efb28e6a74c3e150eb9837806 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 7 Sep 2023 12:20:28 +0800 Subject: [PATCH] Implement remaining locales for clone and regen --- .../MultiverseCore/commands/CloneCommand.java | 7 ------- .../MultiverseCore/utils/MVCorei18n.java | 13 +++++++++---- .../MultiverseCore/worldnew/WorldManager.java | 9 +++++++-- .../worldnew/results/CloneWorldResult.java | 11 ++++++----- .../worldnew/results/RegenWorldResult.java | 2 +- src/main/resources/multiverse-core_en.properties | 11 +++++++---- .../core/commandtools/LocalizationTest.kt | 2 +- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java index 33ea9f15..db364d63 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java @@ -1,12 +1,10 @@ package com.onarandombox.MultiverseCore.commands; -import co.aikar.commands.CommandIssuer; import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.CommandCompletion; import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.Description; import co.aikar.commands.annotation.Optional; -import co.aikar.commands.annotation.Single; import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Syntax; import com.dumptruckman.minecraft.util.Logging; @@ -15,7 +13,6 @@ import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand; import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlag; import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagGroup; -import com.onarandombox.MultiverseCore.commandtools.flags.CommandValueFlag; import com.onarandombox.MultiverseCore.commandtools.flags.ParsedCommandFlags; import com.onarandombox.MultiverseCore.utils.MVCorei18n; import com.onarandombox.MultiverseCore.worldnew.MVWorld; @@ -25,9 +22,6 @@ import jakarta.inject.Inject; import org.jetbrains.annotations.NotNull; import org.jvnet.hk2.annotations.Service; -import java.util.Collections; -import java.util.Random; - @Service @CommandAlias("mv") public class CloneCommand extends MultiverseCommand { @@ -86,6 +80,5 @@ public class CloneCommand extends MultiverseCommand { Logging.fine("World remove failure: " + failure); issuer.sendError(failure.getReasonMessage()); }); - issuer.sendInfo(MVCorei18n.CLONE_SUCCESS, "{world}", newWorldName); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVCorei18n.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVCorei18n.java index 189f596e..279854a1 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVCorei18n.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVCorei18n.java @@ -16,8 +16,6 @@ public enum MVCorei18n implements MessageKeyProvider { // clone command CLONE_CLONING, - CLONE_FAILED, - CLONE_SUCCESS, // Coordinates command COORDINATES_INFO_TITLE, @@ -58,8 +56,6 @@ public enum MVCorei18n implements MessageKeyProvider { // regen command REGEN_REGENERATING, - REGEN_FAILED, - REGEN_SUCCESS, REGEN_PROMPT, // reload command @@ -92,6 +88,13 @@ public enum MVCorei18n implements MessageKeyProvider { ENTRYCHECK_NOWORLDACCESS, // world manager result + CLONEWORLD_CLONED, + CLONEWORLD_INVALIDWORLDNAME, + CLONEWORLD_WORLDEXISTFOLDER, + CLONEWORLD_WORLDEXISTOFFLINE, + CLONEWORLD_WORLDEXISTLOADED, + CLONEWORLD_COPYFAILED, + CREATEWORLD_CREATED, CREATEWORLD_INVALIDWORLDNAME, CREATEWORLD_WORLDEXISTFOLDER, @@ -119,6 +122,8 @@ public enum MVCorei18n implements MessageKeyProvider { LOADWORLD_WORLDEXISTLOADED, LOADWORLD_BUKKITCREATIONFAILED, + REGENWORLD_REGENERATED, + REMOVEWORLD_REMOVED, REMOVEWORLD_WORLDNONEXISTENT, diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java index 2d7a911c..6e38b3d8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/WorldManager.java @@ -506,7 +506,10 @@ public class WorldManager { File worldFolder = world.getBukkitWorld().map(World::getWorldFolder).getOrNull(); // TODO: Check null? File newWorldFolder = new File(Bukkit.getWorldContainer(), newWorldName); - FileUtils.copyFolder(worldFolder, newWorldFolder, CLONE_IGNORE_FILES); + if (!FileUtils.copyFolder(worldFolder, newWorldFolder, CLONE_IGNORE_FILES)) { + // TODO: Use Try + return Result.failure(CloneWorldResult.Failure.COPY_FAILED, replace("{world}").with(world.getName())); + } var importResult = importWorld(ImportWorldOptions.worldName(newWorldName) .environment(world.getEnvironment()) @@ -519,7 +522,9 @@ public class WorldManager { dataTransfer.pasteAllTo(newWorld); saveWorldsConfig(); }); - return Result.success(CloneWorldResult.Success.CLONED, replace("{world}").with(world.getName())); + return Result.success(CloneWorldResult.Success.CLONED, + replace("{world}").with(world.getName()), + replace("{newworld}").with(newWorldName)); } /** diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/results/CloneWorldResult.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/results/CloneWorldResult.java index 6e7fe97d..eed9528f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/results/CloneWorldResult.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/results/CloneWorldResult.java @@ -8,7 +8,7 @@ import com.onarandombox.MultiverseCore.utils.result.SuccessReason; public class CloneWorldResult { public enum Success implements SuccessReason { - CLONED(MVCorei18n.GENERIC_SUCCESS) + CLONED(MVCorei18n.CLONEWORLD_CLONED) ; private final MessageKeyProvider message; @@ -24,10 +24,11 @@ public class CloneWorldResult { } public enum Failure implements FailureReason { - INVALID_WORLDNAME(MVCorei18n.CREATEWORLD_INVALIDWORLDNAME), - WORLD_EXIST_FOLDER(MVCorei18n.CREATEWORLD_WORLDEXISTFOLDER), - WORLD_EXIST_OFFLINE(MVCorei18n.CREATEWORLD_WORLDEXISTOFFLINE), - WORLD_EXIST_LOADED(MVCorei18n.CREATEWORLD_WORLDEXISTLOADED), + INVALID_WORLDNAME(MVCorei18n.CLONEWORLD_INVALIDWORLDNAME), + WORLD_EXIST_FOLDER(MVCorei18n.CLONEWORLD_WORLDEXISTFOLDER), + WORLD_EXIST_OFFLINE(MVCorei18n.CLONEWORLD_WORLDEXISTOFFLINE), + WORLD_EXIST_LOADED(MVCorei18n.CLONEWORLD_WORLDEXISTLOADED), + COPY_FAILED(MVCorei18n.CLONEWORLD_COPYFAILED), IMPORT_FAILED(null), ; diff --git a/src/main/java/com/onarandombox/MultiverseCore/worldnew/results/RegenWorldResult.java b/src/main/java/com/onarandombox/MultiverseCore/worldnew/results/RegenWorldResult.java index f332f18f..ed9ebb5b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/worldnew/results/RegenWorldResult.java +++ b/src/main/java/com/onarandombox/MultiverseCore/worldnew/results/RegenWorldResult.java @@ -8,7 +8,7 @@ import com.onarandombox.MultiverseCore.utils.result.SuccessReason; public class RegenWorldResult { public enum Success implements SuccessReason { - REGENERATED(MVCorei18n.GENERIC_SUCCESS) + REGENERATED(MVCorei18n.REGENWORLD_REGENERATED) ; private final MessageKeyProvider message; diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties index 5c866fd6..d7754f8e 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -13,8 +13,6 @@ mv-core.clone.description=Clones a world. mv-core.clone.world.description=The target world to clone. mv-core.clone.newWorld.description=The new cloned world name. mv-core.clone.cloning=Cloning world '{world}' to '{newworld}'... -mv-core.clone.failed=World could not be cloned! &fSee console for more details. -mv-core.clone.success=Cloned world '{world}'! # /mv confirm mv-core.confirm.description=Confirms dangerous commands before executing them. @@ -85,8 +83,6 @@ mv-core.regen.description=Regenerates a world on your server. The previous state 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.regenerating=Regenerating world '{world}'... -mv-core.regen.failed=There was an issue regenerating '{world}'! &fPlease check console for errors. -mv-core.regen.success=&aWorld {world} was regenerated! mv-core.regen.prompt=Are you sure you want to regenerate world '{world}'? # /mv reload @@ -128,6 +124,13 @@ mv-core.entrycheck.exceedplayerlimit=the world has reached its player limit. mv-core.entrycheck.noworldaccess=you do not have permissions to access the world. # world manager result +mv-core.cloneworld.cloned=&aWorld '{world}' cloned to '{newworld}'! +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.worldexistoffline=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.copyfailed=Failed to copy world '{world}' to '{newworld}': {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.worldexistfolder=World '{world}' already exists in server folders!&f Type '&a/mv import {world} &f' if you wish to import it. diff --git a/src/test/java/org/mvplugins/multiverse/core/commandtools/LocalizationTest.kt b/src/test/java/org/mvplugins/multiverse/core/commandtools/LocalizationTest.kt index bfd223eb..167d5017 100644 --- a/src/test/java/org/mvplugins/multiverse/core/commandtools/LocalizationTest.kt +++ b/src/test/java/org/mvplugins/multiverse/core/commandtools/LocalizationTest.kt @@ -202,7 +202,7 @@ class LocalizationTest : TestWithMockBukkit() { private val messageString = "Hello $replacementKey!" private val replacedMessageString = messageString.replace(replacementKey, replacementValue) - private val message = MVCorei18n.CLONE_SUCCESS + private val message = MVCorei18n.CLONEWORLD_CLONED .bundle(messageString, replace(replacementKey).with(replacementValue)) @Test