summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/ClientHandle.cpp6
-rw-r--r--source/Plugin.h1
-rw-r--r--source/PluginLua.cpp13
-rw-r--r--source/PluginLua.h1
-rw-r--r--source/PluginManager.cpp21
-rw-r--r--source/PluginManager.h2
6 files changed, 44 insertions, 0 deletions
diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp
index 7605f5251..102153de1 100644
--- a/source/ClientHandle.cpp
+++ b/source/ClientHandle.cpp
@@ -997,6 +997,12 @@ void cClientHandle::HandlePlayerMoveLook(double a_PosX, double a_PosY, double a_
void cClientHandle::HandleAnimation(char a_Animation)
{
+ if (cPluginManager::Get()->CallHookPlayerAnimation(*m_Player, a_Animation))
+ {
+ // Plugin disagrees, bail out
+ return;
+ }
+
m_Player->GetWorld()->BroadcastPlayerAnimation(*m_Player, a_Animation, this);
}
diff --git a/source/Plugin.h b/source/Plugin.h
index ce443835b..de8835838 100644
--- a/source/Plugin.h
+++ b/source/Plugin.h
@@ -63,6 +63,7 @@ public:
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) = 0;
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) = 0;
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) = 0;
+ virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) = 0;
virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual bool OnPlayerEating (cPlayer & a_Player) = 0;
diff --git a/source/PluginLua.cpp b/source/PluginLua.cpp
index 8adfdbd81..5ee4fe9f2 100644
--- a/source/PluginLua.cpp
+++ b/source/PluginLua.cpp
@@ -350,6 +350,18 @@ bool cPlugin_NewLua::OnLogin(cClientHandle * a_Client, int a_ProtocolVersion, co
+bool cPlugin_NewLua::OnPlayerAnimation(cPlayer & a_Player, int a_Animation)
+{
+ cCSLock Lock(m_CriticalSection);
+ bool res = false;
+ m_LuaState.Call(GetHookFnName(cPluginManager::HOOK_PLAYER_ANIMATION), &a_Player, a_Animation, cLuaState::Return, res);
+ return res;
+}
+
+
+
+
+
bool cPlugin_NewLua::OnPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
cCSLock Lock(m_CriticalSection);
@@ -842,6 +854,7 @@ const char * cPlugin_NewLua::GetHookFnName(cPluginManager::PluginHook a_Hook)
case cPluginManager::HOOK_HANDSHAKE: return "OnHandshake";
case cPluginManager::HOOK_KILLING: return "OnKilling";
case cPluginManager::HOOK_LOGIN: return "OnLogin";
+ case cPluginManager::HOOK_PLAYER_ANIMATION: return "OnPlayerAnimation";
case cPluginManager::HOOK_PLAYER_BREAKING_BLOCK: return "OnPlayerBreakingBlock";
case cPluginManager::HOOK_PLAYER_BROKEN_BLOCK: return "OnPlayerBrokenBlock";
case cPluginManager::HOOK_PLAYER_EATING: return "OnPlayerEating";
diff --git a/source/PluginLua.h b/source/PluginLua.h
index 5c0ff3f0d..b6344b484 100644
--- a/source/PluginLua.h
+++ b/source/PluginLua.h
@@ -59,6 +59,7 @@ public:
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override;
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer) override;
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
+ virtual bool OnPlayerAnimation (cPlayer & a_Player, int a_Animation) override;
virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual bool OnPlayerEating (cPlayer & a_Player) override;
diff --git a/source/PluginManager.cpp b/source/PluginManager.cpp
index 27ace86b9..523d00372 100644
--- a/source/PluginManager.cpp
+++ b/source/PluginManager.cpp
@@ -531,6 +531,27 @@ bool cPluginManager::CallHookLogin(cClientHandle * a_Client, int a_ProtocolVersi
+bool cPluginManager::CallHookPlayerAnimation(cPlayer & a_Player, int a_Animation)
+{
+ HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_ANIMATION);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnPlayerAnimation(a_Player, a_Animation))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
bool cPluginManager::CallHookPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_BREAKING_BLOCK);
diff --git a/source/PluginManager.h b/source/PluginManager.h
index 9db77124d..36be4d7e5 100644
--- a/source/PluginManager.h
+++ b/source/PluginManager.h
@@ -68,6 +68,7 @@ public: // tolua_export
HOOK_HANDSHAKE,
HOOK_KILLING,
HOOK_LOGIN,
+ HOOK_PLAYER_ANIMATION,
HOOK_PLAYER_BREAKING_BLOCK,
HOOK_PLAYER_BROKEN_BLOCK,
HOOK_PLAYER_EATING,
@@ -144,6 +145,7 @@ public: // tolua_export
bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username);
bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer);
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
+ bool CallHookPlayerAnimation (cPlayer & a_Player, int a_Animation);
bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
bool CallHookPlayerEating (cPlayer & a_Player);