fix(PlayerConnection): /tp fix

fix(PlayerConnection): pointer

fix(PlayerConnection): bytearray

fix(PlayerConnection): bytearray

fix(PlayerConnection): bytearray

fix(TeleportCommand): crash on coords

fix(TeleportCommand): crash on coords

fix: sunflower randomly spawning
This commit is contained in:
neoapps-dev 2026-05-03 16:16:07 +03:00
parent 083ccbd4e9
commit 89a64882ef
6 changed files with 96 additions and 86 deletions

View file

@ -61,6 +61,7 @@ extern bool g_Win64DedicatedServer;
//neo: added //neo: added
#include "ItemNameMap.h" #include "ItemNameMap.h"
#include "../Minecraft.World/ByteArrayOutputStream.h"
namespace namespace
{ {
@ -1131,19 +1132,10 @@ if (cmd == L"tp" || cmd == L"teleport")
? static_cast<byte>(tpTarget->xRot) ? static_cast<byte>(tpTarget->xRot)
: static_cast<byte>(stoi(sXRot) & 0xFF); : static_cast<byte>(stoi(sXRot) & 0xFF);
TeleportEntityPacket packet( shared_ptr<GameCommandPacket> gamePacket = TeleportCommand::preparePacket(
tpTarget->entityId, tpTarget->getXuid(), x, y, z, yRot, xRot);
static_cast<int>(x),
static_cast<int>(y),
static_cast<int>(z),
yRot,
xRot
);
DataOutputStream ds(OutputStream::createMemoryStream());
packet.write(&ds);
shared_ptr<GameCommandPacket> gamePacket = make_shared<GameCommandPacket>(eGameCommand_Teleport, ds.getData());
server->getCommandDispatcher()->performCommand(tpTarget, eGameCommand_Teleport, gamePacket->data); server->getCommandDispatcher()->performCommand(tpTarget, eGameCommand_Teleport, gamePacket->data);
} }
} else if (cmd == L"time") } else if (cmd == L"time")
{ {
if (!player->hasPermission(eGameCommand_Time)) if (!player->hasPermission(eGameCommand_Time))

View file

@ -19,89 +19,95 @@ EGameCommand TeleportCommand::getId()
void TeleportCommand::execute(shared_ptr<CommandSender> source, byteArray commandData) void TeleportCommand::execute(shared_ptr<CommandSender> source, byteArray commandData)
{ {
ByteArrayInputStream bais(commandData); ByteArrayInputStream bais(commandData);
DataInputStream dis(&bais); DataInputStream dis(&bais);
byte flag = dis.readByte();
PlayerUID subjectID = dis.readPlayerUID();
PlayerList *players = MinecraftServer::getInstance()->getPlayerList();
shared_ptr<ServerPlayer> subject = players->getPlayer(subjectID);
if (subject == nullptr || !subject->isAlive())
return;
PlayerUID subjectID = dis.readPlayerUID(); if (flag == 1)
PlayerUID destinationID = dis.readPlayerUID(); {
float x = dis.readFloat();
float y = dis.readFloat();
float z = dis.readFloat();
byte yRot = dis.readByte();
byte xRot = dis.readByte();
bais.reset(); subject->ride(nullptr);
PlayerList *players = MinecraftServer::getInstance()->getPlayerList();
shared_ptr<ServerPlayer> subject = players->getPlayer(subjectID);
shared_ptr<ServerPlayer> destination = players->getPlayer(destinationID);
if(subject != nullptr && destination != nullptr && subject->level->dimension->id == destination->level->dimension->id && subject->isAlive() )
{
subject->ride(nullptr);
#if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD) #if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
{ {
double outX, outY, outZ; double outX, outY, outZ;
bool cancelled = FourKitBridge::FirePlayerTeleport(subject->entityId, bool cancelled = FourKitBridge::FirePlayerTeleport(subject->entityId,
subject->x, subject->y, subject->z, subject->dimension, subject->x, subject->y, subject->z, subject->dimension,
destination->x, destination->y, destination->z, destination->dimension, x, y, z, subject->dimension,
1 /* COMMAND */, 1, &outX, &outY, &outZ);
&outX, &outY, &outZ); if (cancelled)
if (cancelled) return;
return; subject->connection->teleport(outX, outY, outZ, yRot, xRot);
subject->connection->teleport(outX, outY, outZ, destination->yRot, destination->xRot); }
}
#else #else
subject->connection->teleport(destination->x, destination->y, destination->z, destination->yRot, destination->xRot); subject->connection->teleport(x, y, z, yRot, xRot);
#endif #endif
//logAdminAction(source, "commands.tp.success", subject->getAName(), destination->getAName()); logAdminAction(source, ChatPacket::e_ChatCommandTeleportSuccess, subject->getName(), eTYPE_SERVERPLAYER, subject->getName());
logAdminAction(source, ChatPacket::e_ChatCommandTeleportSuccess, subject->getName(), eTYPE_SERVERPLAYER, destination->getName()); }
else
{
PlayerUID destinationID = dis.readPlayerUID();
shared_ptr<ServerPlayer> destination = players->getPlayer(destinationID);
if (destination == nullptr)
return;
if(subject == source) if (subject->level->dimension->id != destination->level->dimension->id)
{ return;
destination->sendMessage(subject->getName(), ChatPacket::e_ChatCommandTeleportToMe);
}
else
{
subject->sendMessage(destination->getName(), ChatPacket::e_ChatCommandTeleportMe);
}
}
//if (args.length >= 1) { subject->ride(nullptr);
// MinecraftServer server = MinecraftServer.getInstance(); #if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD)
// ServerPlayer victim; {
double outX, outY, outZ;
// if (args.length == 2 || args.length == 4) { bool cancelled = FourKitBridge::FirePlayerTeleport(subject->entityId,
// victim = server.getPlayers().getPlayer(args[0]); subject->x, subject->y, subject->z, subject->dimension,
// if (victim == null) throw new PlayerNotFoundException(); destination->x, destination->y, destination->z, destination->dimension,
// } else { 1, &outX, &outY, &outZ);
// victim = (ServerPlayer) convertSourceToPlayer(source); if (cancelled)
// } return;
subject->connection->teleport(outX, outY, outZ, destination->yRot, destination->xRot);
// if (args.length == 3 || args.length == 4) { }
// if (victim.level != null) { #else
// int pos = args.length - 3; subject->connection->teleport(destination->x, destination->y, destination->z, destination->yRot, destination->xRot);
// int maxPos = Level.MAX_LEVEL_SIZE; #endif
// int x = convertArgToInt(source, args[pos++], -maxPos, maxPos); logAdminAction(source, ChatPacket::e_ChatCommandTeleportSuccess, subject->getName(), eTYPE_SERVERPLAYER, destination->getName());
// int y = convertArgToInt(source, args[pos++], Level.minBuildHeight, Level.maxBuildHeight); if (subject == source)
// int z = convertArgToInt(source, args[pos++], -maxPos, maxPos); destination->sendMessage(subject->getName(), ChatPacket::e_ChatCommandTeleportToMe);
else
// victim.teleportTo(x + 0.5f, y, z + 0.5f); subject->sendMessage(destination->getName(), ChatPacket::e_ChatCommandTeleportMe);
// logAdminAction(source, "commands.tp.coordinates", victim.getAName(), x, y, z); }
// }
// } else if (args.length == 1 || args.length == 2) {
// ServerPlayer destination = server.getPlayers().getPlayer(args[args.length - 1]);
// if (destination == null) throw new PlayerNotFoundException();
// victim.connection.teleport(destination.x, destination.y, destination.z, destination.yRot, destination.xRot);
// logAdminAction(source, "commands.tp.success", victim.getAName(), destination.getAName());
// }
//}
} }
shared_ptr<GameCommandPacket> TeleportCommand::preparePacket(PlayerUID subject, PlayerUID destination) shared_ptr<GameCommandPacket> TeleportCommand::preparePacket(PlayerUID subject, PlayerUID destination)
{ {
ByteArrayOutputStream baos; ByteArrayOutputStream baos;
DataOutputStream dos(&baos); DataOutputStream dos(&baos);
dos.writeByte(0);
dos.writePlayerUID(subject); dos.writePlayerUID(subject);
dos.writePlayerUID(destination); dos.writePlayerUID(destination);
return std::make_shared<GameCommandPacket>(eGameCommand_Teleport, baos.toByteArray());
return std::make_shared<GameCommandPacket>(eGameCommand_Teleport, baos.toByteArray()); }
//neo: added
shared_ptr<GameCommandPacket> TeleportCommand::preparePacket(PlayerUID subject, float x, float y, float z, byte yRot, byte xRot)
{
ByteArrayOutputStream baos;
DataOutputStream dos(&baos);
dos.writeByte(1);
dos.writePlayerUID(subject);
dos.writeFloat(x);
dos.writeFloat(y);
dos.writeFloat(z);
dos.writeByte(yRot);
dos.writeByte(xRot);
return std::make_shared<GameCommandPacket>(eGameCommand_Teleport, baos.toByteArray());
} }

View file

@ -9,4 +9,7 @@ public:
virtual void execute(shared_ptr<CommandSender> source, byteArray commandData); virtual void execute(shared_ptr<CommandSender> source, byteArray commandData);
static shared_ptr<GameCommandPacket> preparePacket(PlayerUID subject, PlayerUID destination); static shared_ptr<GameCommandPacket> preparePacket(PlayerUID subject, PlayerUID destination);
//neo: added
static shared_ptr<GameCommandPacket> preparePacket(PlayerUID subject, float x, float y, float z, byte yRot, byte xRot);
}; };

View file

@ -551,10 +551,10 @@ int Biome::getRandomDoublePlantType(Random *random)
{ {
int type = random->nextInt(10); int type = random->nextInt(10);
if (type < 7) return 0; if (type < 7) return 2;
if (type == 7) return 3; if (type == 7) return 3;
if (type == 8) return 4; if (type == 8) return 4;
return 2; return 5;
} }
Biome* Biome::getBiome(uint32_t id) { Biome* Biome::getBiome(uint32_t id) {

View file

@ -274,3 +274,9 @@ void DataOutputStream::writePlayerUID(PlayerUID player)
writeLong(player); writeLong(player);
#endif // PS3 #endif // PS3
} }
//neo: added
OutputStream* DataOutputStream::getChildOutputStream()
{
return stream;
}

View file

@ -35,4 +35,7 @@ public:
virtual void writeUTF(const wstring& a); virtual void writeUTF(const wstring& a);
virtual void writePlayerUID(PlayerUID player); virtual void writePlayerUID(PlayerUID player);
virtual void flush(); virtual void flush();
//neo: added for future use cases, dont ask.
virtual OutputStream* getChildOutputStream();
}; };