Created SpawnCoordinateCommand

This commit is contained in:
isnortkoolaid 2024-01-08 18:32:52 -05:00
parent 111e7cd16b
commit 067db945ed
2 changed files with 37 additions and 0 deletions

View file

@ -25,5 +25,6 @@ public class Extras implements ModInitializer {
ClearChatCommand.register(dispatcher);
PingCommand.register(dispatcher);
TGBCommand.register(dispatcher);
SpawnCoordinatesCommand.register(dispatcher);
}
}

View file

@ -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<ServerCommandSource> dispatcher) {
final LiteralCommandNode node = dispatcher.register(
literal("spawncoords")
.executes(SpawnCoordinatesCommand::spawnCoordinatesCommand)
);
}
public static int spawnCoordinatesCommand (CommandContext<ServerCommandSource> 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;
}
}