From b1a5907d0c1b059eef5fbc1a6c9ad5bd3b802d6e Mon Sep 17 00:00:00 2001 From: Zax71 Date: Sat, 24 Feb 2024 17:38:40 +0000 Subject: [PATCH 1/8] `/mv spawn` basic features --- .../core/commands/SpawnCommand.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java 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..ce8e5309 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java @@ -0,0 +1,66 @@ +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.Subcommand; +import co.aikar.commands.annotation.Syntax; +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.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; + +@Service +@CommandAlias("mv") +class SpawnCommand extends MultiverseCommand { + + private final WorldManager worldManager; + + @Inject + SpawnCommand(@NotNull MVCommandManager commandManager, WorldManager worldManager) { + super(commandManager); + this.worldManager = worldManager; + } + + @Subcommand("spawn") + @CommandPermission("multiverse.core.spawn") + @CommandCompletion("@players") + @Syntax("[player]") + @Description("{@@mv-core.spawn.description}") + void onSpawnCommand( + 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(); + + player.teleport(world.getSpawnLocation()); // TODO: use safety teleporter + + // Make the message make sense + String teleporterName; + if (issuer.getIssuer().getName().equals("CONSOLE")) { + teleporterName = "The console"; + } else if (issuer.getIssuer().getName().equals(player.getName())) { + teleporterName = "You"; + } else { + teleporterName = issuer.getIssuer().getName(); + } + + player.sendMessage(teleporterName + " just sent you to spawn!"); // TODO: i18n + + + } + + +} From 39c533e8085572b81e5d705fc88fc2189fe922c2 Mon Sep 17 00:00:00 2001 From: Zax71 Date: Sat, 24 Feb 2024 17:56:54 +0000 Subject: [PATCH 2/8] Use safetyTeleporter and add i18n --- .../core/commands/SpawnCommand.java | 27 ++++++++++++++----- .../multiverse/core/utils/MVCorei18n.java | 7 +++++ .../resources/multiverse-core_en.properties | 7 +++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java index ce8e5309..b65bcab8 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java @@ -1,6 +1,7 @@ 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; @@ -14,6 +15,8 @@ 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; @@ -22,11 +25,15 @@ import org.mvplugins.multiverse.core.world.WorldManager; class SpawnCommand extends MultiverseCommand { private final WorldManager worldManager; + private final AsyncSafetyTeleporter safetyTeleporter; @Inject - SpawnCommand(@NotNull MVCommandManager commandManager, WorldManager worldManager) { + SpawnCommand(@NotNull MVCommandManager commandManager, + WorldManager worldManager, + @NotNull AsyncSafetyTeleporter safetyTeleporter) { super(commandManager); this.worldManager = worldManager; + this.safetyTeleporter = safetyTeleporter; } @Subcommand("spawn") @@ -45,19 +52,27 @@ class SpawnCommand extends MultiverseCommand { // The player is in the world, so it must be loaded LoadedMultiverseWorld world = worldManager.getLoadedWorld(player.getWorld().getName()).getOrNull(); - player.teleport(world.getSpawnLocation()); // TODO: use safety teleporter + // Teleport the player + safetyTeleporter.teleportSafely(issuer.getIssuer(), player, world.getSpawnLocation()); - // Make the message make sense + // Make the conformation message make sense String teleporterName; if (issuer.getIssuer().getName().equals("CONSOLE")) { - teleporterName = "The console"; + teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_CONSOLENAME); } else if (issuer.getIssuer().getName().equals(player.getName())) { - teleporterName = "You"; + teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_YOU); } else { teleporterName = issuer.getIssuer().getName(); } - player.sendMessage(teleporterName + " just sent you to spawn!"); // TODO: i18n + // Send the conformation message + player.sendMessage(commandManager.formatMessage( + issuer, + MessageType.INFO, + MVCorei18n.SPAWN_MESSAGE, + "{teleporter}", + teleporterName + )); } 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 42d5fab2..6bbdc692 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 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 bfb4bcd5..ea3b7b10 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. From 631ed2973a2fa330cbac5ce3bc4fb79f87499618 Mon Sep 17 00:00:00 2001 From: Zax71 Date: Sat, 24 Feb 2024 18:10:30 +0000 Subject: [PATCH 3/8] Rename to `/mv spawn tp` in preparation for `/mv spawn set` --- .../multiverse/core/commands/SpawnCommand.java | 18 +++++++----------- .../multiverse/core/utils/MVCorei18n.java | 12 ++++++------ .../resources/multiverse-core_en.properties | 12 ++++++------ 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java index b65bcab8..97467546 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java @@ -36,17 +36,17 @@ class SpawnCommand extends MultiverseCommand { this.safetyTeleporter = safetyTeleporter; } - @Subcommand("spawn") + @Subcommand("spawn tp") @CommandPermission("multiverse.core.spawn") @CommandCompletion("@players") @Syntax("[player]") - @Description("{@@mv-core.spawn.description}") - void onSpawnCommand( + @Description("{@@mv-core.spawn.tp.description}") + void onSpawnTpCommand( BukkitCommandIssuer issuer, @Flags("resolve=issuerAware") @Syntax("[player]") - @Description("{@@mv-core.spawn.player.description}") + @Description("{@@mv-core.spawn.tp.player.description}") Player player ) { // The player is in the world, so it must be loaded @@ -58,9 +58,9 @@ class SpawnCommand extends MultiverseCommand { // Make the conformation message make sense String teleporterName; if (issuer.getIssuer().getName().equals("CONSOLE")) { - teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_CONSOLENAME); + teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_TP_CONSOLENAME); } else if (issuer.getIssuer().getName().equals(player.getName())) { - teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_YOU); + teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_TP_YOU); } else { teleporterName = issuer.getIssuer().getName(); } @@ -69,13 +69,9 @@ class SpawnCommand extends MultiverseCommand { player.sendMessage(commandManager.formatMessage( issuer, MessageType.INFO, - MVCorei18n.SPAWN_MESSAGE, + MVCorei18n.SPAWN_TP_MESSAGE, "{teleporter}", teleporterName )); - - } - - } 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 6bbdc692..e9f3c7bc 100644 --- a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java +++ b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java @@ -94,12 +94,12 @@ public enum MVCorei18n implements MessageKeyProvider { ROOT_TITLE, ROOT_HELP, - // spawn command - SPAWN_DESCRIPTION, - SPAWN_PLAYER_DESCRIPTION, - SPAWN_MESSAGE, - SPAWN_CONSOLENAME, - SPAWN_YOU, + // spawn tp command + SPAWN_TP_DESCRIPTION, + SPAWN_TP_PLAYER_DESCRIPTION, + SPAWN_TP_MESSAGE, + SPAWN_TP_CONSOLENAME, + SPAWN_TP_YOU, // teleport command TELEPORT_SUCCESS, diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties index ea3b7b10..3bb00c6b 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -124,12 +124,12 @@ 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 spawn tp +mv-core.spawn.tp.description=Teleports the specified player to the spawn of the world they are in +mv-core.spawn.tp.player.description=The player +mv-core.spawn.tp.message={teleporter} just sent you to spawn! +mv-core.spawn.tp.consolename=The console +mv-core.spawn.tp.you=You # /mv tp mv-core.teleport.description=Allows you to teleport to a location on your server! From 1a508a5d1454739c6a707ee18eb29c9fd3701104 Mon Sep 17 00:00:00 2001 From: Zax71 Date: Fri, 8 Mar 2024 17:58:45 +0000 Subject: [PATCH 4/8] Add logic for spawn and setspawn --- .../core/commands/SetSpawnCommand.java | 71 +++++++++++++++++++ .../core/commands/SpawnCommand.java | 38 +++++----- .../multiverse/core/utils/MVCorei18n.java | 10 +-- .../resources/multiverse-core_en.properties | 12 ++-- 4 files changed, 102 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java 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 index 97467546..22ba9fab 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java @@ -9,6 +9,7 @@ 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; @@ -23,55 +24,56 @@ 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, - WorldManager worldManager, + @NotNull WorldManager worldManager, @NotNull AsyncSafetyTeleporter safetyTeleporter) { super(commandManager); this.worldManager = worldManager; this.safetyTeleporter = safetyTeleporter; } - @Subcommand("spawn tp") + @Subcommand("spawn") @CommandPermission("multiverse.core.spawn") @CommandCompletion("@players") @Syntax("[player]") - @Description("{@@mv-core.spawn.tp.description}") + @Description("{@@mv-core.spawn.description}") void onSpawnTpCommand( BukkitCommandIssuer issuer, @Flags("resolve=issuerAware") @Syntax("[player]") - @Description("{@@mv-core.spawn.tp.player.description}") + @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(); + // 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()); - // Make the conformation message make sense - String teleporterName; - if (issuer.getIssuer().getName().equals("CONSOLE")) { - teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_TP_CONSOLENAME); - } else if (issuer.getIssuer().getName().equals(player.getName())) { - teleporterName = commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.SPAWN_TP_YOU); - } else { - teleporterName = issuer.getIssuer().getName(); - } - - // Send the conformation message player.sendMessage(commandManager.formatMessage( issuer, MessageType.INFO, - MVCorei18n.SPAWN_TP_MESSAGE, + MVCorei18n.SPAWN_MESSAGE, "{teleporter}", - teleporterName + 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 e9f3c7bc..146dd0b1 100644 --- a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java +++ b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java @@ -95,11 +95,11 @@ public enum MVCorei18n implements MessageKeyProvider { ROOT_HELP, // spawn tp command - SPAWN_TP_DESCRIPTION, - SPAWN_TP_PLAYER_DESCRIPTION, - SPAWN_TP_MESSAGE, - SPAWN_TP_CONSOLENAME, - SPAWN_TP_YOU, + 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 3bb00c6b..ea3b7b10 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -124,12 +124,12 @@ 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 tp -mv-core.spawn.tp.description=Teleports the specified player to the spawn of the world they are in -mv-core.spawn.tp.player.description=The player -mv-core.spawn.tp.message={teleporter} just sent you to spawn! -mv-core.spawn.tp.consolename=The console -mv-core.spawn.tp.you=You +# /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! From 6982d8e7ba3939753b5feee521e447e3bda1570d Mon Sep 17 00:00:00 2001 From: Zax71 Date: Fri, 8 Mar 2024 18:02:15 +0000 Subject: [PATCH 5/8] Add null check for world --- .../org/mvplugins/multiverse/core/commands/SpawnCommand.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java index 22ba9fab..ceafc938 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java @@ -51,6 +51,9 @@ class SpawnCommand extends MultiverseCommand { ) { // 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 From 330d4fbe396e070c6e71af0f01aecc272b46b124 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:06:27 +0800 Subject: [PATCH 6/8] Improve spawn command messaging --- .../core/commands/SetSpawnCommand.java | 7 ++-- .../core/commands/SpawnCommand.java | 36 ++++++++++++------- .../multiverse/core/utils/MVCorei18n.java | 3 +- .../resources/multiverse-core_en.properties | 5 +++ 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java index 93e288a3..41defdcf 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java @@ -13,11 +13,9 @@ 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") @@ -28,6 +26,7 @@ public class SetSpawnCommand extends MultiverseCommand { super(commandManager); } + @CommandAlias("mvsetspawn") @Subcommand("setspawn") @CommandPermission("multiverse.core.setspawn") @CommandCompletion("@nothing @mvworlds:scope=loaded ") // TODO: Use Brigadier to show above in chat like the vanilla TP command @@ -46,9 +45,7 @@ public class SetSpawnCommand extends MultiverseCommand { @Flags("resolve=issuerAware") @Syntax("") @Description("{@@mv-core.setspawn.world.description}") - LoadedMultiverseWorld world - ) { - + 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) { diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java index ceafc938..ac3448b7 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java @@ -14,6 +14,7 @@ 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.MVCommandIssuer; import org.mvplugins.multiverse.core.commandtools.MVCommandManager; import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter; @@ -36,36 +37,45 @@ class SpawnCommand extends MultiverseCommand { this.safetyTeleporter = safetyTeleporter; } + @CommandAlias("mvspawn") @Subcommand("spawn") @CommandPermission("multiverse.core.spawn") @CommandCompletion("@players") @Syntax("[player]") @Description("{@@mv-core.spawn.description}") void onSpawnTpCommand( - BukkitCommandIssuer issuer, + MVCommandIssuer issuer, @Flags("resolve=issuerAware") @Syntax("[player]") @Description("{@@mv-core.spawn.player.description}") - Player player - ) { + Player player) { + // TODO: Check for relevant self/others teleport permissions + // 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) - )); + // TODO: Different message for teleporting self vs others + safetyTeleporter.teleportSafely(issuer.getIssuer(), player, world.getSpawnLocation()) + .onSuccess(() -> player.sendMessage(commandManager.formatMessage( + issuer, + MessageType.INFO, + MVCorei18n.SPAWN_SUCCESS, + "{teleporter}", + getTeleporterName(issuer, player) + ))) + .onFailure(failure -> { + issuer.sendError( + MVCorei18n.SPAWN_FAILED, + "{teleporter}", + getTeleporterName(issuer, player) + ); + issuer.sendError(failure.getFailureMessage()); + }); Logging.fine("Teleported " + player.getName() + " to " + world.getSpawnLocation().getX() + ", " + world.getSpawnLocation().getY() + ", " + world.getSpawnLocation().getZ()); } 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 e24acf1e..2707a2ce 100644 --- a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java +++ b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java @@ -97,7 +97,8 @@ public enum MVCorei18n implements MessageKeyProvider { // spawn tp command SPAWN_DESCRIPTION, SPAWN_PLAYER_DESCRIPTION, - SPAWN_MESSAGE, + SPAWN_SUCCESS, + SPAWN_FAILED, SPAWN_CONSOLENAME, SPAWN_YOU, diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties index 06146827..9df2939d 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -131,6 +131,11 @@ mv-core.spawn.message={teleporter} just sent you to spawn! mv-core.spawn.consolename=The console mv-core.spawn.you=You +# /mv setspawn +mv-core.setspawn.description=Sets the spawn location of the specified world +mv-core.setspawn.location.description=Location of the new spawn +mv-core.setspawn.world.description=Target world to set spawn of (defaults to player's current world) + # /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. From 1ec4e4b8f0c96f52aaa8b0bb24f451fe84a47aa0 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:55:39 +0800 Subject: [PATCH 7/8] Improve setspawn command location param --- .../core/commands/SetSpawnCommand.java | 50 +++++++++---------- .../resources/multiverse-core_en.properties | 14 +++--- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java index 41defdcf..d150d5a5 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SetSpawnCommand.java @@ -2,64 +2,60 @@ 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 io.vavr.control.Option; import jakarta.inject.Inject; import org.bukkit.Location; 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.world.LoadedMultiverseWorld; +import org.mvplugins.multiverse.core.world.WorldManager; @Service @CommandAlias("mv") public class SetSpawnCommand extends MultiverseCommand { + private final WorldManager worldManager; + @Inject - SetSpawnCommand(@NotNull MVCommandManager commandManager) { + SetSpawnCommand( + @NotNull MVCommandManager commandManager, + @NotNull WorldManager worldManager) { super(commandManager); + this.worldManager = worldManager; } @CommandAlias("mvsetspawn") @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]") + @CommandPermission("multiverse.core.spawn.set") + // @CommandCompletion("@location") // TODO: Use Brigadier to show above in chat like the vanilla TP command + @Syntax("[location]") @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) { + Location location) { + Option.of(location).orElse(() -> { if (issuer.isPlayer()) { - location = issuer.getPlayer().getLocation(); - } else { - issuer.sendMessage("The console must specify a location"); - return; + return Option.of(issuer.getPlayer().getLocation()); } - } - - issuer.sendMessage("Setting spawn in " + world.getName() + " to " + prettyLocation(location)); - - world.setSpawnLocation(location); + return Option.none(); + }).peek(finalLocation -> + worldManager.getLoadedWorld(finalLocation.getWorld()) + .peek(mvWorld -> mvWorld.setSpawnLocation(finalLocation) + .onSuccess(ignore -> issuer.sendMessage( + "Successfully set spawn in " + mvWorld.getName() + " to " + prettyLocation(mvWorld.getSpawnLocation()))) + .onFailure(e -> issuer.sendMessage(e.getLocalizedMessage()))) + .onEmpty(() -> issuer.sendMessage("That world is not loaded or does not exist!")) + ).onEmpty(() -> issuer.sendMessage("You must specify a location in the format: worldname:x,y,z")); } private String prettyLocation(Location location) { diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties index 9df2939d..2f7ea557 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -124,18 +124,18 @@ 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 setspawn mv-core.setspawn.description=Sets the spawn location of the specified world mv-core.setspawn.location.description=Location of the new spawn mv-core.setspawn.world.description=Target world to set spawn of (defaults to player's current world) +# /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.success={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. From f00e2964f3605274e7becaf60cdb0d5395a65f49 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 30 Aug 2024 14:23:45 +0800 Subject: [PATCH 8/8] Proper spawn permission checking --- .../core/commands/SpawnCommand.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java index ac3448b7..97ff11e6 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/SpawnCommand.java @@ -1,14 +1,9 @@ package org.mvplugins.multiverse.core.commands; import co.aikar.commands.BukkitCommandIssuer; +import co.aikar.commands.CommandIssuer; 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 co.aikar.commands.annotation.*; import com.dumptruckman.minecraft.util.Logging; import jakarta.inject.Inject; import org.bukkit.entity.Player; @@ -39,7 +34,6 @@ class SpawnCommand extends MultiverseCommand { @CommandAlias("mvspawn") @Subcommand("spawn") - @CommandPermission("multiverse.core.spawn") @CommandCompletion("@players") @Syntax("[player]") @Description("{@@mv-core.spawn.description}") @@ -50,12 +44,17 @@ class SpawnCommand extends MultiverseCommand { @Syntax("[player]") @Description("{@@mv-core.spawn.player.description}") Player player) { - // TODO: Check for relevant self/others teleport permissions + // TODO: Better handling of permission checking with CorePermissionsChecker + String permission = player.equals(issuer.getPlayer()) ? "multiverse.core.spawn.self" : "multiverse.core.spawn.other"; + if (!issuer.hasPermission(permission)) { + issuer.sendMessage("You do not have permission to use this command!"); + return; + } - // The player is in the world, so it must be loaded - LoadedMultiverseWorld world = worldManager.getLoadedWorld(player.getWorld().getName()).getOrNull(); + LoadedMultiverseWorld world = worldManager.getLoadedWorld(player.getWorld()).getOrNull(); if (world == null) { issuer.sendMessage("The world the player you are trying to teleport is in, is not a multiverse world"); + return; } // Teleport the player @@ -89,4 +88,10 @@ class SpawnCommand extends MultiverseCommand { } return issuer.getIssuer().getName(); } + + @Override + public boolean hasPermission(CommandIssuer issuer) { + // TODO: Fix autocomplete showing even if the player doesn't have permission + return issuer.hasPermission("multiverse.core.spawn.self") || issuer.hasPermission("multiverse.core.spawn.other"); + } }