summaryrefslogtreecommitdiffstats
path: root/src/Entities/Player.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2016-12-19 21:12:23 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2017-08-07 20:24:16 +0200
commit4ef47aed62364f9cf1474864e5cf94232b4477af (patch)
tree28ca15247c2437b91e9aada48c2da4a1a3c00c17 /src/Entities/Player.cpp
parentRemoved unneeded includes (#3902) (diff)
downloadcuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.gz
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.bz2
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.lz
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.xz
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.tar.zst
cuberite-4ef47aed62364f9cf1474864e5cf94232b4477af.zip
Diffstat (limited to 'src/Entities/Player.cpp')
-rw-r--r--src/Entities/Player.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 3bbe334fb..aaf06fa34 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -149,12 +149,12 @@ cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) :
-bool cPlayer::Initialize(cWorld & a_World)
+bool cPlayer::Initialize(OwnedEntity a_Self, cWorld & a_World)
{
UNUSED(a_World);
ASSERT(GetWorld() != nullptr);
ASSERT(GetParentChunk() == nullptr);
- GetWorld()->AddPlayer(this);
+ GetWorld()->AddPlayer(std::unique_ptr<cPlayer>(static_cast<cPlayer *>(a_Self.release())));
cPluginManager::Get()->CallHookSpawnedEntity(*GetWorld(), *this);
@@ -2003,7 +2003,9 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
GetWorld()->BroadcastDestroyEntity(*this);
// Remove player from world
- GetWorld()->RemovePlayer(this, false);
+ // Make sure that RemovePlayer didn't return a valid smart pointer, due to the second parameter being false
+ // We remain valid and not destructed after this call
+ VERIFY(!GetWorld()->RemovePlayer(*this, false));
// Set position to the new position
SetPosition(a_NewPosition);
@@ -2045,8 +2047,10 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
a_OldWorld.GetName().c_str(), a_World->GetName().c_str(),
ParentChunk->GetPosX(), ParentChunk->GetPosZ()
);
- ParentChunk->RemoveEntity(this);
- a_World->AddPlayer(this, &a_OldWorld); // New world will take over and announce client at its next tick
+
+ // New world will take over and announce client at its next tick
+ auto PlayerPtr = static_cast<cPlayer *>(ParentChunk->RemoveEntity(*this).release());
+ a_World->AddPlayer(std::unique_ptr<cPlayer>(PlayerPtr), &a_OldWorld);
});
return true;