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.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 <position> above in chat like the vanilla TP command
@ -46,9 +45,7 @@ public class SetSpawnCommand extends MultiverseCommand {
@Flags("resolve=issuerAware")
@Syntax("<world>")
@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) {

View File

@ -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());
}

View File

@ -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,

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.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.