1
0

Renamed HOOK_KILLED to HOOK_KILLING to match naming conventions.

Also tweaked the mechanics so that plugins may revive without dropping other plugins out of the picture.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1182 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-01-28 16:54:11 +00:00
parent f7721c258b
commit 71bbf2d44b
12 changed files with 38 additions and 41 deletions

View File

@ -19,7 +19,7 @@ function Initialize( Plugin )
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BREAKING_BLOCK)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_PLACING_BLOCK)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_LOGIN)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLED)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLING)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT) -- used in web_chat.lua

View File

@ -1,6 +1,6 @@
function OnKilled( Killed, Killer )
if( Killer == nil ) then
local KilledPlayer = tolua.cast( Killed, "cPlayer")
function OnKilling(Victim, Killer)
if (Killer == nil) then
local KilledPlayer = tolua.cast(Victim, "cPlayer")
if( not KilledPlayer:IsA("cPlayer") or KilledPlayer == nil ) then
return false
end
@ -8,11 +8,11 @@ function OnKilled( Killed, Killer )
local Server = cRoot:Get():GetServer()
Server:SendMessage( cChatColor.Red .. KilledPlayer:GetName() .. " died" )
else
local KilledPlayer = tolua.cast( Killed, "cPlayer")
local KilledPlayer = tolua.cast(Victim, "cPlayer")
if( not KilledPlayer:IsA("cPlayer") or KilledPlayer == nil ) then
return false
end
local KillerPlayer = tolua.cast( Killer, "cPlayer")
local KillerPlayer = tolua.cast(Killer, "cPlayer")
if( not KillerPlayer:IsA("cPlayer") or KillerPlayer == nil ) then
return false
end

View File

@ -21,7 +21,7 @@ function Initialize(Plugin)
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_DISCONNECT);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_HANDSHAKE);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLED);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLING);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_LOGIN);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BREAKING_BLOCK);
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BROKEN_BLOCK);
@ -154,8 +154,8 @@ end
function OnKilled(...)
LogHook("OnKilled", unpack(arg));
function OnKilling(...)
LogHook("OnKilling", unpack(arg));
end

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 01/28/13 17:07:07.
** Generated automatically by tolua++-1.0.92 on 01/28/13 17:46:12.
*/
#ifndef __cplusplus
@ -21260,7 +21260,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_constant(tolua_S,"HOOK_CRAFTING_NO_RECIPE",cPluginManager::HOOK_CRAFTING_NO_RECIPE);
tolua_constant(tolua_S,"HOOK_DISCONNECT",cPluginManager::HOOK_DISCONNECT);
tolua_constant(tolua_S,"HOOK_HANDSHAKE",cPluginManager::HOOK_HANDSHAKE);
tolua_constant(tolua_S,"HOOK_KILLED",cPluginManager::HOOK_KILLED);
tolua_constant(tolua_S,"HOOK_KILLING",cPluginManager::HOOK_KILLING);
tolua_constant(tolua_S,"HOOK_LOGIN",cPluginManager::HOOK_LOGIN);
tolua_constant(tolua_S,"HOOK_PLAYER_BREAKING_BLOCK",cPluginManager::HOOK_PLAYER_BREAKING_BLOCK);
tolua_constant(tolua_S,"HOOK_PLAYER_BROKEN_BLOCK",cPluginManager::HOOK_PLAYER_BROKEN_BLOCK);

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 01/28/13 17:07:08.
** Generated automatically by tolua++-1.0.92 on 01/28/13 17:46:13.
*/
/* Exported function */

View File

@ -121,13 +121,13 @@ void cPawn::DoTakeDamage(TakeDamageInfo & a_TDI)
void cPawn::KilledBy(cPawn * a_Killer)
{
short OldHealth = m_Health;
m_Health = 0;
if (cRoot::Get()->GetPluginManager()->CallHookKilled(*this, a_Killer))
cRoot::Get()->GetPluginManager()->CallHookKilling(*this, a_Killer);
if (m_Health > 0)
{
// Plugin wants to 'unkill' the pawn. Set health back and abort
m_Health = OldHealth;
// Plugin wants to 'unkill' the pawn. Abort
return;
}

View File

@ -126,9 +126,9 @@ bool cPlugin::OnDisconnect(cPlayer * a_Player, const AString & a_Reason)
bool cPlugin::OnKilled(cPawn & a_Killed, cEntity * a_Killer)
bool cPlugin::OnKilling(cPawn & a_Victim, cEntity * a_Killer)
{
UNUSED(a_Killed);
UNUSED(a_Victim);
UNUSED(a_Killer);
return false;
}

View File

@ -56,7 +56,7 @@ public:
virtual bool OnCraftingNoRecipe (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason);
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username);
virtual bool OnKilled (cPawn & a_Killed, cEntity * a_Killer);
virtual bool OnKilling (cPawn & a_Victim, cEntity * a_Killer);
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
virtual bool OnPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);

