From 90522a014e3a74a0817c4f414d9dc3de9740b490 Mon Sep 17 00:00:00 2001 From: zax71 Date: Wed, 30 Aug 2023 16:41:15 +0100 Subject: [PATCH] Add /mv coordinates --- .../commands/CoordinatesCommand.java | 61 +++++++++++++++++++ .../MultiverseCore/utils/MVCorei18n.java | 10 +++ .../resources/multiverse-core_en.properties | 11 ++++ 3 files changed, 82 insertions(+) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commands/CoordinatesCommand.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CoordinatesCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CoordinatesCommand.java new file mode 100644 index 00000000..fb3e1870 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CoordinatesCommand.java @@ -0,0 +1,61 @@ +package com.onarandombox.MultiverseCore.commands; + +import co.aikar.commands.BukkitCommandIssuer; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.Subcommand; +import com.onarandombox.MultiverseCore.api.LocationManipulation; +import com.onarandombox.MultiverseCore.api.MVWorld; +import com.onarandombox.MultiverseCore.api.MVWorldManager; +import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; +import com.onarandombox.MultiverseCore.commandtools.MultiverseCommand; +import com.onarandombox.MultiverseCore.utils.MVCorei18n; +import jakarta.inject.Inject; +import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jvnet.hk2.annotations.Service; + +@Service +@CommandAlias("mv") +public class CoordinatesCommand extends MultiverseCommand { + + private final MVWorldManager worldManager; + private final LocationManipulation locationManipulation; + + @Inject + public CoordinatesCommand(@NotNull MVCommandManager commandManager, @NotNull MVWorldManager worldManager, @NotNull LocationManipulation locationManipulation) { + super(commandManager); + + this.worldManager = worldManager; + this.locationManipulation = locationManipulation; + } + + @Subcommand("coordinates|coord|coords|co") + @CommandPermission("multiverse.core.coord") + @Description("{@@mv-core.coordinates.description}") + public void onCoordinatesCommand(BukkitCommandIssuer issuer) { + if (!issuer.isPlayer()) { // Players only + issuer.sendInfo(MVCorei18n.COORDINATES_ERRORPLAYERSONLY); + return; + } + + Player player = issuer.getPlayer(); + + if (!this.worldManager.isMVWorld(player.getWorld().getName())) { // MV Worlds only + issuer.sendInfo(MVCorei18n.COORDINATES_ERROR_MULTIVERSEWORLDONLY); + return; + } + World world = player.getWorld(); + MVWorld mvworld = this.worldManager.getMVWorld(world.getName()); + + issuer.sendInfo(MVCorei18n.COORDINATES_INFO_TITLE); + issuer.sendInfo(MVCorei18n.COORDINATES_INFO_WORLD, "{world}", world.getName()); + issuer.sendInfo(MVCorei18n.COORDINATES_INFO_ALIAS, "{alias}", mvworld.getColoredWorldString()); + issuer.sendInfo(MVCorei18n.COORDINATES_INFO_WORLDSCALE, "{scale}", String.valueOf(mvworld.getScaling())); + issuer.sendInfo(MVCorei18n.COORDINATES_INFO_COORDINATES, "{coordinates}", locationManipulation.strCoords(player.getLocation())); + issuer.sendInfo(MVCorei18n.COORDINATES_INFO_DIRECTION, "{direction}", locationManipulation.getDirection(player.getLocation())); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/MVCorei18n.java b/src/main/java/com/onarandombox/MultiverseCore/utils/MVCorei18n.java index 0c2b3351..ed731059 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/MVCorei18n.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/MVCorei18n.java @@ -19,6 +19,16 @@ public enum MVCorei18n implements MessageKeyProvider { CLONE_FAILED, CLONE_SUCCESS, + // Coordinates command + COORDINATES_ERRORPLAYERSONLY, + COORDINATES_ERROR_MULTIVERSEWORLDONLY, + COORDINATES_INFO_TITLE, + COORDINATES_INFO_WORLD, + COORDINATES_INFO_ALIAS, + COORDINATES_INFO_WORLDSCALE, + COORDINATES_INFO_COORDINATES, + COORDINATES_INFO_DIRECTION, + // create command CREATE_PROPERTIES, CREATE_PROPERTIES_ENVIRONMENT, diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties index b97ca106..be773d3d 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -19,6 +19,17 @@ mv-core.clone.success=Cloned world '{world}'! # /mv confirm mv-core.confirm.description=Confirms dangerous commands before executing them. +# /mv coordinates +mv-core.coordinates.description=Simply sends your coordinates +mv-core.coordinates.error.players-only=&cThis command can only be used by players +mv-core.coordinates.error.multiverseWorldOnly=&cThis can only be used in multiverse worlds +mv-core.coordinates.info.title=&b--- Location Information --- +mv-core.coordinates.info.world=&bWorld: &f{world} +mv-core.coordinates.info.alias=&bAlias: &f{alias} +mv-core.coordinates.info.worldScale=&bWorld Scale: &f{scale} +mv-core.coordinates.info.coordinates=&bCoordinates: &f{coordinates} +mv-core.coordinates.info.direction=&bDirection: &f{direction} + # /mv create mv-core.create.description=Creates a new world and loads it. mv-core.create.name.description=New world name.