Merge pull request #1329 from mc-server/Move
Better OnPlayerMoving hook.
This commit is contained in:
commit
e045a25e10
@ -11,9 +11,11 @@ return
|
|||||||
Params =
|
Params =
|
||||||
{
|
{
|
||||||
{ Name = "Player", Type = "{{cPlayer}}", Notes = "The player who has moved. The object already has the new position stored in it." },
|
{ Name = "Player", Type = "{{cPlayer}}", Notes = "The player who has moved. The object already has the new position stored in it." },
|
||||||
|
{ Name = "OldPosition", Type = "{{Vector3d}}", Notes = "The old position." },
|
||||||
|
{ Name = "NewPosition", Type = "{{Vector3d}}", Notes = "The new position." },
|
||||||
},
|
},
|
||||||
Returns = [[
|
Returns = [[
|
||||||
If the function returns true, movement is prohibited. FIXME: The player's client is not informed.</p>
|
If the function returns true, movement is prohibited.</p>
|
||||||
<p>
|
<p>
|
||||||
If the function returns false or no value, other plugins' callbacks are called and finally the new
|
If the function returns false or no value, other plugins' callbacks are called and finally the new
|
||||||
position is permanently stored in the cPlayer object.</p>
|
position is permanently stored in the cPlayer object.</p>
|
||||||
|
@ -73,7 +73,7 @@ public:
|
|||||||
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) = 0;
|
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) = 0;
|
||||||
virtual bool OnPlayerJoined (cPlayer & a_Player) = 0;
|
virtual bool OnPlayerJoined (cPlayer & a_Player) = 0;
|
||||||
virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) = 0;
|
virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) = 0;
|
||||||
virtual bool OnPlayerMoved (cPlayer & a_Player) = 0;
|
virtual bool OnPlayerMoving (cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition) = 0;
|
||||||
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
|
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
|
||||||
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
|
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
|
||||||
virtual bool OnPlayerRightClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) = 0;
|
virtual bool OnPlayerRightClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) = 0;
|
||||||
|
@ -835,14 +835,14 @@ bool cPluginLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_Block
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPluginLua::OnPlayerMoved(cPlayer & a_Player)
|
bool cPluginLua::OnPlayerMoving(cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition)
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CriticalSection);
|
cCSLock Lock(m_CriticalSection);
|
||||||
bool res = false;
|
bool res = false;
|
||||||
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_MOVING];
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_MOVING];
|
||||||
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
||||||
{
|
{
|
||||||
m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res);
|
m_LuaState.Call((int)(**itr), &a_Player, &a_OldPosition, &a_NewPosition, cLuaState::Return, res);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -98,7 +98,7 @@ public:
|
|||||||
virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override;
|
virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override;
|
||||||
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) override;
|
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) override;
|
||||||
virtual bool OnPlayerJoined (cPlayer & a_Player) override;
|
virtual bool OnPlayerJoined (cPlayer & a_Player) override;
|
||||||
virtual bool OnPlayerMoved (cPlayer & a_Player) override;
|
virtual bool OnPlayerMoving (cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition) override;
|
||||||
virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) override;
|
virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) override;
|
||||||
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
||||||
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
||||||
|
@ -849,14 +849,14 @@ bool cPluginManager::CallHookPlayerLeftClick(cPlayer & a_Player, int a_BlockX, i
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPluginManager::CallHookPlayerMoving(cPlayer & a_Player)
|
bool cPluginManager::CallHookPlayerMoving(cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition)
|
||||||
{
|
{
|
||||||
FIND_HOOK(HOOK_PLAYER_MOVING);
|
FIND_HOOK(HOOK_PLAYER_MOVING);
|
||||||
VERIFY_HOOK;
|
VERIFY_HOOK;
|
||||||
|
|
||||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||||
{
|
{
|
||||||
if ((*itr)->OnPlayerMoved(a_Player))
|
if ((*itr)->OnPlayerMoving(a_Player, a_OldPosition, a_NewPosition))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ public:
|
|||||||
bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward);
|
bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward);
|
||||||
bool CallHookPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel);
|
bool CallHookPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel);
|
||||||
bool CallHookPlayerJoined (cPlayer & a_Player);
|
bool CallHookPlayerJoined (cPlayer & a_Player);
|
||||||
bool CallHookPlayerMoving (cPlayer & a_Player);
|
bool CallHookPlayerMoving (cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition);
|
||||||
bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
|
bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
|
||||||
bool CallHookPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
bool CallHookPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||||
bool CallHookPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
bool CallHookPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||||
|
@ -225,16 +225,24 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
SendExperience();
|
SendExperience();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CanMove = true;
|
||||||
if (!GetPosition().EqualsEps(m_LastPos, 0.01)) // Non negligible change in position from last tick?
|
if (!GetPosition().EqualsEps(m_LastPos, 0.01)) // Non negligible change in position from last tick?
|
||||||
{
|
{
|
||||||
// Apply food exhaustion from movement:
|
// Apply food exhaustion from movement:
|
||||||
ApplyFoodExhaustionFromMovement();
|
ApplyFoodExhaustionFromMovement();
|
||||||
|
|
||||||
cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this);
|
if (cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this, m_LastPos, GetPosition()))
|
||||||
|
{
|
||||||
|
CanMove = false;
|
||||||
|
TeleportToCoords(m_LastPos.x, m_LastPos.y, m_LastPos.z);
|
||||||
|
}
|
||||||
m_ClientHandle->StreamChunks();
|
m_ClientHandle->StreamChunks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (CanMove)
|
||||||
|
{
|
||||||
BroadcastMovementUpdate(m_ClientHandle);
|
BroadcastMovementUpdate(m_ClientHandle);
|
||||||
|
}
|
||||||
|
|
||||||
if (m_Health > 0) // make sure player is alive
|
if (m_Health > 0) // make sure player is alive
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user