Improve spawn command messaging

This commit is contained in:
Ben Woo 2024-08-30 13:06:27 +08:00
parent 8cbf2bc050
commit 330d4fbe39
4 changed files with 32 additions and 19 deletions

View File

@ -13,11 +13,9 @@ import jakarta.inject.Inject;
import org.bukkit.Location; import org.bukkit.Location;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service; 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.MVCommandManager;
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld; import org.mvplugins.multiverse.core.world.LoadedMultiverseWorld;
import org.mvplugins.multiverse.core.world.WorldManager;
@Service @Service
@CommandAlias("mv") @CommandAlias("mv")
@ -28,6 +26,7 @@ public class SetSpawnCommand extends MultiverseCommand {
super(commandManager); super(commandManager);
} }
@CommandAlias("mvsetspawn")
@Subcommand("setspawn") @Subcommand("setspawn")
@CommandPermission("multiverse.core.setspawn") @CommandPermission("multiverse.core.setspawn")
@CommandCompletion("@nothing @mvworlds:scope=loaded ") // TODO: Use Brigadier to show <position> above in chat like the vanilla TP command @CommandCompletion("@nothing @mvworlds:scope=loaded ") // TODO: Use Brigadier to show <position> above in chat like the vanilla TP command
@ -46,9 +45,7 @@ public class SetSpawnCommand extends MultiverseCommand {
@Flags("resolve=issuerAware") @Flags("resolve=issuerAware")
@Syntax("<world>") @Syntax("<world>")
@Description("{@@mv-core.setspawn.world.description}") @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 // TODO: Use a flag to do this, no clue how to edit an inbuilt ACF flag though
// Get the Location // Get the Location
if (location == null) { if (location == null) {

View File

@ -14,6 +14,7 @@ import jakarta.inject.Inject;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jvnet.hk2.annotations.Service; 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.MVCommandManager;
import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; import org.mvplugins.multiverse.core.commandtools.MultiverseCommand;
import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter; import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter;
@ -36,36 +37,45 @@ class SpawnCommand extends MultiverseCommand {
this.safetyTeleporter = safetyTeleporter; this.safetyTeleporter = safetyTeleporter;
} }
@CommandAlias("mvspawn")
@Subcommand("spawn") @Subcommand("spawn")
@CommandPermission("multiverse.core.spawn") @CommandPermission("multiverse.core.spawn")
@CommandCompletion("@players") @CommandCompletion("@players")
@Syntax("[player]") @Syntax("[player]")
@Description("{@@mv-core.spawn.description}") @Description("{@@mv-core.spawn.description}")
void onSpawnTpCommand( void onSpawnTpCommand(
BukkitCommandIssuer issuer, MVCommandIssuer issuer,
@Flags("resolve=issuerAware") @Flags("resolve=issuerAware")
@Syntax("[player]") @Syntax("[player]")
@Description("{@@mv-core.spawn.player.description}") @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 // 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().getName()).getOrNull();
if (world == null) { if (world == null) {
issuer.sendMessage("The world the player you are trying to teleport is in, is not a multiverse world"); 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 // Teleport the player
safetyTeleporter.teleportSafely(issuer.getIssuer(), player, world.getSpawnLocation()); // TODO: Different message for teleporting self vs others
safetyTeleporter.teleportSafely(issuer.getIssuer(), player, world.getSpawnLocation())
player.sendMessage(commandManager.formatMessage( .onSuccess(() -> player.sendMessage(commandManager.formatMessage(
issuer, issuer,
MessageType.INFO, MessageType.INFO,
MVCorei18n.SPAWN_MESSAGE, MVCorei18n.SPAWN_SUCCESS,
"{teleporter}", "{teleporter}",
getTeleporterName(issuer, player) 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()); Logging.fine("Teleported " + player.getName() + " to " + world.getSpawnLocation().getX() + ", " + world.getSpawnLocation().getY() + ", " + world.getSpawnLocation().getZ());
} }

View File

@ -97,7 +97,8 @@ public enum MVCorei18n implements MessageKeyProvider {
// spawn tp command // spawn tp command
SPAWN_DESCRIPTION, SPAWN_DESCRIPTION,
SPAWN_PLAYER_DESCRIPTION, SPAWN_PLAYER_DESCRIPTION,
SPAWN_MESSAGE, SPAWN_SUCCESS,
SPAWN_FAILED,
SPAWN_CONSOLENAME, SPAWN_CONSOLENAME,
SPAWN_YOU, SPAWN_YOU,

View File

@ -131,6 +131,11 @@ mv-core.spawn.message={teleporter} just sent you to spawn!
mv-core.spawn.consolename=The console mv-core.spawn.consolename=The console
mv-core.spawn.you=You 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 tp
mv-core.teleport.description=Allows you to teleport to a location on your server! mv-core.teleport.description=Allows you to teleport to a location on your server!
mv-core.teleport.player.description=Target player to teleport. mv-core.teleport.player.description=Target player to teleport.