From 067db945ed8fa5e05b232ccf95f26a4271d53b0e Mon Sep 17 00:00:00 2001 From: isnortkoolaid Date: Mon, 8 Jan 2024 18:32:52 -0500 Subject: [PATCH] Created SpawnCoordinateCommand --- .../java/land/chipmunk/tgbextras/Extras.java | 1 + .../commands/SpawnCoordinatesCommand.java | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/main/java/land/chipmunk/tgbextras/commands/SpawnCoordinatesCommand.java diff --git a/src/main/java/land/chipmunk/tgbextras/Extras.java b/src/main/java/land/chipmunk/tgbextras/Extras.java index 41e4155..7e04e97 100644 --- a/src/main/java/land/chipmunk/tgbextras/Extras.java +++ b/src/main/java/land/chipmunk/tgbextras/Extras.java @@ -25,5 +25,6 @@ public class Extras implements ModInitializer { ClearChatCommand.register(dispatcher); PingCommand.register(dispatcher); TGBCommand.register(dispatcher); + SpawnCoordinatesCommand.register(dispatcher); } } \ No newline at end of file diff --git a/src/main/java/land/chipmunk/tgbextras/commands/SpawnCoordinatesCommand.java b/src/main/java/land/chipmunk/tgbextras/commands/SpawnCoordinatesCommand.java new file mode 100644 index 0000000..e435084 --- /dev/null +++ b/src/main/java/land/chipmunk/tgbextras/commands/SpawnCoordinatesCommand.java @@ -0,0 +1,36 @@ +package land.chipmunk.tgbextras.commands; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.tree.LiteralCommandNode; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.text.Text; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +import static net.minecraft.server.command.CommandManager.literal; + +public class SpawnCoordinatesCommand { + public static void register (CommandDispatcher dispatcher) { + final LiteralCommandNode node = dispatcher.register( + literal("spawncoords") + .executes(SpawnCoordinatesCommand::spawnCoordinatesCommand) + ); + } + public static int spawnCoordinatesCommand (CommandContext context) throws CommandSyntaxException { + final ServerCommandSource source = context.getSource(); + final @NotNull ServerPlayerEntity player = source.getPlayerOrThrow(); + if(player.getSpawnPointPosition() == null){ + source.sendFeedback(() -> Text.literal("Your spawn point doesn't exist / is at the world spawn."), false); + } else { + final String coords = String.valueOf(player.getSpawnPointPosition().toString()).replace("BlockPos{x=", "").replace("y=", "").replace("z=", "").replace("}", ""); + source.sendFeedback(() -> Text.literal("Your spawn point is at " + coords), false); + } + return Command.SINGLE_SUCCESS; + } + +} \ No newline at end of file