summaryrefslogtreecommitdiffstats
path: root/source/cPluginManager.h
blob: 9f9e41e8b27c9895494af6fd21307eac4da82fa6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128

#pragma once

#include "cItem.h"

struct lua_State;
class cLuaCommandBinder;
class cPlugin;
class cPlugin_Lua;

// fwd: cWorld.h
class cWorld;

// fwd: cLuaChunk.h
class cLuaChunk;

// fwd: cPlayer.h
class cPlayer;

// fwd: CraftingRecipes.h
class cCraftingGrid;
class cCraftingRecipe;





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,
		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
		HOOK_BLOCK_TO_PICKUP,     /// BlockType, BlockMeta, cPlayer, cItem, cItems
		HOOK_WEATHER_CHANGE,
		
		// 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

	typedef std::list< cPlugin * > PluginList;
	cPlugin* GetPlugin( const char* a_Plugin ) const;					//tolua_export
	const PluginList & GetAllPlugins() const;							// >> EXPORTED IN MANUALBINDINGS <<

	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

	unsigned int GetNumPlugins() const;									//tolua_export

	bool CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... );
	
	bool CallHookChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_Chunk);
	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);
	bool CallHookBlockToPickup   (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);

	void RemoveHooks( cPlugin* a_Plugin );
	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

	cLuaCommandBinder* GetLuaCommandBinder() const { return m_LuaCommandBinder; }

	bool HasPlugin( cPlugin* a_Plugin ) const;
private:
	friend class cRoot;
	cPluginManager();
	~cPluginManager();

	typedef std::list< cPlugin_Lua* > LuaPluginList;
	typedef std::map< cPluginManager::PluginHook, cPluginManager::PluginList > HookMap;

	LuaPluginList m_LuaPlugins;
	PluginList m_Plugins;
	HookMap m_Hooks;

	void ReloadPluginsNow();
	void UnloadPluginsNow();

	cLuaCommandBinder* m_LuaCommandBinder;

	bool m_bReloadPlugins;
}; //tolua_export