#include "stdafx.h" #include "net.minecraft.commands.h" #include "../Minecraft.Client/MinecraftServer.h" #include "../Minecraft.Client/ServerLevel.h" #include "../Minecraft.Client/ServerPlayer.h" #include "../Minecraft.Client/PlayerList.h" #include "net.minecraft.world.level.h" #include "net.minecraft.world.level.dimension.h" #include "net.minecraft.network.packet.h" #include "SetSpawnpointCommand.h" EGameCommand SetSpawnpointCommand::getId() { return eGameCommand_SetSpawnpoint; } int SetSpawnpointCommand::getPermissionLevel() { return LEVEL_GAMEMASTERS; } void SetSpawnpointCommand::execute(shared_ptr source, byteArray commandData) { ByteArrayInputStream bais(commandData); DataInputStream dis(&bais); PlayerUID uid = dis.readPlayerUID(); shared_ptr player = MinecraftServer::getInstance()->getPlayers()->getPlayer(uid); if (player == nullptr || player->level == nullptr) return; if (player->level->dimension->id != 0) return; Pos pos(Mth::floor(player->x), Mth::floor(player->y), Mth::floor(player->z)); player->setRespawnPosition(&pos, true); } shared_ptr SetSpawnpointCommand::preparePacket(PlayerUID player) { ByteArrayOutputStream baos; DataOutputStream dos(&baos); dos.writePlayerUID(player); return std::make_shared(eGameCommand_SetSpawnpoint, baos.toByteArray()); }