diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2017-08-18 12:17:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-18 12:17:56 +0200 |
commit | 72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82 (patch) | |
tree | c1c1a040332d4ba1f784be25c67c9800e85015eb /src/Entities/Player.cpp | |
parent | Sitting cats block enderchests from opening (#3906) (diff) | |
parent | Changed entity ownership model to use smart pointers (diff) | |
download | cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.gz cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.bz2 cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.lz cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.xz cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.tar.zst cuberite-72d7027861a3b7e7e8bb5fdcbbc5a1a778fa7f82.zip |
Diffstat (limited to 'src/Entities/Player.cpp')
-rw-r--r-- | src/Entities/Player.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 3e6d912dd..a1b518cbc 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); @@ -2009,7 +2009,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); @@ -2051,8 +2053,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; |