Implement remaining locales for clone and regen

This commit is contained in:
Ben Woo 2023-09-07 12:20:28 +08:00
parent 6427881c98
commit 6ebcd40a50
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
7 changed files with 31 additions and 24 deletions

View File

@ -1,12 +1,10 @@
package com.onarandombox.MultiverseCore.commands; package com.onarandombox.MultiverseCore.commands;
import co.aikar.commands.CommandIssuer;
import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandCompletion; import co.aikar.commands.annotation.CommandCompletion;
import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Description; import co.aikar.commands.annotation.Description;
import co.aikar.commands.annotation.Optional; import co.aikar.commands.annotation.Optional;
import co.aikar.commands.annotation.Single;
import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax; import co.aikar.commands.annotation.Syntax;
import com.dumptruckman.minecraft.util.Logging; 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.MultiverseCommand;
import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlag; import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlag;
import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagGroup; 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.commandtools.flags.ParsedCommandFlags;
import com.onarandombox.MultiverseCore.utils.MVCorei18n; import com.onarandombox.MultiverseCore.utils.MVCorei18n;
import com.onarandombox.MultiverseCore.worldnew.MVWorld; import com.onarandombox.MultiverseCore.worldnew.MVWorld;
@ -25,9 +22,6 @@ import jakarta.inject.Inject;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.annotations.Service;
import java.util.Collections;
import java.util.Random;
@Service @Service
@CommandAlias("mv") @CommandAlias("mv")
public class CloneCommand extends MultiverseCommand { public class CloneCommand extends MultiverseCommand {
@ -86,6 +80,5 @@ public class CloneCommand extends MultiverseCommand {
Logging.fine("World remove failure: " + failure); Logging.fine("World remove failure: " + failure);
issuer.sendError(failure.getReasonMessage()); issuer.sendError(failure.getReasonMessage());
}); });
issuer.sendInfo(MVCorei18n.CLONE_SUCCESS, "{world}", newWorldName);
} }
} }

View File

