From 22e18545edfa3d6d1b065f57eece1efae8676cab Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 31 Dec 2024 12:04:16 +0800 Subject: [PATCH] Actually implement check command --- .../core/commands/CheckCommand.java | 34 ++++++++++++++----- .../multiverse/core/utils/MVCorei18n.java | 9 +++-- .../resources/multiverse-core_en.properties | 8 +++-- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/CheckCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/CheckCommand.java index 9e75633b5..285c7cef2 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/CheckCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/CheckCommand.java @@ -7,26 +7,35 @@ import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Syntax; import jakarta.inject.Inject; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.core.api.LocationManipulation; import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; import org.mvplugins.multiverse.core.commandtools.MVCommandManager; import org.mvplugins.multiverse.core.destination.DestinationInstance; -import org.mvplugins.multiverse.core.destination.DestinationsProvider; +import org.mvplugins.multiverse.core.permissions.CorePermissionsChecker; import org.mvplugins.multiverse.core.utils.MVCorei18n; +import org.mvplugins.multiverse.core.utils.message.Message; + +import static org.mvplugins.multiverse.core.utils.message.MessageReplacement.replace; @Service @CommandAlias("mv") class CheckCommand extends CoreCommand { - private final DestinationsProvider destinationsProvider; + private final CorePermissionsChecker corePermissionsChecker; + private final LocationManipulation locationManipulation; @Inject - CheckCommand(@NotNull MVCommandManager commandManager, @NotNull DestinationsProvider destinationsProvider) { + CheckCommand(@NotNull MVCommandManager commandManager, + @NotNull CorePermissionsChecker corePermissionsChecker, + @NotNull LocationManipulation locationManipulation) { super(commandManager); - this.destinationsProvider = destinationsProvider; + this.corePermissionsChecker = corePermissionsChecker; + this.locationManipulation = locationManipulation; } @CommandAlias("mvcheck") @@ -45,10 +54,17 @@ void onCheckCommand( @Syntax("") @Description("{@@mv-core.check.destination.description}") DestinationInstance destination) { - issuer.sendInfo(MVCorei18n.CHECK_CHECKING, - "{player}", player.getName(), - "{destination}", destination.toString()); - // TODO: More detailed output on permissions required. - // this.destinationsProvider.checkTeleportPermissions(issuer, player, destination); + issuer.sendInfo(this.corePermissionsChecker.checkTeleportPermissions(player, player, destination) + ? MVCorei18n.CHECK_HASPERMISSION + : MVCorei18n.CHECK_NOPERMISSION, + replace("{player}").with(player.getName()), + replace("{destination}").with(destination)); + issuer.sendInfo(MVCorei18n.CHECK_LOCATION, + replace("{location}").with(destination.getLocation(player) + .map(locationManipulation::locationToString) + .map(Message::of) + .getOrElse(() -> Message.of(MVCorei18n.GENERIC_NULL, "Null!")))); + + // TODO: Show permission required for this particular destination } } diff --git a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java index 2707a2ce3..aa75792ac 100644 --- a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java +++ b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java @@ -15,7 +15,9 @@ public enum MVCorei18n implements MessageKeyProvider { CONFIG_NODE_NOTFOUND, // check command - CHECK_CHECKING, + CHECK_HASPERMISSION, + CHECK_NOPERMISSION, + CHECK_LOCATION, // clone command CLONE_CLONING, @@ -175,7 +177,10 @@ public enum MVCorei18n implements MessageKeyProvider { // generic GENERIC_SUCCESS, - GENERIC_FAILURE; + GENERIC_FAILURE, + GENERIC_ERROR, + GENERIC_NULL, + ; // END CHECKSTYLE-SUPPRESSION: Javadoc diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties index 2f7ea5579..75ccdc04f 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -3,10 +3,12 @@ mv-core.config.save.failed=Unable to save Multiverse-Core config.yml. Your chang mv-core.config.node.notfound=Node not found in config: {node} # /mv check -mv-core.check.description=Checks if a player can teleport to a destination. +mv-core.check.description=Checks if a player can teleport themselves to a destination. mv-core.check.player.description=Player to check destination on. mv-core.check.destination.description=A destination location, e.g. a world name. -mv-core.check.checking=Checking {player} to {destination} .. +mv-core.check.haspermission=&a{player} can teleport to {destination} +mv-core.check.nopermission=&c{player} cannot teleport to {destination} +mv-core.check.location=The destination's location is: &f{location} # /mv clone mv-core.clone.description=Clones a world. @@ -216,3 +218,5 @@ mv-core.unloadworld.bukkitunloadfailed=Bukkit failed to unload world '{world}': # generic mv-core.generic.success=Success! mv-core.generic.failure=Failed! +mv-core.generic.error=Error! +mv-core.generic.null=Null!