View File

@ -407,16 +407,16 @@ bool cPluginManager::CallHookHandshake(cClientHandle * a_ClientHandle, const ASt
bool cPluginManager::CallHookKilled(cPawn & a_Victim, cEntity * a_Killer)
bool cPluginManager::CallHookKilling(cPawn & a_Victim, cEntity * a_Killer)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_KILLED);
HookMap::iterator Plugins = m_Hooks.find(HOOK_KILLING);
if (Plugins == m_Hooks.end())
{
return false;
}
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
if ((*itr)->OnKilled(a_Victim, a_Killer))
if ((*itr)->OnKilling(a_Victim, a_Killer))
{
return true;
}

View File

@ -54,7 +54,7 @@ public: // tolua_export
HOOK_CRAFTING_NO_RECIPE,
HOOK_DISCONNECT,
HOOK_HANDSHAKE,
HOOK_KILLED,
HOOK_KILLING,
HOOK_LOGIN,
HOOK_PLAYER_BREAKING_BLOCK,
HOOK_PLAYER_BROKEN_BLOCK,
@ -106,7 +106,7 @@ public: // tolua_export
bool CallHookCraftingNoRecipe (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookDisconnect (cPlayer * a_Player, const AString & a_Reason);
bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username);
bool CallHookKilled (cPawn & a_Victim, cEntity * a_Killer);
bool CallHookKilling (cPawn & a_Victim, cEntity * a_Killer);
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
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);

View File

@ -14,26 +14,23 @@ extern "C"
#include "Bindings.h"
#include "ManualBindings.h"
#ifdef _WIN32
// #include "wdirent.h"
#else
#include <dirent.h>
#endif
extern bool report_errors(lua_State * lua, int status);
extern bool report_errors(lua_State* lua, int status);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// cPlugin_NewLua:
cPlugin_NewLua::cPlugin_NewLua( const AString & a_PluginDirectory )
cPlugin_NewLua::cPlugin_NewLua(const AString & a_PluginDirectory)
: m_LuaState( 0 )
, cWebPlugin()
, cPlugin( a_PluginDirectory )
, cPlugin(a_PluginDirectory)
{
}
@ -389,17 +386,17 @@ bool cPlugin_NewLua::OnHandshake(cClientHandle * a_Client, const AString & a_Use
bool cPlugin_NewLua::OnKilled(cPawn & a_Killed, cEntity * a_Killer)
bool cPlugin_NewLua::OnKilling(cPawn & a_Victim, cEntity * a_Killer)
{
cCSLock Lock(m_CriticalSection);
const char * FnName = GetHookFnName(cPluginManager::HOOK_KILLED);
const char * FnName = GetHookFnName(cPluginManager::HOOK_KILLING);
ASSERT(FnName != NULL);
if (!PushFunction(FnName))
{
return false;
}
tolua_pushusertype(m_LuaState, &a_Killed, "cPawn");
tolua_pushusertype(m_LuaState, &a_Victim, "cPawn");
tolua_pushusertype(m_LuaState, a_Killer, "cEntity");
if (!CallFunction(2, 1, FnName))
@ -1194,7 +1191,7 @@ const char * cPlugin_NewLua::GetHookFnName(cPluginManager::PluginHook a_Hook)
case cPluginManager::HOOK_CRAFTING_NO_RECIPE: return "OnCraftingNoRecipe";
case cPluginManager::HOOK_DISCONNECT: return "OnDisconnect";
case cPluginManager::HOOK_HANDSHAKE: return "OnHandshake";
case cPluginManager::HOOK_KILLED: return "OnKilled";
case cPluginManager::HOOK_KILLING: return "OnKilling";
case cPluginManager::HOOK_LOGIN: return "OnLogin";
case cPluginManager::HOOK_PLAYER_BREAKING_BLOCK: return "OnPlayerBreakingBlock";
case cPluginManager::HOOK_PLAYER_BROKEN_BLOCK: return "OnPlayerBrokenBlock";

View File

@ -38,7 +38,7 @@ public:
virtual bool OnCraftingNoRecipe (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason) override;
virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username) override;
virtual bool OnKilled (cPawn & a_Killed, cEntity * a_Killer) override;
virtual bool OnKilling (cPawn & a_Victim, cEntity * a_Killer) override;
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) 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;