@ -16,8 +16,6 @@ public enum MVCorei18n implements MessageKeyProvider {
// clone command // clone command
CLONE_CLONING, CLONE_CLONING,
CLONE_FAILED,
CLONE_SUCCESS,
// Coordinates command // Coordinates command
COORDINATES_INFO_TITLE, COORDINATES_INFO_TITLE,
@ -58,8 +56,6 @@ public enum MVCorei18n implements MessageKeyProvider {
// regen command // regen command
REGEN_REGENERATING, REGEN_REGENERATING,
REGEN_FAILED,
REGEN_SUCCESS,
REGEN_PROMPT, REGEN_PROMPT,
// reload command // reload command
@ -92,6 +88,13 @@ public enum MVCorei18n implements MessageKeyProvider {
ENTRYCHECK_NOWORLDACCESS, ENTRYCHECK_NOWORLDACCESS,
// world manager result // world manager result
CLONEWORLD_CLONED,
CLONEWORLD_INVALIDWORLDNAME,
CLONEWORLD_WORLDEXISTFOLDER,
CLONEWORLD_WORLDEXISTOFFLINE,
CLONEWORLD_WORLDEXISTLOADED,
CLONEWORLD_COPYFAILED,
CREATEWORLD_CREATED, CREATEWORLD_CREATED,
CREATEWORLD_INVALIDWORLDNAME, CREATEWORLD_INVALIDWORLDNAME,
CREATEWORLD_WORLDEXISTFOLDER, CREATEWORLD_WORLDEXISTFOLDER,
@ -119,6 +122,8 @@ public enum MVCorei18n implements MessageKeyProvider {
LOADWORLD_WORLDEXISTLOADED, LOADWORLD_WORLDEXISTLOADED,
LOADWORLD_BUKKITCREATIONFAILED, LOADWORLD_BUKKITCREATIONFAILED,
REGENWORLD_REGENERATED,
REMOVEWORLD_REMOVED, REMOVEWORLD_REMOVED,
REMOVEWORLD_WORLDNONEXISTENT, REMOVEWORLD_WORLDNONEXISTENT,

View File

@ -506,7 +506,10 @@ public class WorldManager {
File worldFolder = world.getBukkitWorld().map(World::getWorldFolder).getOrNull(); // TODO: Check null? File worldFolder = world.getBukkitWorld().map(World::getWorldFolder).getOrNull(); // TODO: Check null?
File newWorldFolder = new File(Bukkit.getWorldContainer(), newWorldName); 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<Void>
return Result.failure(CloneWorldResult.Failure.COPY_FAILED, replace("{world}").with(world.getName()));
}
var importResult = importWorld(ImportWorldOptions.worldName(newWorldName) var importResult = importWorld(ImportWorldOptions.worldName(newWorldName)
.environment(world.getEnvironment()) .environment(world.getEnvironment())
@ -519,7 +522,9 @@ public class WorldManager {
dataTransfer.pasteAllTo(newWorld); dataTransfer.pasteAllTo(newWorld);
saveWorldsConfig(); 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));
} }
/** /**

View File

@ -8,7 +8,7 @@ import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
public class CloneWorldResult { public class CloneWorldResult {
public enum Success implements SuccessReason { public enum Success implements SuccessReason {
CLONED(MVCorei18n.GENERIC_SUCCESS) CLONED(MVCorei18n.CLONEWORLD_CLONED)
; ;
private final MessageKeyProvider message; private final MessageKeyProvider message;
@ -24,10 +24,11 @@ public class CloneWorldResult {
} }
public enum Failure implements FailureReason { public enum Failure implements FailureReason {
INVALID_WORLDNAME(MVCorei18n.CREATEWORLD_INVALIDWORLDNAME), INVALID_WORLDNAME(MVCorei18n.CLONEWORLD_INVALIDWORLDNAME),
WORLD_EXIST_FOLDER(MVCorei18n.CREATEWORLD_WORLDEXISTFOLDER), WORLD_EXIST_FOLDER(MVCorei18n.CLONEWORLD_WORLDEXISTFOLDER),
WORLD_EXIST_OFFLINE(MVCorei18n.CREATEWORLD_WORLDEXISTOFFLINE), WORLD_EXIST_OFFLINE(MVCorei18n.CLONEWORLD_WORLDEXISTOFFLINE),
WORLD_EXIST_LOADED(MVCorei18n.CREATEWORLD_WORLDEXISTLOADED), WORLD_EXIST_LOADED(MVCorei18n.CLONEWORLD_WORLDEXISTLOADED),
COPY_FAILED(MVCorei18n.CLONEWORLD_COPYFAILED),
IMPORT_FAILED(null), IMPORT_FAILED(null),
; ;

View File

@ -8,7 +8,7 @@ import com.onarandombox.MultiverseCore.utils.result.SuccessReason;
public class RegenWorldResult { public class RegenWorldResult {
public enum Success implements SuccessReason { public enum Success implements SuccessReason {
REGENERATED(MVCorei18n.GENERIC_SUCCESS) REGENERATED(MVCorei18n.REGENWORLD_REGENERATED)
; ;
private final MessageKeyProvider message; private final MessageKeyProvider message;

View File

@ -13,8 +13,6 @@ 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.failed=World could not be cloned! &fSee console for more details.
mv-core.clone.success=Cloned world '{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.
@ -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.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.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-core.regen.prompt=Are you sure you want to regenerate world '{world}'?
# /mv reload # /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. mv-core.entrycheck.noworldaccess=you do not have permissions to access the world.
# world manager result # 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.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.

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.CLONE_SUCCESS private val message = MVCorei18n.CLONEWORLD_CLONED
.bundle(messageString, replace(replacementKey).with(replacementValue)) .bundle(messageString, replace(replacementKey).with(replacementValue))
@Test @Test