2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-09 09:15:56 -04:00
|
|
|
// PluginLua.cpp
|
|
|
|
|
|
|
|
// Implements the cPluginLua class representing a plugin written in Lua
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
2014-03-25 13:15:05 -04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#define LUA_USE_MACOSX
|
|
|
|
#else
|
2012-06-14 09:06:06 -04:00
|
|
|
#define LUA_USE_POSIX
|
2014-03-25 13:15:05 -04:00
|
|
|
#endif
|
2013-08-09 09:15:56 -04:00
|
|
|
#include "PluginLua.h"
|
2013-12-08 06:17:54 -05:00
|
|
|
#include "../CommandOutput.h"
|
2014-09-26 11:26:03 -04:00
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "../Item.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
{
|
2014-09-26 11:26:03 -04:00
|
|
|
#include "lua/src/lauxlib.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2014-03-25 13:15:05 -04:00
|
|
|
#undef TOLUA_TEMPLATE_BIND
|
2013-12-08 12:24:56 -05:00
|
|
|
#include "tolua++/include/tolua++.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:15:34 -04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2013-08-19 03:39:18 -04:00
|
|
|
// cPluginLua:
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
cPluginLua::cPluginLua(const AString & a_PluginDirectory) :
|
2013-08-04 17:11:25 -04:00
|
|
|
cPlugin(a_PluginDirectory),
|
2013-08-07 08:33:16 -04:00
|
|
|
m_LuaState(Printf("plugin %s", a_PluginDirectory.c_str()))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
cPluginLua::~cPluginLua()
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-21 15:29:30 -04:00
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPluginLua::Close(void)
|
|
|
|
{
|
2013-08-20 14:42:43 -04:00
|
|
|
if (m_LuaState.IsValid())
|
|
|
|
{
|
2013-08-21 15:29:30 -04:00
|
|
|
// Release all the references in the hook map:
|
|
|
|
for (cHookMap::iterator itrH = m_HookMap.begin(), endH = m_HookMap.end(); itrH != endH; ++itrH)
|
|
|
|
{
|
|
|
|
for (cLuaRefs::iterator itrR = itrH->second.begin(), endR = itrH->second.end(); itrR != endR; ++itrR)
|
|
|
|
{
|
|
|
|
delete *itrR;
|
|
|
|
} // for itrR - itrH->second[]
|
|
|
|
} // for itrH - m_HookMap[]
|
|
|
|
m_HookMap.clear();
|
|
|
|
|
2013-08-20 14:42:43 -04:00
|
|
|
m_LuaState.Close();
|
|
|
|
}
|
2013-08-21 15:29:30 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ASSERT(m_HookMap.empty());
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::Initialize(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-04 17:11:25 -04:00
|
|
|
if (!m_LuaState.IsValid())
|
2014-07-17 16:50:58 -04:00
|
|
|
{
|
2013-08-04 17:11:25 -04:00
|
|
|
m_LuaState.Create();
|
2014-03-12 08:05:28 -04:00
|
|
|
m_LuaState.RegisterAPILibs();
|
2013-02-01 14:55:42 -05:00
|
|
|
|
|
|
|
// Inject the identification global variables into the state:
|
|
|
|
lua_pushlightuserdata(m_LuaState, this);
|
|
|
|
lua_setglobal(m_LuaState, LUA_PLUGIN_INSTANCE_VAR_NAME);
|
|
|
|
lua_pushstring(m_LuaState, GetName().c_str());
|
|
|
|
lua_setglobal(m_LuaState, LUA_PLUGIN_NAME_VAR_NAME);
|
2013-09-18 16:31:44 -04:00
|
|
|
|
2014-02-17 17:12:46 -05:00
|
|
|
// Add the plugin's folder to the package.path and package.cpath variables (#693):
|
|
|
|
m_LuaState.AddPackagePath("path", FILE_IO_PREFIX + GetLocalFolder() + "/?.lua");
|
|
|
|
#ifdef _WIN32
|
|
|
|
m_LuaState.AddPackagePath("cpath", GetLocalFolder() + "\\?.dll");
|
|
|
|
#else
|
|
|
|
m_LuaState.AddPackagePath("cpath", FILE_IO_PREFIX + GetLocalFolder() + "/?.so");
|
|
|
|
#endif
|
|
|
|
|
2013-09-18 16:31:44 -04:00
|
|
|
tolua_pushusertype(m_LuaState, this, "cPluginLua");
|
|
|
|
lua_setglobal(m_LuaState, "g_Plugin");
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
2013-11-22 14:11:24 -05:00
|
|
|
std::string PluginPath = FILE_IO_PREFIX + GetLocalFolder() + "/";
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2014-01-29 11:47:32 -05:00
|
|
|
// List all Lua files for this plugin. Info.lua has a special handling - make it the last to load:
|
2013-11-22 14:11:24 -05:00
|
|
|
AStringVector Files = cFile::GetFolderContents(PluginPath.c_str());
|
2014-01-29 11:47:32 -05:00
|
|
|
AStringVector LuaFiles;
|
|
|
|
bool HasInfoLua = false;
|
|
|
|
for (AStringVector::const_iterator itr = Files.begin(), end = Files.end(); itr != end; ++itr)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-01-29 11:47:32 -05:00
|
|
|
if (itr->rfind(".lua") != AString::npos)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2014-01-29 11:47:32 -05:00
|
|
|
if (*itr == "Info.lua")
|
|
|
|
{
|
|
|
|
HasInfoLua = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LuaFiles.push_back(*itr);
|
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2014-01-29 11:47:32 -05:00
|
|
|
}
|
|
|
|
std::sort(LuaFiles.begin(), LuaFiles.end());
|
|
|
|
|
|
|
|
// Warn if there are no Lua files in the plugin folder:
|
|
|
|
if (LuaFiles.empty())
|
|
|
|
{
|
|
|
|
LOGWARNING("No lua files found: plugin %s is missing.", GetName().c_str());
|
|
|
|
Close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load all files in the list, including the Info.lua as last, if it exists:
|
|
|
|
for (AStringVector::const_iterator itr = LuaFiles.begin(), end = LuaFiles.end(); itr != end; ++itr)
|
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
AString Path = PluginPath + *itr;
|
2013-08-04 17:11:25 -04:00
|
|
|
if (!m_LuaState.LoadFile(Path))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-08-21 15:29:30 -04:00
|
|
|
Close();
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} // for itr - Files[]
|
2014-01-29 11:47:32 -05:00
|
|
|
if (HasInfoLua)
|
2014-01-07 14:47:15 -05:00
|
|
|
{
|
2014-01-29 11:47:32 -05:00
|
|
|
AString Path = PluginPath + "Info.lua";
|
|
|
|
if (!m_LuaState.LoadFile(Path))
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
return false;
|
|
|
|
}
|
2014-01-07 14:47:15 -05:00
|
|
|
}
|
|
|
|
|
2014-01-29 11:47:32 -05:00
|
|
|
// Call the Initialize function:
|
2013-08-08 10:02:07 -04:00
|
|
|
bool res = false;
|
|
|
|
if (!m_LuaState.Call("Initialize", this, cLuaState::Return, res))
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-08-08 10:02:07 -04:00
|
|
|
LOGWARNING("Error in plugin %s: Cannot call the Initialize() function. Plugin is temporarily disabled.", GetName().c_str());
|
2013-08-21 15:29:30 -04:00
|
|
|
Close();
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
2013-08-08 10:02:07 -04:00
|
|
|
if (!res)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-08-08 10:02:07 -04:00
|
|
|
LOGINFO("Plugin %s: Initialize() call failed, plugin is temporarily disabled.", GetName().c_str());
|
2013-08-21 15:29:30 -04:00
|
|
|
Close();
|
2012-06-14 09:06:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-08 10:02:07 -04:00
|
|
|
return true;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
void cPluginLua::OnDisable(void)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 10:02:07 -04:00
|
|
|
if (!m_LuaState.HasFunction("OnDisable"))
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
2012-06-14 09:06:06 -04:00
|
|
|
return;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
2013-08-08 10:02:07 -04:00
|
|
|
m_LuaState.Call("OnDisable");
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
void cPluginLua::Tick(float a_Dt)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_TICK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), a_Dt);
|
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnBlockSpread(cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source)
|
2014-03-16 09:38:41 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_BLOCK_SPREAD];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source, cLuaState::Return, res);
|
2014-03-16 09:38:41 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnBlockToPickups(cWorld & a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups)
|
2013-01-26 21:00:33 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_BLOCK_TO_PICKUPS];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, &a_Pickups, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-26 21:00:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnChat(cPlayer & a_Player, AString & a_Message)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_CHAT];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_Message, cLuaState::Return, res, a_Message);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnChunkAvailable(cWorld & a_World, int a_ChunkX, int a_ChunkZ)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_CHUNK_AVAILABLE];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_ChunkX, a_ChunkZ, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnChunkGenerated(cWorld & a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc)
|
2013-02-05 14:57:22 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_CHUNK_GENERATED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-02-05 14:57:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnChunkGenerating(cWorld & a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_CHUNK_GENERATING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnChunkUnloaded(cWorld & a_World, int a_ChunkX, int a_ChunkZ)
|
2013-02-05 14:57:22 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_CHUNK_UNLOADED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_ChunkX, a_ChunkZ, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-02-05 14:57:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnChunkUnloading(cWorld & a_World, int a_ChunkX, int a_ChunkZ)
|
2013-02-05 14:57:22 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_CHUNK_UNLOADING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_ChunkX, a_ChunkZ, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-08 08:08:21 -04:00
|
|
|
}
|
2013-02-05 14:57:22 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnCollectingPickup(cPlayer & a_Player, cPickup & a_Pickup)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-24 05:49:00 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_COLLECTING_PICKUP];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, &a_Pickup, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-12-04 03:21:57 -05:00
|
|
|
bool cPluginLua::OnCraftingNoRecipe(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_CRAFTING_NO_RECIPE];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, &a_Grid, &a_Recipe, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-02 05:18:02 -04:00
|
|
|
bool cPluginLua::OnDisconnect(cClientHandle & a_Client, const AString & a_Reason)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-19 15:42:32 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_DISCONNECT];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-05-02 05:18:02 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Client, a_Reason, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-11 20:27:29 -04:00
|
|
|
bool cPluginLua::OnEntityAddEffect(cEntity & a_Entity, int a_EffectType, int a_EffectDurationTicks, int a_EffectIntensity, double a_DistanceModifier)
|
2014-06-13 06:47:01 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_ENTITY_ADD_EFFECT];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-07-11 20:27:29 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Entity, a_EffectType, a_EffectDurationTicks, a_EffectIntensity, a_DistanceModifier, cLuaState::Return, res);
|
2014-06-13 06:47:01 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnExecuteCommand(cPlayer * a_Player, const AStringVector & a_Split)
|
2013-02-21 08:47:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_EXECUTE_COMMAND];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), a_Player, a_Split, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-02-21 08:47:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnExploded(cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_EXPLODED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-08-21 15:29:30 -04:00
|
|
|
switch (a_Source)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
case esOther: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break;
|
|
|
|
case esPrimedTNT: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, (cTNTEntity *)a_SourceData, cLuaState::Return, res); break;
|
|
|
|
case esMonster: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, (cMonster *)a_SourceData, cLuaState::Return, res); break;
|
|
|
|
case esBed: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, (Vector3i *)a_SourceData, cLuaState::Return, res); break;
|
|
|
|
case esEnderCrystal: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, (Vector3i *)a_SourceData, cLuaState::Return, res); break;
|
|
|
|
case esGhastFireball: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break;
|
2013-08-21 15:29:30 -04:00
|
|
|
case esWitherSkullBlack:
|
|
|
|
case esWitherSkullBlue: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break;
|
|
|
|
case esWitherBirth: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break;
|
|
|
|
case esPlugin: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res); break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled ExplosionSource");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
}
|
|
|
|
}
|
2013-08-21 15:29:30 -04:00
|
|
|
return false;
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnExploding(cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_EXPLODING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-08-21 15:29:30 -04:00
|
|
|
switch (a_Source)
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
{
|
2013-08-21 15:29:30 -04:00
|
|
|
case esOther: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
|
|
|
|
case esPrimedTNT: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, (cTNTEntity *)a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
|
2014-01-13 11:25:16 -05:00
|
|
|
case esMonster: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, (cMonster *)a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
|
2013-08-21 15:29:30 -04:00
|
|
|
case esBed: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, (Vector3i *)a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
|
|
|
|
case esEnderCrystal: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, (Vector3i *)a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
|
|
|
|
case esGhastFireball: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
|
|
|
|
case esWitherSkullBlack:
|
|
|
|
case esWitherSkullBlue: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
|
|
|
|
case esWitherBirth: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
|
|
|
|
case esPlugin: m_LuaState.Call((int)(**itr), &a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData, cLuaState::Return, res, a_CanCauseFire, a_ExplosionSize); break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
ASSERT(!"Unhandled ExplosionSource");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
}
|
|
|
|
}
|
2013-08-21 15:29:30 -04:00
|
|
|
return false;
|
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnHandshake(cClientHandle & a_Client, const AString & a_Username)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 05:56:28 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_HANDSHAKE];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Client, a_Username, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnHopperPullingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum)
|
2013-08-11 08:57:07 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_HOPPER_PULLING_ITEM];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_World, &a_Hopper, a_DstSlotNum, &a_SrcEntity, a_SrcSlotNum, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-11 08:57:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnHopperPushingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum)
|
2013-08-11 08:57:07 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_HOPPER_PUSHING_ITEM];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_World, &a_Hopper, a_SrcSlotNum, &a_DstEntity, a_DstSlotNum, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-11 08:57:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-16 06:38:52 -04:00
|
|
|
bool cPluginLua::OnKilling(cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_KILLING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-07-16 06:38:52 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Victim, a_Killer, &a_TDI, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnLogin(cClientHandle & a_Client, int a_ProtocolVersion, const AString & a_Username)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_LOGIN];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Client, a_ProtocolVersion, a_Username, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-18 11:11:15 -05:00
|
|
|
bool cPluginLua::OnPlayerAnimation(cPlayer & a_Player, int a_Animation)
|
2013-08-11 06:12:20 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
2013-12-18 11:11:15 -05:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_ANIMATION];
|
2013-08-21 15:29:30 -04:00
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2013-12-18 11:11:15 -05:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_Animation, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-11 06:12:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_BREAKING_BLOCK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 05:56:28 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_BROKEN_BLOCK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-25 05:25:22 -05:00
|
|
|
bool cPluginLua::OnPlayerDestroyed(cPlayer & a_Player)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_DESTROYED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerEating(cPlayer & a_Player)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-18 06:38:15 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_EATING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-02 08:46:00 -04:00
|
|
|
bool cPluginLua::OnPlayerFoodLevelChange(cPlayer & a_Player, int a_NewFoodLevel)
|
2014-06-30 09:12:56 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FOOD_LEVEL_CHANGE];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-07-02 08:46:00 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_NewFoodLevel, cLuaState::Return, res);
|
2014-06-30 09:12:56 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-31 08:53:10 -05:00
|
|
|
bool cPluginLua::OnPlayerFished(cPlayer & a_Player, const cItems & a_Reward)
|
2013-12-30 16:56:08 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2013-12-31 08:53:10 -05:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_Reward, cLuaState::Return, res);
|
2013-12-30 16:56:08 -05:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-01 09:09:53 -05:00
|
|
|
bool cPluginLua::OnPlayerFishing(cPlayer & a_Player, cItems & a_Reward)
|
2013-12-30 16:56:08 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, &a_Reward, cLuaState::Return, res);
|
2013-12-30 16:56:08 -05:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerJoined(cPlayer & a_Player)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_JOINED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_LEFT_CLICK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-22 04:33:53 -04:00
|
|
|
bool cPluginLua::OnPlayerMoving(cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_MOVING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-08-21 15:37:52 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_OldPosition, a_NewPosition, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-12-24 01:20:17 -05:00
|
|
|
bool cPluginLua::OnPlayerPlacedBlock(cPlayer & a_Player, const sSetBlock & a_BlockChange)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_PLACED_BLOCK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-12-24 01:20:17 -05:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player,
|
|
|
|
a_BlockChange.GetX(), a_BlockChange.GetY(), a_BlockChange.GetZ(),
|
|
|
|
a_BlockChange.m_BlockType, a_BlockChange.m_BlockMeta,
|
|
|
|
cLuaState::Return,
|
|
|
|
res
|
|
|
|
);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-08 08:08:21 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2013-01-11 23:46:01 -05:00
|
|
|
|
2013-08-08 08:08:21 -04:00
|
|
|
|
|
|
|
|
2014-12-24 01:20:17 -05:00
|
|
|
bool cPluginLua::OnPlayerPlacingBlock(cPlayer & a_Player, const sSetBlock & a_BlockChange)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_PLACING_BLOCK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-12-24 01:20:17 -05:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player,
|
|
|
|
a_BlockChange.GetX(), a_BlockChange.GetY(), a_BlockChange.GetZ(),
|
|
|
|
a_BlockChange.m_BlockType, a_BlockChange.m_BlockMeta,
|
|
|
|
cLuaState::Return,
|
|
|
|
res
|
|
|
|
);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
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)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-12-21 06:04:08 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_RIGHT_CLICK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-08 08:08:21 -04:00
|
|
|
}
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
2012-12-21 06:04:08 -05:00
|
|
|
|
2013-08-08 08:08:21 -04:00
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity)
|
2013-08-08 08:08:21 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, &a_Entity, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerShooting(cPlayer & a_Player)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_SHOOTING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerSpawned(cPlayer & a_Player)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_SPAWNED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerTossingItem(cPlayer & a_Player)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_TOSSING_ITEM];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerUsedBlock(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)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_USED_BLOCK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-17 16:50:58 -04:00
|
|
|
bool cPluginLua::OnPlayerUsedItem(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_USED_ITEM];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerUsingBlock(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)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_USING_BLOCK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnPlayerUsingItem(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_USING_ITEM];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-01-11 23:46:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-07 11:47:05 -05:00
|
|
|
bool cPluginLua::OnPluginMessage(cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLUGIN_MESSAGE];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-04-27 15:37:08 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Client, a_Channel, a_Message, cLuaState::Return, res);
|
2014-01-07 11:47:05 -05:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-29 06:51:58 -05:00
|
|
|
bool cPluginLua::OnPluginsLoaded(void)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLUGINS_LOADED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
m_LuaState.Call((int)(**itr), cLuaState::Return, ret);
|
|
|
|
res = res || ret;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnPostCrafting(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_POST_CRAFTING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, &a_Grid, &a_Recipe, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::OnPreCrafting(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PRE_CRAFTING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Player, &a_Grid, &a_Recipe, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-01 08:06:47 -04:00
|
|
|
bool cPluginLua::OnProjectileHitBlock(cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos)
|
2014-03-29 11:00:45 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PROJECTILE_HIT_BLOCK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-06-03 13:29:04 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_Projectile, a_BlockX, a_BlockY, a_BlockZ, a_Face, a_BlockHitPos, cLuaState::Return, res);
|
2014-03-29 11:00:45 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-29 10:26:41 -04:00
|
|
|
bool cPluginLua::OnProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PROJECTILE_HIT_ENTITY];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Projectile, &a_HitEntity, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-20 16:22:38 -04:00
|
|
|
bool cPluginLua::OnServerPing(cClientHandle & a_ClientHandle, AString & a_ServerDescription, int & a_OnlinePlayersCount, int & a_MaxPlayersCount, AString & a_Favicon)
|
2014-08-16 12:02:16 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
bool res = false;
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_SERVER_PING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-08-20 16:22:38 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_ClientHandle, a_ServerDescription, a_OnlinePlayersCount, a_MaxPlayersCount, a_Favicon, cLuaState::Return, res, a_ServerDescription, a_OnlinePlayersCount, a_MaxPlayersCount, a_Favicon);
|
2014-08-16 12:02:16 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
|
2013-08-08 03:13:13 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_SPAWNED_ENTITY];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_World, &a_Entity, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-08 03:13:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnSpawnedMonster(cWorld & a_World, cMonster & a_Monster)
|
2013-08-08 03:13:13 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_SPAWNED_MONSTER];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_World, &a_Monster, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-08 03:13:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnSpawningEntity(cWorld & a_World, cEntity & a_Entity)
|
2013-08-08 03:13:13 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_SPAWNING_ENTITY];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_World, &a_Entity, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-08 03:13:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnSpawningMonster(cWorld & a_World, cMonster & a_Monster)
|
2013-08-08 03:13:13 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_SPAWNING_MONSTER];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_World, &a_Monster, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-08-08 03:13:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnTakeDamage(cEntity & a_Receiver, TakeDamageInfo & a_TDI)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_TAKE_DAMAGE];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_Receiver, &a_TDI, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnUpdatedSign(
|
2014-10-15 13:01:55 -04:00
|
|
|
cWorld & a_World,
|
2014-07-17 16:50:58 -04:00
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ,
|
2013-01-11 23:46:01 -05:00
|
|
|
const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4,
|
|
|
|
cPlayer * a_Player
|
|
|
|
)
|
2012-06-14 15:20:31 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_UPDATED_SIGN];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player, cLuaState::Return, res);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-14 15:20:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnUpdatingSign(
|
2014-10-15 13:01:55 -04:00
|
|
|
cWorld & a_World,
|
2014-07-17 16:50:58 -04:00
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ,
|
2012-09-01 17:31:20 -04:00
|
|
|
AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4,
|
|
|
|
cPlayer * a_Player
|
2012-06-16 11:06:14 -04:00
|
|
|
)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_UPDATING_SIGN];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player, cLuaState::Return, res, a_Line1, a_Line2, a_Line3, a_Line4);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-16 11:06:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnWeatherChanged(cWorld & a_World)
|
2012-06-16 11:06:14 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_WEATHER_CHANGED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_World, cLuaState::Return, res);
|
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-16 11:06:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::OnWeatherChanging(cWorld & a_World, eWeather & a_NewWeather)
|
2013-02-13 14:22:08 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 08:08:21 -04:00
|
|
|
bool res = false;
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_WEATHER_CHANGING];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2014-07-03 11:49:21 -04:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_NewWeather, cLuaState::Return, res, a_NewWeather);
|
2013-08-21 15:29:30 -04:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2013-02-13 14:22:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-11 06:39:13 -05:00
|
|
|
bool cPluginLua::OnWorldStarted(cWorld & a_World)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_WORLD_STARTED];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_LuaState.Call((int)(**itr), &a_World);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-01-11 16:12:26 -05:00
|
|
|
bool cPluginLua::OnWorldTick(cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec)
|
2013-08-19 03:28:22 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-21 15:29:30 -04:00
|
|
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_WORLD_TICK];
|
|
|
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
|
|
|
{
|
2013-11-30 08:22:26 -05:00
|
|
|
m_LuaState.Call((int)(**itr), &a_World, a_Dt, a_LastTickDurationMSec);
|
2013-08-21 15:29:30 -04:00
|
|
|
}
|
2013-08-19 03:28:22 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-10-15 13:01:55 -04:00
|
|
|
bool cPluginLua::HandleCommand(const AStringVector & a_Split, cPlayer & a_Player)
|
2013-02-01 14:55:42 -05:00
|
|
|
{
|
|
|
|
ASSERT(!a_Split.empty());
|
|
|
|
CommandMap::iterator cmd = m_Commands.find(a_Split[0]);
|
|
|
|
if (cmd == m_Commands.end())
|
|
|
|
{
|
2013-02-15 08:00:59 -05:00
|
|
|
LOGWARNING("Command handler is registered in cPluginManager but not in cPlugin, wtf? Command \"%s\".", a_Split[0].c_str());
|
2013-02-01 14:55:42 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 10:02:07 -04:00
|
|
|
bool res = false;
|
2014-10-15 13:01:55 -04:00
|
|
|
m_LuaState.Call(cmd->second, a_Split, &a_Player, cLuaState::Return, res);
|
2013-08-08 10:02:07 -04:00
|
|
|
return res;
|
2013-02-01 14:55:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::HandleConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output)
|
2013-02-15 08:00:59 -05:00
|
|
|
{
|
|
|
|
ASSERT(!a_Split.empty());
|
|
|
|
CommandMap::iterator cmd = m_ConsoleCommands.find(a_Split[0]);
|
|
|
|
if (cmd == m_ConsoleCommands.end())
|
|
|
|
{
|
2013-06-29 11:30:05 -04:00
|
|
|
LOGWARNING("Console command handler is registered in cPluginManager but not in cPlugin, wtf? Console command \"%s\", plugin \"%s\".",
|
|
|
|
a_Split[0].c_str(), GetName().c_str()
|
|
|
|
);
|
2013-02-15 08:00:59 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 10:02:07 -04:00
|
|
|
bool res = false;
|
|
|
|
AString str;
|
|
|
|
m_LuaState.Call(cmd->second, a_Split, cLuaState::Return, res, str);
|
|
|
|
if (res && !str.empty())
|
2013-06-29 11:30:05 -04:00
|
|
|
{
|
|
|
|
a_Output.Out(str);
|
|
|
|
}
|
2013-08-08 10:02:07 -04:00
|
|
|
return res;
|
2013-02-15 08:00:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
void cPluginLua::ClearCommands(void)
|
2013-02-01 14:55:42 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
|
|
|
|
// Unreference the bound functions so that Lua can GC them
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_LuaState != nullptr)
|
2013-02-01 14:55:42 -05:00
|
|
|
{
|
|
|
|
for (CommandMap::iterator itr = m_Commands.begin(), end = m_Commands.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
luaL_unref(m_LuaState, LUA_REGISTRYINDEX, itr->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_Commands.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
void cPluginLua::ClearConsoleCommands(void)
|
2013-02-15 08:00:59 -05:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
|
|
|
|
// Unreference the bound functions so that Lua can GC them
|
2014-10-20 16:55:07 -04:00
|
|
|
if (m_LuaState != nullptr)
|
2013-02-15 08:00:59 -05:00
|
|
|
{
|
|
|
|
for (CommandMap::iterator itr = m_ConsoleCommands.begin(), end = m_ConsoleCommands.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
luaL_unref(m_LuaState, LUA_REGISTRYINDEX, itr->second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_ConsoleCommands.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-22 15:03:20 -04:00
|
|
|
bool cPluginLua::CanAddOldStyleHook(int a_HookType)
|
2012-09-05 16:30:27 -04:00
|
|
|
{
|
2013-08-22 15:03:20 -04:00
|
|
|
const char * FnName = GetHookFnName(a_HookType);
|
2014-10-20 16:55:07 -04:00
|
|
|
if (FnName == nullptr)
|
2012-09-05 16:30:27 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
// Unknown hook ID
|
2013-08-22 15:03:20 -04:00
|
|
|
LOGWARNING("Plugin %s wants to add an unknown hook ID (%d). The plugin need not work properly.",
|
|
|
|
GetName().c_str(), a_HookType
|
|
|
|
);
|
|
|
|
m_LuaState.LogStackTrace();
|
2012-09-05 16:30:27 -04:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
|
|
|
|
// Check if the function is available
|
2013-08-08 10:02:07 -04:00
|
|
|
if (m_LuaState.HasFunction(FnName))
|
2012-09-05 16:30:27 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
return true;
|
2012-09-05 16:30:27 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
|
2014-07-17 16:50:58 -04:00
|
|
|
LOGWARNING("Plugin %s wants to add a hook (%d), but it doesn't provide the callback function \"%s\" for it. The plugin need not work properly.",
|
2013-08-22 15:03:20 -04:00
|
|
|
GetName().c_str(), a_HookType, FnName
|
2013-01-11 23:46:01 -05:00
|
|
|
);
|
2013-08-21 15:29:30 -04:00
|
|
|
m_LuaState.LogStackTrace();
|
2013-01-11 23:46:01 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-22 15:03:20 -04:00
|
|
|
const char * cPluginLua::GetHookFnName(int a_HookType)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
2013-08-22 15:03:20 -04:00
|
|
|
switch (a_HookType)
|
2013-01-11 23:46:01 -05:00
|
|
|
{
|
2014-03-16 09:38:41 -04:00
|
|
|
case cPluginManager::HOOK_BLOCK_SPREAD: return "OnBlockSpread";
|
2013-08-02 02:44:06 -04:00
|
|
|
case cPluginManager::HOOK_BLOCK_TO_PICKUPS: return "OnBlockToPickups";
|
|
|
|
case cPluginManager::HOOK_CHAT: return "OnChat";
|
|
|
|
case cPluginManager::HOOK_CHUNK_AVAILABLE: return "OnChunkAvailable";
|
|
|
|
case cPluginManager::HOOK_CHUNK_GENERATED: return "OnChunkGenerated";
|
|
|
|
case cPluginManager::HOOK_CHUNK_GENERATING: return "OnChunkGenerating";
|
|
|
|
case cPluginManager::HOOK_CHUNK_UNLOADED: return "OnChunkUnloaded";
|
|
|
|
case cPluginManager::HOOK_CHUNK_UNLOADING: return "OnChunkUnloading";
|
|
|
|
case cPluginManager::HOOK_COLLECTING_PICKUP: return "OnCollectingPickup";
|
|
|
|
case cPluginManager::HOOK_CRAFTING_NO_RECIPE: return "OnCraftingNoRecipe";
|
|
|
|
case cPluginManager::HOOK_DISCONNECT: return "OnDisconnect";
|
2013-12-18 11:11:15 -05:00
|
|
|
case cPluginManager::HOOK_PLAYER_ANIMATION: return "OnPlayerAnimation";
|
2014-06-13 06:47:01 -04:00
|
|
|
case cPluginManager::HOOK_ENTITY_ADD_EFFECT: return "OnEntityAddEffect";
|
2013-08-02 02:44:06 -04:00
|
|
|
case cPluginManager::HOOK_EXECUTE_COMMAND: return "OnExecuteCommand";
|
|
|
|
case cPluginManager::HOOK_HANDSHAKE: return "OnHandshake";
|
|
|
|
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";
|
|
|
|
case cPluginManager::HOOK_PLAYER_EATING: return "OnPlayerEating";
|
|
|
|
case cPluginManager::HOOK_PLAYER_JOINED: return "OnPlayerJoined";
|
|
|
|
case cPluginManager::HOOK_PLAYER_LEFT_CLICK: return "OnPlayerLeftClick";
|
|
|
|
case cPluginManager::HOOK_PLAYER_MOVING: return "OnPlayerMoving";
|
|
|
|
case cPluginManager::HOOK_PLAYER_PLACED_BLOCK: return "OnPlayerPlacedBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_PLACING_BLOCK: return "OnPlayerPlacingBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_RIGHT_CLICK: return "OnPlayerRightClick";
|
|
|
|
case cPluginManager::HOOK_PLAYER_RIGHT_CLICKING_ENTITY: return "OnPlayerRightClickingEntity";
|
|
|
|
case cPluginManager::HOOK_PLAYER_SHOOTING: return "OnPlayerShooting";
|
|
|
|
case cPluginManager::HOOK_PLAYER_SPAWNED: return "OnPlayerSpawned";
|
|
|
|
case cPluginManager::HOOK_PLAYER_TOSSING_ITEM: return "OnPlayerTossingItem";
|
|
|
|
case cPluginManager::HOOK_PLAYER_USED_BLOCK: return "OnPlayerUsedBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_USED_ITEM: return "OnPlayerUsedItem";
|
|
|
|
case cPluginManager::HOOK_PLAYER_USING_BLOCK: return "OnPlayerUsingBlock";
|
|
|
|
case cPluginManager::HOOK_PLAYER_USING_ITEM: return "OnPlayerUsingItem";
|
2014-01-07 11:47:05 -05:00
|
|
|
case cPluginManager::HOOK_PLUGIN_MESSAGE: return "OnPluginMessage";
|
|
|
|
case cPluginManager::HOOK_PLUGINS_LOADED: return "OnPluginsLoaded";
|
2013-08-02 02:44:06 -04:00
|
|
|
case cPluginManager::HOOK_POST_CRAFTING: return "OnPostCrafting";
|
|
|
|
case cPluginManager::HOOK_PRE_CRAFTING: return "OnPreCrafting";
|
2014-08-20 16:19:50 -04:00
|
|
|
case cPluginManager::HOOK_SERVER_PING: return "OnServerPing";
|
2013-08-08 03:13:13 -04:00
|
|
|
case cPluginManager::HOOK_SPAWNED_ENTITY: return "OnSpawnedEntity";
|
|
|
|
case cPluginManager::HOOK_SPAWNED_MONSTER: return "OnSpawnedMonster";
|
|
|
|
case cPluginManager::HOOK_SPAWNING_ENTITY: return "OnSpawningEntity";
|
|
|
|
case cPluginManager::HOOK_SPAWNING_MONSTER: return "OnSpawningMonster";
|
2013-08-02 02:44:06 -04:00
|
|
|
case cPluginManager::HOOK_TAKE_DAMAGE: return "OnTakeDamage";
|
|
|
|
case cPluginManager::HOOK_TICK: return "OnTick";
|
|
|
|
case cPluginManager::HOOK_UPDATED_SIGN: return "OnUpdatedSign";
|
|
|
|
case cPluginManager::HOOK_UPDATING_SIGN: return "OnUpdatingSign";
|
|
|
|
case cPluginManager::HOOK_WEATHER_CHANGED: return "OnWeatherChanged";
|
|
|
|
case cPluginManager::HOOK_WEATHER_CHANGING: return "OnWeatherChanging";
|
2013-08-19 03:28:22 -04:00
|
|
|
case cPluginManager::HOOK_WORLD_TICK: return "OnWorldTick";
|
2014-01-07 11:47:05 -05:00
|
|
|
|
|
|
|
case cPluginManager::HOOK_NUM_HOOKS:
|
|
|
|
{
|
|
|
|
// Satisfy a warning that all enum values should be used in a switch
|
|
|
|
// but don't want a default branch, so that we catch new hooks missing from this list.
|
|
|
|
break;
|
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
} // switch (a_Hook)
|
2014-01-07 11:47:05 -05:00
|
|
|
LOGWARNING("Requested name of an unknown hook type function: %d (max is %d)", a_HookType, cPluginManager::HOOK_MAX);
|
|
|
|
ASSERT(!"Unknown hook requested!");
|
2014-10-20 16:55:07 -04:00
|
|
|
return nullptr;
|
2012-09-05 16:30:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-21 15:29:30 -04:00
|
|
|
bool cPluginLua::AddHookRef(int a_HookType, int a_FnRefIdx)
|
|
|
|
{
|
|
|
|
ASSERT(m_CriticalSection.IsLockedByCurrentThread()); // It probably has to be, how else would we have a LuaState?
|
|
|
|
|
2013-08-22 15:03:20 -04:00
|
|
|
// Check if the function reference is valid:
|
|
|
|
cLuaState::cRef * Ref = new cLuaState::cRef(m_LuaState, a_FnRefIdx);
|
2014-10-20 16:55:07 -04:00
|
|
|
if ((Ref == nullptr) || !Ref->IsValid())
|
2013-08-22 15:03:20 -04:00
|
|
|
{
|
|
|
|
LOGWARNING("Plugin %s tried to add a hook %d with bad handler function.", GetName().c_str(), a_HookType);
|
|
|
|
m_LuaState.LogStackTrace();
|
|
|
|
delete Ref;
|
2014-10-20 16:55:07 -04:00
|
|
|
Ref = nullptr;
|
2013-08-22 15:03:20 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_HookMap[a_HookType].push_back(Ref);
|
2013-08-21 15:29:30 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-01-21 16:59:08 -05:00
|
|
|
int cPluginLua::CallFunctionFromForeignState(
|
|
|
|
const AString & a_FunctionName,
|
|
|
|
cLuaState & a_ForeignState,
|
|
|
|
int a_ParamStart,
|
|
|
|
int a_ParamEnd
|
|
|
|
)
|
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
|
|
|
|
// Call the function:
|
|
|
|
int NumReturns = m_LuaState.CallFunctionWithForeignParams(a_FunctionName, a_ForeignState, a_ParamStart, a_ParamEnd);
|
|
|
|
if (NumReturns < 0)
|
|
|
|
{
|
|
|
|
// The call has failed, an error has already been output to the log, so just silently bail out with the same error
|
|
|
|
return NumReturns;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy all the return values:
|
|
|
|
int Top = lua_gettop(m_LuaState);
|
|
|
|
int res = a_ForeignState.CopyStackFrom(m_LuaState, Top - NumReturns + 1, Top);
|
|
|
|
|
|
|
|
// Remove the return values off this stack:
|
|
|
|
if (NumReturns > 0)
|
|
|
|
{
|
|
|
|
lua_pop(m_LuaState, NumReturns);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-21 09:19:48 -04:00
|
|
|
AString cPluginLua::HandleWebRequest(const HTTPRequest * a_Request)
|
2012-08-22 10:22:21 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2012-08-22 10:22:21 -04:00
|
|
|
std::string RetVal = "";
|
|
|
|
|
|
|
|
std::pair< std::string, std::string > TabName = GetTabNameForRequest(a_Request);
|
|
|
|
std::string SafeTabName = TabName.second;
|
2013-08-08 10:02:07 -04:00
|
|
|
if (SafeTabName.empty())
|
|
|
|
{
|
2012-08-22 10:22:21 -04:00
|
|
|
return "";
|
2013-08-08 10:02:07 -04:00
|
|
|
}
|
2012-08-22 10:22:21 -04:00
|
|
|
|
2013-08-08 10:02:07 -04:00
|
|
|
sWebPluginTab * Tab = 0;
|
2013-08-04 17:11:25 -04:00
|
|
|
for (TabList::iterator itr = GetTabs().begin(); itr != GetTabs().end(); ++itr)
|
2012-08-22 10:22:21 -04:00
|
|
|
{
|
2014-07-17 16:15:34 -04:00
|
|
|
if ((*itr)->SafeTitle.compare(SafeTabName) == 0) // This is the one! Rawr
|
2012-08-22 10:22:21 -04:00
|
|
|
{
|
|
|
|
Tab = *itr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (Tab != nullptr)
|
2012-08-22 10:22:21 -04:00
|
|
|
{
|
2013-08-08 10:02:07 -04:00
|
|
|
AString Contents = Printf("WARNING: WebPlugin tab '%s' did not return a string!", Tab->Title.c_str());
|
|
|
|
if (!m_LuaState.Call(Tab->UserData, a_Request, cLuaState::Return, Contents))
|
2012-08-22 10:22:21 -04:00
|
|
|
{
|
2013-08-06 02:59:54 -04:00
|
|
|
return "Lua encountered error while processing the page request";
|
2012-08-22 10:22:21 -04:00
|
|
|
}
|
|
|
|
|
2013-08-08 10:02:07 -04:00
|
|
|
RetVal += Contents;
|
2012-08-22 10:22:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return RetVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::AddWebTab(const AString & a_Title, lua_State * a_LuaState, int a_FunctionReference)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2013-01-11 23:46:01 -05:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
if (a_LuaState != m_LuaState)
|
2012-06-14 09:06:06 -04:00
|
|
|
{
|
2012-08-22 10:22:21 -04:00
|
|
|
LOGERROR("Only allowed to add a tab to a WebPlugin of your own Plugin!");
|
|
|
|
return false;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
2013-01-11 23:46:01 -05:00
|
|
|
sWebPluginTab * Tab = new sWebPluginTab();
|
2012-08-22 10:22:21 -04:00
|
|
|
Tab->Title = a_Title;
|
2013-01-11 23:46:01 -05:00
|
|
|
Tab->SafeTitle = SafeString(a_Title);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-08-22 10:22:21 -04:00
|
|
|
Tab->UserData = a_FunctionReference;
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2013-08-04 17:11:25 -04:00
|
|
|
GetTabs().push_back(Tab);
|
2012-08-22 10:22:21 -04:00
|
|
|
return true;
|
2012-06-14 09:06:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 10:22:21 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
void cPluginLua::BindCommand(const AString & a_Command, int a_FnRef)
|
2013-02-01 14:55:42 -05:00
|
|
|
{
|
|
|
|
ASSERT(m_Commands.find(a_Command) == m_Commands.end());
|
|
|
|
m_Commands[a_Command] = a_FnRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
void cPluginLua::BindConsoleCommand(const AString & a_Command, int a_FnRef)
|
2013-02-15 08:00:59 -05:00
|
|
|
{
|
|
|
|
ASSERT(m_ConsoleCommands.find(a_Command) == m_ConsoleCommands.end());
|
|
|
|
m_ConsoleCommands[a_Command] = a_FnRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
void cPluginLua::Unreference(int a_LuaRef)
|
2013-05-30 15:34:09 -04:00
|
|
|
{
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
|
|
|
luaL_unref(m_LuaState, LUA_REGISTRYINDEX, a_LuaRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
bool cPluginLua::CallbackWindowClosing(int a_FnRef, cWindow & a_Window, cPlayer & a_Player, bool a_CanRefuse)
|
2013-05-30 16:40:43 -04:00
|
|
|
{
|
2013-05-31 03:16:14 -04:00
|
|
|
ASSERT(a_FnRef != LUA_REFNIL);
|
|
|
|
|
2013-05-30 16:40:43 -04:00
|
|
|
cCSLock Lock(m_CriticalSection);
|
2014-07-01 09:46:31 -04:00
|
|
|
bool res = false;
|
2013-08-08 10:02:07 -04:00
|
|
|
m_LuaState.Call(a_FnRef, &a_Window, &a_Player, a_CanRefuse, cLuaState::Return, res);
|
|
|
|
return res;
|
2013-05-30 16:40:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-08-19 03:39:18 -04:00
|
|
|
void cPluginLua::CallbackWindowSlotChanged(int a_FnRef, cWindow & a_Window, int a_SlotNum)
|
2013-05-31 03:16:14 -04:00
|
|
|
{
|
|
|
|
ASSERT(a_FnRef != LUA_REFNIL);
|
|
|
|
|
|
|
|
cCSLock Lock(m_CriticalSection);
|
2013-08-08 10:02:07 -04:00
|
|
|
m_LuaState.Call(a_FnRef, &a_Window, a_SlotNum);
|
2013-05-31 03:16:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|