diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java new file mode 100644 index 00000000..93e288a3 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java @@ -0,0 +1,71 @@ +package org.mvplugins.multiverse.core.commands; + +import co.aikar.commands.BukkitCommandIssuer; +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.Flags; +import co.aikar.commands.annotation.Optional; +import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; +import jakarta.inject.Inject; +import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; +import org.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.core.api.BlockSafety; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; + +@Service +@CommandAlias("mv") +public class SetSpawnCommand extends MultiverseCommand { + + @Inject + SetSpawnCommand(@NotNull MVCommandManager commandManager) { + super(commandManager); + } + + @Subcommand("setspawn") + @CommandPermission("multiverse.core.setspawn") + @CommandCompletion("@nothing @mvworlds:scope=loaded ") // TODO: Use Brigadier to show above in chat like the vanilla TP command + @Syntax("[location] [world]") + @Description("{@@mv-core.setspawn.description}") + void onSetSpawnCommand( + BukkitCommandIssuer issuer, + + @Optional + @Flags("resolve=issuerAware") + @Syntax("") + @Description("{@@mv-core.setspawn.location.description}") + Location location, + + @Optional + @Flags("resolve=issuerAware") + @Syntax("") + @Description("{@@mv-core.setspawn.world.description}") + LoadedMultiverseWorld world + ) { + + // TODO: Use a flag to do this, no clue how to edit an inbuilt ACF flag though + // Get the Location + if (location == null) { + if (issuer.isPlayer()) { + location = issuer.getPlayer().getLocation(); + } else { + issuer.sendMessage("The console must specify a location"); + return; + } + } + + issuer.sendMessage("Setting spawn in " + world.getName() + " to " + prettyLocation(location)); + + world.setSpawnLocation(location); + } + + private String prettyLocation(Location location) { + return location.getX() + ", " + location.getY() + ", " + location.getZ(); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java new file mode 100644 index 00000000..ceafc938 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java @@ -0,0 +1,82 @@ +package org.mvplugins.multiverse.core.commands; + +import co.aikar.commands.BukkitCommandIssuer; +import co.aikar.commands.MessageType; +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.Flags; +import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; +import com.dumptruckman.minecraft.util.Logging; +import jakarta.inject.Inject; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jvnet.hk2.annotations.Service; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; +import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter; +import org.mvplugins.multiverse.core.utils.MVCorei18n; +import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; + +@Service +@CommandAlias("mv") +class SpawnCommand extends MultiverseCommand { + private final WorldManager worldManager; + private final AsyncSafetyTeleporter safetyTeleporter; + + @Inject + SpawnCommand(@NotNull MVCommandManager commandManager, + @NotNull WorldManager worldManager, + @NotNull AsyncSafetyTeleporter safetyTeleporter) { + super(commandManager); + this.worldManager = worldManager; + this.safetyTeleporter = safetyTeleporter; + } + + @Subcommand("spawn") + @CommandPermission("multiverse.core.spawn") + @CommandCompletion("@players") + @Syntax("[player]") + @Description("{@@mv-core.spawn.description}") + void onSpawnTpCommand( + BukkitCommandIssuer issuer, + + @Flags("resolve=issuerAware") + @Syntax("[player]") + @Description("{@@mv-core.spawn.player.description}") + Player player + ) { + // The player is in the world, so it must be loaded + LoadedMultiverseWorld world = worldManager.getLoadedWorld(player.getWorld().getName()).getOrNull(); + if (world == null) { + issuer.sendMessage("The world the player you are trying to teleport is in, is not a multiverse world"); + } + + // TODO: Log when the player cannot be teleported there. No clue how to detect that + // Teleport the player + safetyTeleporter.teleportSafely(issuer.getIssuer(), player, world.getSpawnLocation()); + + player.sendMessage(commandManager.formatMessage( + issuer, + MessageType.INFO, + MVCorei18n.SPAWN_MESSAGE, + "{teleporter}", + getTeleporterName(issuer, player) + )); + + Logging.fine("Teleported " + player.getName() + " to " + world.getSpawnLocation().getX() + ", " + world.getSpawnLocation().getY() + ", " + world.getSpawnLocation().getZ()); + } + + private String getTeleporterName(BukkitCommandIssuer issuer, Player teleportTo) { + if (issuer.getIssuer().getName().equals("CONSOLE")) { + return commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_CONSOLENAME); + } + if (issuer.getIssuer().getName().equals(teleportTo.getName())) { + return commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_YOU); + } + return issuer.getIssuer().getName(); + } +} 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 c257157a..cdb94c2d 100644 --- a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java +++ b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java @@ -94,6 +94,13 @@ public enum MVCorei18n implements MessageKeyProvider { ROOT_TITLE, ROOT_HELP, + // spawn tp command + SPAWN_DESCRIPTION, + SPAWN_PLAYER_DESCRIPTION, + SPAWN_MESSAGE, + SPAWN_CONSOLENAME, + SPAWN_YOU, + // teleport command TELEPORT_SUCCESS, diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties index 26a9ab61..4225b7d5 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -124,6 +124,13 @@ mv-core.remove.success=&aWorld '{world}' removed! mv-core.root.title=&a{name} version {version} mv-core.root.help=&aSee &f/mv help&a for commands available. +# /mv spawn +mv-core.spawn.description=Teleports the specified player to the spawn of the world they are in +mv-core.spawn.player.description=The player +mv-core.spawn.message={teleporter} just sent you to spawn! +mv-core.spawn.consolename=The console +mv-core.spawn.you=You + # /mv tp mv-core.teleport.description=Allows you to teleport to a location on your server! mv-core.teleport.player.description=Target player to teleport.