summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CONTRIBUTORS1
-rw-r--r--Server/Plugins/APIDump/Classes/Plugins.lua4
-rw-r--r--Server/Plugins/APIDump/Hooks/OnPlayerMoving.lua1
-rw-r--r--src/Bindings/Plugin.h5
-rw-r--r--src/Bindings/PluginLua.cpp15
-rw-r--r--src/Bindings/PluginLua.h5
-rw-r--r--src/Bindings/PluginManager.cpp17
-rw-r--r--src/Bindings/PluginManager.h4
-rw-r--r--src/ClientHandle.cpp2
-rw-r--r--src/Entities/Player.cpp7
10 files changed, 50 insertions, 11 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 8c6f6fd56..0bfc953f5 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -38,6 +38,7 @@ marmot21
Masy98
mathiascode
mborland
+MeMuXin
mgueydan
MikeHunsinger
mtilden
diff --git a/Server/Plugins/APIDump/Classes/Plugins.lua b/Server/Plugins/APIDump/Classes/Plugins.lua
index 9945a2478..bb9848667 100644
--- a/Server/Plugins/APIDump/Classes/Plugins.lua
+++ b/Server/Plugins/APIDump/Classes/Plugins.lua
@@ -818,6 +818,10 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
{
Notes = "Called after a player has broken a block.",
},
+ HOOK_PLAYER_CROUCHED =
+ {
+ Notes = "Called when a player crouches.",
+ },
HOOK_PLAYER_DESTROYED =
{
Notes = "Called when the {{cPlayer}} object is destroyed - a player has disconnected.",
diff --git a/Server/Plugins/APIDump/Hooks/OnPlayerMoving.lua b/Server/Plugins/APIDump/Hooks/OnPlayerMoving.lua
index 4385bf94d..6b3df6bf4 100644
--- a/Server/Plugins/APIDump/Hooks/OnPlayerMoving.lua
+++ b/Server/Plugins/APIDump/Hooks/OnPlayerMoving.lua
@@ -13,6 +13,7 @@ return
{ 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." },
+ { Name = "PreviousIsOnGround", Type = "{{boolean}}", Notes = "Specifies if the player was standing on a solid block." },
},
Returns = [[
If the function returns true, movement is prohibited.</p>
diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h
index 737ed8465..afc575b13 100644
--- a/src/Bindings/Plugin.h
+++ b/src/Bindings/Plugin.h
@@ -80,10 +80,11 @@ public:
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) = 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 OnPlayerMoving (cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition) = 0;
- virtual bool OnPlayerOpeningWindow(cPlayer & a_Player, cWindow & a_Window) = 0;
+ virtual bool OnPlayerMoving (cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition, bool a_PreviousIsOnGround) = 0;
+ virtual bool OnPlayerOpeningWindow (cPlayer & a_Player, cWindow & a_Window) = 0;
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, const sSetBlock & a_BlockChange) = 0;
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, const sSetBlock & a_BlockChange) = 0;
+ virtual bool OnPlayerCrouched (cPlayer & a_Player) = 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 OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity) = 0;
virtual bool OnPlayerShooting (cPlayer & a_Player) = 0;
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index e2062117a..52695196b 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -665,9 +665,9 @@ bool cPluginLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_Block
-bool cPluginLua::OnPlayerMoving(cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition)
+bool cPluginLua::OnPlayerMoving(cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition, bool a_PreviousIsOnGround)
{
- return CallSimpleHooks(cPluginManager::HOOK_PLAYER_MOVING, &a_Player, a_OldPosition, a_NewPosition);
+ return CallSimpleHooks(cPluginManager::HOOK_PLAYER_MOVING, &a_Player, a_OldPosition, a_NewPosition, a_PreviousIsOnGround);
}
@@ -718,6 +718,16 @@ bool cPluginLua::OnPlayerPlacingBlock(cPlayer & a_Player, const sSetBlock & a_Bl
+bool cPluginLua::OnPlayerCrouched(cPlayer & a_Player)
+{
+ return CallSimpleHooks(cPluginManager::HOOK_PLAYER_CROUCHED,
+ &a_Player);
+}
+
+
+
+
+
bool cPluginLua::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)
{
return CallSimpleHooks(cPluginManager::HOOK_PLAYER_RIGHT_CLICK, &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
@@ -1093,6 +1103,7 @@ const char * cPluginLua::GetHookFnName(int a_HookType)
case cPluginManager::HOOK_PLAYER_OPENING_WINDOW: return "OnPlayerOpeningWindow";
case cPluginManager::HOOK_PLAYER_PLACED_BLOCK: return "OnPlayerPlacedBlock";
case cPluginManager::HOOK_PLAYER_PLACING_BLOCK: return "OnPlayerPlacingBlock";
+ case cPluginManager::HOOK_PLAYER_CROUCHED: return "OnPlayerCrouched";
case cPluginManager::HOOK_PLAYER_RIGHT_CLICK: return "OnPlayerRightClick";
case cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY: return "OnPlayerRightClickingEntity";
case cPluginManager::HOOK_PLAYER_SHOOTING: return "OnPlayerShooting";
diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h
index 50ab328d6..99e2f22ef 100644
--- a/src/Bindings/PluginLua.h
+++ b/src/Bindings/PluginLua.h
@@ -101,10 +101,11 @@ public:
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) override;
virtual bool OnPlayerJoined (cPlayer & a_Player) 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 OnPlayerMoving (cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition) override;
- virtual bool OnPlayerOpeningWindow(cPlayer & a_Player, cWindow & a_Window) override;
+ virtual bool OnPlayerMoving (cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition, bool a_PreviousIsOnGround) override;
+ virtual bool OnPlayerOpeningWindow (cPlayer & a_Player, cWindow & a_Window) override;
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, const sSetBlock & a_BlockChange) override;
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, const sSetBlock & a_BlockChange) override;
+ virtual bool OnPlayerCrouched (cPlayer & a_Player) override;
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) override;
virtual bool OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity) override;
virtual bool OnPlayerShooting (cPlayer & a_Player) override;
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 987b6a7cf..13039f834 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -794,11 +794,11 @@ bool cPluginManager::CallHookPlayerLeftClick(cPlayer & a_Player, int a_BlockX, i
-bool cPluginManager::CallHookPlayerMoving(cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition)
+bool cPluginManager::CallHookPlayerMoving(cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition, bool a_PreviousIsOnGround)
{
return GenericCallHook(HOOK_PLAYER_MOVING, [&](cPlugin * a_Plugin)
{
- return a_Plugin->OnPlayerMoving(a_Player, a_OldPosition, a_NewPosition);
+ return a_Plugin->OnPlayerMoving(a_Player, a_OldPosition, a_NewPosition, a_PreviousIsOnGround);
}
);
}
@@ -846,6 +846,19 @@ bool cPluginManager::CallHookPlayerPlacingBlock(cPlayer & a_Player, const sSetBl
+bool cPluginManager::CallHookPlayerCrouched(cPlayer & a_Player)
+{
+ return GenericCallHook(HOOK_PLAYER_CROUCHED, [&](cPlugin * a_Plugin)
+ {
+ return a_Plugin->OnPlayerCrouched(a_Player);
+ }
+ );
+}
+
+
+
+
+
bool cPluginManager::CallHookPlayerRightClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
return GenericCallHook(HOOK_PLAYER_RIGHT_CLICK, [&](cPlugin * a_Plugin)
diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h
index 7ce4b0f3f..04dbed67d 100644
--- a/src/Bindings/PluginManager.h
+++ b/src/Bindings/PluginManager.h
@@ -117,6 +117,7 @@ public:
HOOK_PLAYER_OPENING_WINDOW,
HOOK_PLAYER_PLACED_BLOCK,
HOOK_PLAYER_PLACING_BLOCK,
+ HOOK_PLAYER_CROUCHED,
HOOK_PLAYER_RIGHT_CLICK,
HOOK_PLAYER_RIGHT_CLICKING_ENTITY,
HOOK_PLAYER_SHOOTING,
@@ -261,10 +262,11 @@ public:
bool CallHookPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel);
bool CallHookPlayerJoined (cPlayer & a_Player);
bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
- bool CallHookPlayerMoving (cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition);
+ bool CallHookPlayerMoving (cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition, bool a_PreviousIsOnGround);
bool CallHookPlayerOpeningWindow (cPlayer & a_Player, cWindow & a_Window);
bool CallHookPlayerPlacedBlock (cPlayer & a_Player, const sSetBlock & a_BlockChange);
bool CallHookPlayerPlacingBlock (cPlayer & a_Player, const sSetBlock & a_BlockChange);
+ bool CallHookPlayerCrouched (cPlayer & a_Player);
bool CallHookPlayerRightClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ);
bool CallHookPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity);
bool CallHookPlayerShooting (cPlayer & a_Player);
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 351e7203a..5fbea5403 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -869,7 +869,7 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ,
return;
}
- if (cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*m_Player, OldPosition, NewPosition))
+ if (cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*m_Player, OldPosition, NewPosition, PreviousIsOnGround))
{
SendPlayerMoveLook();
return;
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 637cc3710..f673813af 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -863,12 +863,17 @@ void cPlayer::SetFlyingMaxSpeed(double a_Speed)
void cPlayer::SetCrouch(bool a_IsCrouched)
{
// Set the crouch status, broadcast to all visible players
-
if (a_IsCrouched == m_IsCrouched)
{
// No change
return;
}
+
+ if (a_IsCrouched)
+ {
+ cRoot::Get()->GetPluginManager()->CallHookPlayerCrouched(*this);
+ }
+
m_IsCrouched = a_IsCrouched;
m_World->BroadcastEntityMetadata(*this);
}