/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.brigadier.CommandDispatcher * com.mojang.brigadier.builder.LiteralArgumentBuilder * com.mojang.brigadier.builder.RequiredArgumentBuilder * com.mojang.brigadier.context.CommandContext */ package net.minecraft.server.commands; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.context.CommandContext; import java.util.Collection; import java.util.Collections; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.commands.arguments.EntityArgument; import net.minecraft.commands.arguments.coordinates.BlockPosArgument; import net.minecraft.commands.arguments.coordinates.Coordinates; import net.minecraft.commands.arguments.coordinates.RotationArgument; import net.minecraft.commands.arguments.coordinates.WorldCoordinates; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceKey; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.level.Level; import net.minecraft.world.level.storage.LevelData; import net.minecraft.world.phys.Vec2; public class SetSpawnCommand { public static void register(CommandDispatcher dispatcher) { dispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("spawnpoint").requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS))).executes(c -> SetSpawnCommand.setSpawn((CommandSourceStack)c.getSource(), Collections.singleton(((CommandSourceStack)c.getSource()).getPlayerOrException()), BlockPos.containing(((CommandSourceStack)c.getSource()).getPosition()), WorldCoordinates.ZERO_ROTATION))).then(((RequiredArgumentBuilder)Commands.argument("targets", EntityArgument.players()).executes(c -> SetSpawnCommand.setSpawn((CommandSourceStack)c.getSource(), EntityArgument.getPlayers((CommandContext)c, "targets"), BlockPos.containing(((CommandSourceStack)c.getSource()).getPosition()), WorldCoordinates.ZERO_ROTATION))).then(((RequiredArgumentBuilder)Commands.argument("pos", BlockPosArgument.blockPos()).executes(c -> SetSpawnCommand.setSpawn((CommandSourceStack)c.getSource(), EntityArgument.getPlayers((CommandContext)c, "targets"), BlockPosArgument.getSpawnablePos((CommandContext)c, "pos"), WorldCoordinates.ZERO_ROTATION))).then(Commands.argument("rotation", RotationArgument.rotation()).executes(c -> SetSpawnCommand.setSpawn((CommandSourceStack)c.getSource(), EntityArgument.getPlayers((CommandContext)c, "targets"), BlockPosArgument.getSpawnablePos((CommandContext)c, "pos"), RotationArgument.getRotation((CommandContext)c, "rotation"))))))); } private static int setSpawn(CommandSourceStack source, Collection targets, BlockPos pos, Coordinates rotation) { ResourceKey dimension = source.getLevel().dimension(); Vec2 rotationVector = rotation.getRotation(source); float yaw = Mth.wrapDegrees(rotationVector.y); float pitch = Mth.clamp(rotationVector.x, -90.0f, 90.0f); for (ServerPlayer target : targets) { target.setRespawnPosition(new ServerPlayer.RespawnConfig(LevelData.RespawnData.of(dimension, pos, yaw, pitch), true), false); } String dimensionName = dimension.identifier().toString(); if (targets.size() == 1) { source.sendSuccess(() -> Component.translatable("commands.spawnpoint.success.single", pos.getX(), pos.getY(), pos.getZ(), Float.valueOf(yaw), Float.valueOf(pitch), dimensionName, ((ServerPlayer)targets.iterator().next()).getDisplayName()), true); } else { source.sendSuccess(() -> Component.translatable("commands.spawnpoint.success.multiple", pos.getX(), pos.getY(), pos.getZ(), Float.valueOf(yaw), Float.valueOf(pitch), dimensionName, targets.size()), true); } return targets.size(); } }