the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 90 lines 3.4 kB view raw
1#include "stdafx.h" 2#include "MinecraftServer.h" 3#include "PlayerList.h" 4#include "ServerPlayer.h" 5#include "PlayerConnection.h" 6#include "..\Minecraft.World\net.minecraft.commands.h" 7#include "..\Minecraft.World\net.minecraft.network.packet.h" 8#include "..\Minecraft.World\net.minecraft.world.level.h" 9#include "..\Minecraft.World\net.minecraft.world.level.dimension.h" 10#include "TeleportCommand.h" 11 12EGameCommand TeleportCommand::getId() 13{ 14 return eGameCommand_Teleport; 15} 16 17void TeleportCommand::execute(shared_ptr<CommandSender> source, byteArray commandData) 18{ 19 ByteArrayInputStream bais(commandData); 20 DataInputStream dis(&bais); 21 22 PlayerUID subjectID = dis.readPlayerUID(); 23 PlayerUID destinationID = dis.readPlayerUID(); 24 25 bais.reset(); 26 27 PlayerList *players = MinecraftServer::getInstance()->getPlayerList(); 28 29 shared_ptr<ServerPlayer> subject = players->getPlayer(subjectID); 30 shared_ptr<ServerPlayer> destination = players->getPlayer(destinationID); 31 32 if(subject != NULL && destination != NULL && subject->level->dimension->id == destination->level->dimension->id && subject->isAlive() ) 33 { 34 subject->ride(nullptr); 35 subject->connection->teleport(destination->x, destination->y, destination->z, destination->yRot, destination->xRot); 36 //logAdminAction(source, "commands.tp.success", subject->getAName(), destination->getAName()); 37 logAdminAction(source, ChatPacket::e_ChatCommandTeleportSuccess, subject->getName(), eTYPE_SERVERPLAYER, destination->getName()); 38 39 if(subject == source) 40 { 41 destination->sendMessage(subject->getName(), ChatPacket::e_ChatCommandTeleportToMe); 42 } 43 else 44 { 45 subject->sendMessage(destination->getName(), ChatPacket::e_ChatCommandTeleportMe); 46 } 47 } 48 49 //if (args.length >= 1) { 50 // MinecraftServer server = MinecraftServer.getInstance(); 51 // ServerPlayer victim; 52 53 // if (args.length == 2 || args.length == 4) { 54 // victim = server.getPlayers().getPlayer(args[0]); 55 // if (victim == null) throw new PlayerNotFoundException(); 56 // } else { 57 // victim = (ServerPlayer) convertSourceToPlayer(source); 58 // } 59 60 // if (args.length == 3 || args.length == 4) { 61 // if (victim.level != null) { 62 // int pos = args.length - 3; 63 // int maxPos = Level.MAX_LEVEL_SIZE; 64 // int x = convertArgToInt(source, args[pos++], -maxPos, maxPos); 65 // int y = convertArgToInt(source, args[pos++], Level.minBuildHeight, Level.maxBuildHeight); 66 // int z = convertArgToInt(source, args[pos++], -maxPos, maxPos); 67 68 // victim.teleportTo(x + 0.5f, y, z + 0.5f); 69 // logAdminAction(source, "commands.tp.coordinates", victim.getAName(), x, y, z); 70 // } 71 // } else if (args.length == 1 || args.length == 2) { 72 // ServerPlayer destination = server.getPlayers().getPlayer(args[args.length - 1]); 73 // if (destination == null) throw new PlayerNotFoundException(); 74 75 // victim.connection.teleport(destination.x, destination.y, destination.z, destination.yRot, destination.xRot); 76 // logAdminAction(source, "commands.tp.success", victim.getAName(), destination.getAName()); 77 // } 78 //} 79} 80 81shared_ptr<GameCommandPacket> TeleportCommand::preparePacket(PlayerUID subject, PlayerUID destination) 82{ 83 ByteArrayOutputStream baos; 84 DataOutputStream dos(&baos); 85 86 dos.writePlayerUID(subject); 87 dos.writePlayerUID(destination); 88 89 return shared_ptr<GameCommandPacket>( new GameCommandPacket(eGameCommand_Teleport, baos.toByteArray() )); 90}