summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorchangyong guo <guo1487@163.com>2018-07-23 01:35:32 +0200
committerpeterbell10 <peterbell10@live.co.uk>2018-07-23 01:35:32 +0200
commit7b0db672d1ff72caec1f45cbc0c855680337766d (patch)
treedf2d4d43418ba307983e5be1d2ed4999c786f02a /src
parentrecover hotbar selected slot after reconnect (#4249) (diff)
downloadcuberite-7b0db672d1ff72caec1f45cbc0c855680337766d.tar
cuberite-7b0db672d1ff72caec1f45cbc0c855680337766d.tar.gz
cuberite-7b0db672d1ff72caec1f45cbc0c855680337766d.tar.bz2
cuberite-7b0db672d1ff72caec1f45cbc0c855680337766d.tar.lz
cuberite-7b0db672d1ff72caec1f45cbc0c855680337766d.tar.xz
cuberite-7b0db672d1ff72caec1f45cbc0c855680337766d.tar.zst
cuberite-7b0db672d1ff72caec1f45cbc0c855680337766d.zip
Diffstat (limited to 'src')
-rw-r--r--src/ClientHandle.cpp21
-rw-r--r--src/Entities/Player.cpp56
-rw-r--r--src/Entities/Player.h3
-rw-r--r--src/Items/ItemBucket.h2
-rw-r--r--src/Protocol/Protocol_1_8.cpp4
-rw-r--r--src/Protocol/Protocol_1_9.cpp4
-rw-r--r--src/World.h1
7 files changed, 48 insertions, 43 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 9ae0b4adc..80819cb61 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -373,16 +373,22 @@ void cClientHandle::FinishAuthenticate(const AString & a_Name, const cUUID & a_U
InvalidateCachedSentChunk();
m_Self.reset();
- World = cRoot::Get()->GetWorld(m_Player->GetLoadedWorldName());
- if (World == nullptr)
+
+ // New player use default world
+ // Player who can load from disk, use loaded world
+ if (m_Player->GetWorld() == nullptr)
{
- World = cRoot::Get()->GetDefaultWorld();
- m_Player->SetPosition(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ());
+ World = cRoot::Get()->GetWorld(m_Player->GetLoadedWorldName());
+ if (World == nullptr)
+ {
+ World = cRoot::Get()->GetDefaultWorld();
+ m_Player->SetPosition(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ());
+ }
+ m_Player->SetWorld(World);
}
-
- if (m_Player->GetGameMode() == eGameMode_NotSet)
+ else
{
- m_Player->LoginSetGameMode(World->GetGameMode());
+ World = m_Player->GetWorld();
}
m_Player->SetIP (m_IPString);
@@ -425,7 +431,6 @@ void cClientHandle::FinishAuthenticate(const AString & a_Name, const cUUID & a_U
cRoot::Get()->BroadcastPlayerListsAddPlayer(*m_Player);
cRoot::Get()->SendPlayerLists(m_Player);
- m_Player->SetWorld(World);
m_State = csAuthenticated;
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index bf5daf172..d8bb22e2f 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -148,6 +148,9 @@ cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) :
// This is a new player. Set the player spawn point to the spawn point of the default world
SetBedPos(Vector3i(static_cast<int>(World->GetSpawnX()), static_cast<int>(World->GetSpawnY()), static_cast<int>(World->GetSpawnZ())), World);
+ SetWorld(World); // Use default world
+ SetCapabilities();
+
LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
);
@@ -1255,8 +1258,7 @@ Vector3d cPlayer::GetEyePosition(void) const
bool cPlayer::IsGameModeCreative(void) const
{
- return (m_GameMode == gmCreative) || // Either the player is explicitly in Creative
- ((m_GameMode == gmNotSet) && m_World->IsGameModeCreative()); // or they inherit from the world and the world is Creative
+ return (GetEffectiveGameMode() == gmCreative);
}
@@ -1265,8 +1267,7 @@ bool cPlayer::IsGameModeCreative(void) const
bool cPlayer::IsGameModeSurvival(void) const
{
- return (m_GameMode == gmSurvival) || // Either the player is explicitly in Survival
- ((m_GameMode == gmNotSet) && m_World->IsGameModeSurvival()); // or they inherit from the world and the world is Survival
+ return (GetEffectiveGameMode() == gmSurvival);
}
@@ -1275,8 +1276,7 @@ bool cPlayer::IsGameModeSurvival(void) const
bool cPlayer::IsGameModeAdventure(void) const
{
- return (m_GameMode == gmAdventure) || // Either the player is explicitly in Adventure
- ((m_GameMode == gmNotSet) && m_World->IsGameModeAdventure()); // or they inherit from the world and the world is Adventure
+ return (GetEffectiveGameMode() == gmAdventure);
}
@@ -1284,8 +1284,7 @@ bool cPlayer::IsGameModeAdventure(void) const
bool cPlayer::IsGameModeSpectator(void) const
{
- return (m_GameMode == gmSpectator) || // Either the player is explicitly in Spectator
- ((m_GameMode == gmNotSet) && m_World->IsGameModeSpectator()); // or they inherit from the world and the world is Spectator
+ return (GetEffectiveGameMode() == gmSpectator);
}
@@ -1553,30 +1552,32 @@ void cPlayer::SetGameMode(eGameMode a_GameMode)
-void cPlayer::LoginSetGameMode( eGameMode a_GameMode)
-{
- m_GameMode = a_GameMode;
-
- SetCapabilities();
-}
-
-
-
-
-
void cPlayer::SetCapabilities()
{
- if (!IsGameModeCreative() || IsGameModeSpectator())
+ // Fly ability
+ if (IsGameModeCreative() || IsGameModeSpectator())
+ {
+ SetCanFly(true);
+ }
+ else
{
SetFlying(false);
SetCanFly(false);
}
+ // Visible
if (IsGameModeSpectator())
{
SetVisible(false);
- SetCanFly(true);
+ }
+ else
+ {
+ SetVisible(true);
+ }
+ // Set for spectator
+ if (IsGameModeSpectator())
+ {
// Clear the current dragging item of the player
if (GetWindow() != nullptr)
{
@@ -1584,10 +1585,6 @@ void cPlayer::SetCapabilities()
GetClientHandle()->SendInventorySlot(-1, -1, m_DraggingItem);
}
}
- else
- {
- SetVisible(true);
- }
}
@@ -2046,6 +2043,12 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
// Stop all mobs from targeting this player
StopEveryoneFromTargetingMe();
+ // Deal with new world
+ SetWorld(a_World);
+
+ // Set capabilities based on new world
+ SetCapabilities();
+
cClientHandle * ch = this->GetClientHandle();
if (ch != nullptr)
{
@@ -2055,7 +2058,6 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
m_ClientHandle->SendRespawn(a_World->GetDimension());
}
-
// Update the view distance.
ch->SetViewDistance(m_ClientHandle->GetRequestedViewDistance());
@@ -2071,7 +2073,7 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
// Queue add to new world and removal from the old one
- SetWorld(a_World); // Chunks may be streamed before cWorld::AddPlayer() sets the world to the new value
+ // Chunks may be streamed before cWorld::AddPlayer() sets the world to the new value
cChunk * ParentChunk = this->GetParentChunk();
LOGD("Warping player \"%s\" from world \"%s\" to \"%s\". Source chunk: (%d, %d) ",
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index a2ee13b45..e710e8396 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -146,9 +146,6 @@ public:
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override;
- // Sets the current gamemode, doesn't check validity, doesn't send update packets to client
- void LoginSetGameMode(eGameMode a_GameMode);
-
// Updates player's capabilities - flying, visibility, etc. from their gamemode.
void SetCapabilities();
diff --git a/src/Items/ItemBucket.h b/src/Items/ItemBucket.h
index 2c93c3856..f45dbae3e 100644
--- a/src/Items/ItemBucket.h
+++ b/src/Items/ItemBucket.h
@@ -140,7 +140,7 @@ public:
return false;
}
- if (a_Player->GetGameMode() != gmCreative)
+ if (!a_Player->IsGameModeCreative())
{
// Remove fluid bucket, add empty bucket:
if (!a_Player->GetInventory().RemoveOneEquippedItem())
diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp
index 643f99841..5055526df 100644
--- a/src/Protocol/Protocol_1_8.cpp
+++ b/src/Protocol/Protocol_1_8.cpp
@@ -947,7 +947,7 @@ void cProtocol_1_8_0::SendPlayerListAddPlayer(const cPlayer & a_Player)
}
}
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetEffectiveGameMode()));
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetClientHandle()->GetPing()));
Pkt.WriteBool(false);
}
@@ -978,7 +978,7 @@ void cProtocol_1_8_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
Pkt.WriteVarInt32(1);
Pkt.WriteVarInt32(1);
Pkt.WriteUUID(a_Player.GetUUID());
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetEffectiveGameMode()));
}
diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp
index 2621f140c..73b81580e 100644
--- a/src/Protocol/Protocol_1_9.cpp
+++ b/src/Protocol/Protocol_1_9.cpp
@@ -992,7 +992,7 @@ void cProtocol_1_9_0::SendPlayerListAddPlayer(const cPlayer & a_Player)
}
}
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetEffectiveGameMode()));
Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetClientHandle()->GetPing()));
Pkt.WriteBool(false);
}
@@ -1023,7 +1023,7 @@ void cProtocol_1_9_0::SendPlayerListUpdateGameMode(const cPlayer & a_Player)
Pkt.WriteVarInt32(1);
Pkt.WriteVarInt32(1);
Pkt.WriteUUID(a_Player.GetUUID());
- Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetGameMode()));
+ Pkt.WriteVarInt32(static_cast<UInt32>(a_Player.GetEffectiveGameMode()));
}
diff --git a/src/World.h b/src/World.h
index bce9212af..fda4ef045 100644
--- a/src/World.h
+++ b/src/World.h
@@ -142,6 +142,7 @@ public:
bool IsGameModeSpectator(void) const { return (m_GameMode == gmSpectator); }
bool IsPVPEnabled(void) const { return m_bEnabledPVP; }
+
bool IsDeepSnowEnabled(void) const { return m_IsDeepSnowEnabled; }
bool ShouldLavaSpawnFire(void) const { return m_ShouldLavaSpawnFire; }