Merge pull request #2986 from zax71/MV5-coord-command

Add `/mv coordinates` command
This commit is contained in:
Ben Woo 2023-09-01 23:42:04 +08:00 committed by GitHub
commit 4300d83c90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 1 deletions

View File

@ -0,0 +1,52 @@
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.Flags;
import co.aikar.commands.annotation.Subcommand;
import com.onarandombox.MultiverseCore.api.LocationManipulation;
import com.onarandombox.MultiverseCore.api.MVWorld;
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.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service;
@Service
@CommandAlias("mv")
public class CoordinatesCommand extends MultiverseCommand {
private final LocationManipulation locationManipulation;
@Inject
public CoordinatesCommand(
@NotNull MVCommandManager commandManager,
@NotNull LocationManipulation locationManipulation
) {
super(commandManager);
this.locationManipulation = locationManipulation;
}
@Subcommand("coordinates|coords|coord|co")
@CommandPermission("multiverse.core.coord")
@Description("{@@mv-core.coordinates.description}")
public void onCoordinatesCommand(BukkitCommandIssuer issuer,
@Flags("resolve=issuerOnly")
Player player,
@Flags("resolve=issuerOnly")
MVWorld world
) {
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_TITLE);
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_WORLD, "{world}", world.getName());
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_ALIAS, "{alias}", world.getColoredWorldString());
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_WORLDSCALE, "{scale}", String.valueOf(world.getScaling()));
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_COORDINATES, "{coordinates}", locationManipulation.strCoords(player.getLocation()));
issuer.sendInfo(MVCorei18n.COORDINATES_INFO_DIRECTION, "{direction}", locationManipulation.getDirection(player.getLocation()));
}
}

View File

@ -19,6 +19,14 @@ public enum MVCorei18n implements MessageKeyProvider {
CLONE_FAILED,
CLONE_SUCCESS,
// Coordinates command
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,
@ -82,6 +90,10 @@ public enum MVCorei18n implements MessageKeyProvider {
DEBUG_INFO_OFF,
DEBUG_INFO_ON,
// commands error
COMMANDS_ERROR_PLAYERSONLY,
COMMANDS_ERROR_MULTIVERSEWORLDONLY,
// entry check
ENTRYCHECK_BLACKLISTED,
ENTRYCHECK_NOTENOUGHMONEY,

View File

@ -19,6 +19,15 @@ 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.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.
@ -115,6 +124,10 @@ mv-core.unload.success=&aUnloaded world '{world}'!
# /mv usage
mv-core.usage.description=Show Multiverse-Core command usage.
# commands error
mv-core.commands.error.playersonly=&cThis command can only be used by players
mv-core.commands.error.multiverseworldonly=&cThis can only be used in multiverse worlds
# entry check
mv-core.entrycheck.blacklisted='{world}' is blacklisted.
mv-core.entrycheck.notenoughmoney=you do not have enough money to pay entry fee. You are required to pay {amount}.

View File

@ -127,7 +127,7 @@ class InjectionTest : TestWithMockBukkit() {
fun `Commands are available as services`() {
val commands = multiverseCore.getAllServices(MultiverseCommand::class.java)
// TODO come up with a better way to test this like via actually testing the effect of calling each command
assertEquals(18, commands.size)
assertEquals(19, commands.size)
}
@Test