1
0

Merge pull request #2118 from mc-server/login-gamemode

Fix gamemode not changing properly.
This commit is contained in:
Safwat Halaby 2015-05-24 09:52:45 +03:00
commit 79c3e11a31
2 changed files with 154 additions and 148 deletions

View File

@ -1206,20 +1206,7 @@ void cPlayer::SetGameMode(eGameMode a_GameMode)
m_GameMode = a_GameMode; m_GameMode = a_GameMode;
m_ClientHandle->SendGameMode(a_GameMode); m_ClientHandle->SendGameMode(a_GameMode);
if (!(IsGameModeCreative() || IsGameModeSpectator())) SetCapabilities();
{
SetFlying(false);
SetCanFly(false);
}
if (IsGameModeSpectator() && IsVisible())
{
SetVisible(false);
}
else if (!IsVisible())
{
SetVisible(true);
}
m_World->BroadcastPlayerListUpdateGameMode(*this); m_World->BroadcastPlayerListUpdateGameMode(*this);
} }
@ -1231,6 +1218,30 @@ void cPlayer::SetGameMode(eGameMode a_GameMode)
void cPlayer::LoginSetGameMode( eGameMode a_GameMode) void cPlayer::LoginSetGameMode( eGameMode a_GameMode)
{ {
m_GameMode = a_GameMode; m_GameMode = a_GameMode;
SetCapabilities();
}
void cPlayer::SetCapabilities()
{
if (!IsGameModeCreative() || IsGameModeSpectator())
{
SetFlying(false);
SetCanFly(false);
}
if (IsGameModeSpectator())
{
SetVisible(false);
}
else
{
SetVisible(true);
}
} }
@ -2372,7 +2383,3 @@ AString cPlayer::GetUUIDFileName(const AString & a_UUID)
res.append(".json"); res.append(".json");
return res; return res;
} }

View File

@ -162,6 +162,12 @@ public:
*/ */
void SetGameMode(eGameMode a_GameMode); void SetGameMode(eGameMode a_GameMode);
// 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();
/** Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world */ /** Returns true if the player is in Creative mode, either explicitly, or by inheriting from current world */
bool IsGameModeCreative(void) const; bool IsGameModeCreative(void) const;
@ -198,9 +204,6 @@ public:
void SetIP(const AString & a_IP); void SetIP(const AString & a_IP);
// Sets the current gamemode, doesn't check validity, doesn't send update packets to client
void LoginSetGameMode(eGameMode a_GameMode);
/** Forces the player to move in the given direction. /** Forces the player to move in the given direction.
@deprecated Use SetSpeed instead. */ @deprecated Use SetSpeed instead. */
void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export
@ -666,7 +669,3 @@ protected:
This can be used both for online and offline UUIDs. */ This can be used both for online and offline UUIDs. */
AString GetUUIDFileName(const AString & a_UUID); AString GetUUIDFileName(const AString & a_UUID);
} ; // tolua_export } ; // tolua_export