|
| 1 | +package dev.ftb.mods.ftbteambases.command; |
| 2 | + |
| 3 | +import com.mojang.brigadier.Command; |
| 4 | +import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
| 5 | +import dev.ftb.mods.ftbteambases.config.ServerConfig; |
| 6 | +import dev.ftb.mods.ftbteambases.data.bases.BaseInstanceManager; |
| 7 | +import dev.ftb.mods.ftbteambases.util.MiscUtil; |
| 8 | +import net.minecraft.commands.CommandSourceStack; |
| 9 | +import net.minecraft.commands.Commands; |
| 10 | +import net.minecraft.commands.arguments.coordinates.BlockPosArgument; |
| 11 | +import net.minecraft.core.BlockPos; |
| 12 | +import net.minecraft.network.chat.Component; |
| 13 | +import net.minecraft.server.level.ServerLevel; |
| 14 | + |
| 15 | +import static net.minecraft.commands.Commands.argument; |
| 16 | +import static net.minecraft.commands.Commands.literal; |
| 17 | + |
| 18 | +public class SetLobbyPosCommand { |
| 19 | + public static LiteralArgumentBuilder<CommandSourceStack> register() { |
| 20 | + return literal("setlobbypos") |
| 21 | + .requires(ctx -> ctx.hasPermission(Commands.LEVEL_GAMEMASTERS)) |
| 22 | + .then(argument("pos", BlockPosArgument.blockPos()) |
| 23 | + .executes(ctx -> setLobbyPos(ctx.getSource(), BlockPosArgument.getBlockPos(ctx, "pos"))) |
| 24 | + ); |
| 25 | + } |
| 26 | + |
| 27 | + private static int setLobbyPos(CommandSourceStack source, BlockPos pos) { |
| 28 | + BaseInstanceManager.get(source.getServer()).setLobbySpawnPos(pos); |
| 29 | + |
| 30 | + source.sendSuccess(() -> Component.literal("lobby pos updated to " + MiscUtil.blockPosStr(pos)), false); |
| 31 | + |
| 32 | + ServerConfig.lobbyDimension().ifPresent(dim -> { |
| 33 | + ServerLevel level = source.getServer().getLevel(dim); |
| 34 | + if (level != null) { |
| 35 | + level.setDefaultSpawnPos(pos, ServerConfig.LOBBY_PLAYER_YAW.get().floatValue()); |
| 36 | + } |
| 37 | + }); |
| 38 | + |
| 39 | + return Command.SINGLE_SUCCESS; |
| 40 | + } |
| 41 | +} |
0 commit comments