2011-10-03 11:41:19 -07:00
|
|
|
|
2012-02-13 13:47:03 -08:00
|
|
|
#pragma once
|
2011-10-03 11:41:19 -07:00
|
|
|
|
|
|
|
struct lua_State;
|
|
|
|
class cLuaCommandBinder;
|
|
|
|
class cPlugin;
|
|
|
|
class cPlugin_Lua;
|
2012-06-12 14:30:32 -07:00
|
|
|
|
|
|
|
// fwd: cPlayer.h
|
|
|
|
class cPlayer;
|
|
|
|
|
|
|
|
// fwd: CraftingRecipes.h
|
|
|
|
class cCraftingGrid;
|
|
|
|
class cCraftingRecipe;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 11:41:19 -07:00
|
|
|
class cPluginManager //tolua_export
|
|
|
|
{ //tolua_export
|
|
|
|
public: //tolua_export
|
|
|
|
|
|
|
|
// Called each tick
|
|
|
|
virtual void Tick(float a_Dt);
|
|
|
|
|
2012-06-12 14:30:32 -07:00
|
|
|
// tolua_begin
|
|
|
|
enum PluginHook
|
|
|
|
{
|
|
|
|
HOOK_TICK,
|
|
|
|
HOOK_CHAT,
|
|
|
|
HOOK_COLLECT_ITEM,
|
|
|
|
HOOK_BLOCK_DIG,
|
|
|
|
HOOK_BLOCK_PLACE,
|
|
|
|
HOOK_DISCONNECT,
|
|
|
|
HOOK_HANDSHAKE,
|
|
|
|
HOOK_LOGIN,
|
|
|
|
HOOK_PLAYER_SPAWN,
|
|
|
|
HOOK_PLAYER_JOIN,
|
|
|
|
HOOK_PLAYER_MOVE,
|
|
|
|
HOOK_TAKE_DAMAGE,
|
|
|
|
HOOK_KILLED,
|
|
|
|
HOOK_CHUNK_GENERATED,
|
|
|
|
HOOK_CHUNK_GENERATING,
|
|
|
|
HOOK_BLOCK_TO_DROPS,
|
|
|
|
HOOK_PRE_CRAFTING, /// cPlayer, cCraftingGrid, cCraftingRecipe
|
|
|
|
HOOK_CRAFTING_NO_RECIPE, /// cPlayer, cCraftingGrid, cCraftingRecipe
|
|
|
|
HOOK_POST_CRAFTING, /// cPlayer, cCraftingGrid, cCraftingRecipe
|
|
|
|
|
|
|
|
// E_PLUGIN_ names are obsolete, but are kept for compatibility reasons
|
|
|
|
E_PLUGIN_TICK = HOOK_TICK,
|
|
|
|
E_PLUGIN_CHAT = HOOK_CHAT,
|
|
|
|
E_PLUGIN_COLLECT_ITEM = HOOK_COLLECT_ITEM,
|
|
|
|
E_PLUGIN_BLOCK_DIG = HOOK_BLOCK_DIG,
|
|
|
|
E_PLUGIN_BLOCK_PLACE = HOOK_BLOCK_PLACE,
|
|
|
|
E_PLUGIN_DISCONNECT = HOOK_DISCONNECT,
|
|
|
|
E_PLUGIN_HANDSHAKE = HOOK_HANDSHAKE,
|
|
|
|
E_PLUGIN_LOGIN = HOOK_LOGIN,
|
|
|
|
E_PLUGIN_PLAYER_SPAWN = HOOK_PLAYER_SPAWN,
|
|
|
|
E_PLUGIN_PLAYER_JOIN = HOOK_PLAYER_JOIN,
|
|
|
|
E_PLUGIN_PLAYER_MOVE = HOOK_PLAYER_MOVE,
|
|
|
|
E_PLUGIN_TAKE_DAMAGE = HOOK_TAKE_DAMAGE,
|
|
|
|
E_PLUGIN_KILLED = HOOK_KILLED,
|
|
|
|
E_PLUGIN_CHUNK_GENERATED = HOOK_CHUNK_GENERATED,
|
|
|
|
E_PLUGIN_CHUNK_GENERATING = HOOK_CHUNK_GENERATING,
|
|
|
|
E_PLUGIN_BLOCK_TO_DROPS = HOOK_BLOCK_TO_DROPS,
|
|
|
|
};
|
|
|
|
// tolua_end
|
2011-10-03 11:41:19 -07:00
|
|
|
|
|
|
|
static cPluginManager * GetPluginManager(); //tolua_export
|
|
|
|
|
2012-06-12 14:30:32 -07:00
|
|
|
typedef std::list< cPlugin * > PluginList;
|
2012-03-28 11:11:06 -07:00
|
|
|
cPlugin* GetPlugin( const char* a_Plugin ) const; //tolua_export
|
|
|
|
const PluginList & GetAllPlugins() const; // >> EXPORTED IN MANUALBINDINGS <<
|
2011-10-03 11:41:19 -07:00
|
|
|
|
|
|
|
void ReloadPlugins(); //tolua_export
|
|
|
|
bool AddPlugin( cPlugin* a_Plugin );
|
|
|
|
bool AddPlugin( lua_State* a_LuaState, cPlugin* a_Plugin ); //tolua_export
|
|
|
|
bool AddLuaPlugin( cPlugin_Lua* a_Plugin );
|
|
|
|
void AddHook( cPlugin* a_Plugin, PluginHook a_Hook ); //tolua_export
|
|
|
|
|
2012-03-28 11:11:06 -07:00
|
|
|
unsigned int GetNumPlugins() const; //tolua_export
|
2011-10-03 11:41:19 -07:00
|
|
|
|
|
|
|
bool CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... );
|
2012-06-12 14:30:32 -07:00
|
|
|
|
|
|
|
bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
|
|
|
bool CallHookCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
|
|
|
bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
2011-10-03 11:41:19 -07:00
|
|
|
|
2011-11-07 17:25:01 -08:00
|
|
|
void RemoveHooks( cPlugin* a_Plugin );
|
2011-10-03 11:41:19 -07:00
|
|
|
void RemovePlugin( cPlugin* a_Plugin, bool a_bDelete = false ); //tolua_export
|
|
|
|
void RemoveLuaPlugin( std::string a_FileName ); //tolua_export
|
|
|
|
cPlugin_Lua* GetLuaPlugin( lua_State* a_State ); //tolua_export
|
|
|
|
|
2012-03-28 11:11:06 -07:00
|
|
|
cLuaCommandBinder* GetLuaCommandBinder() const { return m_LuaCommandBinder; }
|
|
|
|
|
|
|
|
bool HasPlugin( cPlugin* a_Plugin ) const;
|
2011-10-03 11:41:19 -07:00
|
|
|
private:
|
|
|
|
friend class cRoot;
|
|
|
|
cPluginManager();
|
|
|
|
~cPluginManager();
|
|
|
|
|
2012-03-28 11:11:06 -07:00
|
|
|
typedef std::list< cPlugin_Lua* > LuaPluginList;
|
|
|
|
typedef std::map< cPluginManager::PluginHook, cPluginManager::PluginList > HookMap;
|
|
|
|
|
|
|
|
LuaPluginList m_LuaPlugins;
|
|
|
|
PluginList m_Plugins;
|
|
|
|
HookMap m_Hooks;
|
2011-10-03 11:41:19 -07:00
|
|
|
|
|
|
|
void ReloadPluginsNow();
|
|
|
|
void UnloadPluginsNow();
|
|
|
|
|
|
|
|
cLuaCommandBinder* m_LuaCommandBinder;
|
|
|
|
|
|
|
|
bool m_bReloadPlugins;
|
|
|
|
}; //tolua_export
|