2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2012-09-23 18:09:57 -04:00
|
|
|
#include "Item.h"
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
struct lua_State;
|
|
|
|
class cLuaCommandBinder;
|
2012-11-08 14:09:35 -05:00
|
|
|
|
|
|
|
#ifdef USE_SQUIRREL
|
|
|
|
class cSquirrelCommandBinder;
|
|
|
|
#endif // USE_SQUIRREL
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
class cPlugin;
|
|
|
|
|
2012-06-14 13:30:37 -04:00
|
|
|
// fwd: cWorld.h
|
|
|
|
class cWorld;
|
|
|
|
|
|
|
|
// fwd: cLuaChunk.h
|
|
|
|
class cLuaChunk;
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
// fwd: cPlayer.h
|
|
|
|
class cPlayer;
|
|
|
|
|
|
|
|
// fwd: CraftingRecipes.h
|
|
|
|
class cCraftingGrid;
|
|
|
|
class cCraftingRecipe;
|
|
|
|
|
2012-08-24 05:49:00 -04:00
|
|
|
// fwd: cPickup.h
|
|
|
|
class cPickup;
|
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cPluginManager //tolua_export
|
|
|
|
{ //tolua_export
|
|
|
|
public: //tolua_export
|
|
|
|
|
|
|
|
// Called each tick
|
|
|
|
virtual void Tick(float a_Dt);
|
|
|
|
|
|
|
|
// tolua_begin
|
|
|
|
enum PluginHook
|
|
|
|
{
|
|
|
|
HOOK_TICK,
|
|
|
|
HOOK_CHAT,
|
2012-08-24 05:49:00 -04:00
|
|
|
HOOK_COLLECT_PICKUP,
|
|
|
|
HOOK_COLLECT_ITEM = HOOK_COLLECT_PICKUP, // OBSOLETE, use HOOK_COLLECT_PICKUP instead
|
2012-06-14 09:06:06 -04:00
|
|
|
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
|
|
|
|
HOOK_BLOCK_TO_PICKUP, /// BlockType, BlockMeta, cPlayer, cItem, cItems
|
2012-06-16 11:06:14 -04:00
|
|
|
HOOK_WEATHER_CHANGED, /// cWorld
|
|
|
|
HOOK_UPDATING_SIGN, /// cWorld, int, int, int, string, string, string, string
|
|
|
|
HOOK_UPDATED_SIGN, /// cWorld, int, int, int, string, string, string, string
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
static cPluginManager * GetPluginManager(); //tolua_export
|
|
|
|
|
2012-10-13 19:34:47 -04:00
|
|
|
typedef std::map< AString, cPlugin * > PluginMap;
|
2012-06-14 09:06:06 -04:00
|
|
|
typedef std::list< cPlugin * > PluginList;
|
2012-10-13 19:34:47 -04:00
|
|
|
cPlugin * GetPlugin( const AString & a_Plugin ) const; //tolua_export
|
|
|
|
const PluginMap & GetAllPlugins() const; // >> EXPORTED IN MANUALBINDINGS <<
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-10-13 19:34:47 -04:00
|
|
|
void FindPlugins(); //tolua_export
|
2012-06-14 09:06:06 -04:00
|
|
|
void ReloadPlugins(); //tolua_export
|
|
|
|
bool AddPlugin( cPlugin* a_Plugin );
|
|
|
|
void AddHook( cPlugin* a_Plugin, PluginHook a_Hook ); //tolua_export
|
|
|
|
|
|
|
|
unsigned int GetNumPlugins() const; //tolua_export
|
|
|
|
|
2012-06-16 11:06:14 -04:00
|
|
|
// If the hook returns true, no further hook is called and the functions return false
|
2012-06-14 09:06:06 -04:00
|
|
|
bool CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... );
|
|
|
|
|
2012-08-18 05:56:28 -04:00
|
|
|
bool CallHookBlockDig (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE OldBlock, NIBBLETYPE OldMeta);
|
|
|
|
bool CallHookBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem);
|
2012-08-18 06:38:15 -04:00
|
|
|
bool CallHookBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
|
|
|
|
bool CallHookChat (cPlayer * a_Player, const AString & a_Message);
|
2012-06-14 13:30:37 -04:00
|
|
|
bool CallHookChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_Chunk);
|
2012-08-24 05:49:00 -04:00
|
|
|
bool CallHookCollectPickup (cPlayer * a_Player, cPickup & a_Pickup);
|
2012-06-14 09:06:06 -04:00
|
|
|
bool CallHookCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
2012-08-19 15:42:32 -04:00
|
|
|
bool CallHookDisconnect (cPlayer * a_Player, const AString & a_Reason);
|
2012-08-18 06:38:15 -04:00
|
|
|
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
|
2012-06-14 09:06:06 -04:00
|
|
|
bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
2012-08-18 06:38:15 -04:00
|
|
|
bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
2012-09-01 17:31:20 -04:00
|
|
|
bool CallHookUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player);
|
|
|
|
bool CallHookUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player);
|
2012-08-18 06:38:15 -04:00
|
|
|
bool CallHookWeatherChanged (cWorld * a_World);
|
2012-09-05 16:30:27 -04:00
|
|
|
bool CallHookHandshake (cClientHandle * a_ClientHandle, const AString & a_Username);
|
2012-06-14 09:06:06 -04:00
|
|
|
|
2012-10-13 19:34:47 -04:00
|
|
|
bool DisablePlugin( AString & a_PluginName ); //tolua_export
|
|
|
|
bool LoadPlugin( AString & a_PluginName ); //tolua_export
|
|
|
|
|
|
|
|
void RemoveHooks( cPlugin * a_Plugin );
|
|
|
|
void RemovePlugin( cPlugin * a_Plugin, bool a_bDelete = false );
|
2012-07-09 11:53:17 -04:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cLuaCommandBinder* GetLuaCommandBinder() const { return m_LuaCommandBinder; }
|
2012-07-09 11:53:17 -04:00
|
|
|
|
2012-11-08 14:09:35 -05:00
|
|
|
#ifdef USE_SQUIRREL
|
|
|
|
cSquirrelCommandBinder * GetSquirrelCommandBinder() { return m_SquirrelCommandBinder; }
|
|
|
|
#endif // USE_SQUIRREL
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
bool HasPlugin( cPlugin* a_Plugin ) const;
|
2012-11-08 14:09:35 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
private:
|
2012-11-08 14:09:35 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
friend class cRoot;
|
2012-11-08 14:09:35 -05:00
|
|
|
|
2012-06-14 09:06:06 -04:00
|
|
|
cPluginManager();
|
|
|
|
~cPluginManager();
|
|
|
|
|
|
|
|
typedef std::map< cPluginManager::PluginHook, cPluginManager::PluginList > HookMap;
|
|
|
|
|
2012-10-13 19:34:47 -04:00
|
|
|
PluginList m_DisablePluginList;
|
|
|
|
|
|
|
|
PluginMap m_Plugins;
|
2012-06-14 09:06:06 -04:00
|
|
|
HookMap m_Hooks;
|
|
|
|
|
|
|
|
void ReloadPluginsNow();
|
|
|
|
void UnloadPluginsNow();
|
2012-07-09 11:53:17 -04:00
|
|
|
|
2012-11-08 14:09:35 -05:00
|
|
|
cLuaCommandBinder * m_LuaCommandBinder;
|
|
|
|
|
|
|
|
#ifdef USE_SQUIRREL
|
|
|
|
cSquirrelCommandBinder * m_SquirrelCommandBinder;
|
|
|
|
#endif // USE_SQUIRREL
|
2012-06-14 09:06:06 -04:00
|
|
|
|
|
|
|
bool m_bReloadPlugins;
|
|
|
|
}; //tolua_export
|
2012-11-08 14:09:35 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|