diff options
Diffstat (limited to '')
-rw-r--r-- | source/Plugin.h | 95 |
1 files changed, 60 insertions, 35 deletions
diff --git a/source/Plugin.h b/source/Plugin.h index 9ee06e369..7cb82743e 100644 --- a/source/Plugin.h +++ b/source/Plugin.h @@ -2,6 +2,11 @@ #pragma once #include "Item.h" +#include "PluginManager.h" + + + + class cClientHandle; class cPlayer; @@ -28,51 +33,61 @@ class cCraftingRecipe; class cPlugin { public: + // tolua_end + cPlugin( const AString & a_PluginDirectory ); virtual ~cPlugin(); - virtual void OnDisable() {} - virtual bool Initialize() = 0; + virtual void OnDisable(void) {} + virtual bool Initialize(void) = 0; // Called each tick virtual void Tick(float a_Dt); /** - * On all these functions, return true if you want to override default behavior + * On all these functions, return true if you want to override default behavior and not call other plugins on that callback. * You can also return false, so default behavior is used. **/ - virtual bool OnBlockDig (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta); - virtual bool OnBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem); - virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups); - virtual bool OnChat (cPlayer * a_Player, const AString & a_Message); - virtual void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ); - virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk); - virtual bool OnCollectPickup (cPlayer * a_Player, cPickup * a_Pickup); - virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); - virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason); - virtual bool OnKilled (cPawn * a_Killed, cEntity* a_Killer ); - virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username); - virtual bool OnPlayerJoin (cPlayer* a_Player ); - virtual void OnPlayerMove (cPlayer* a_Player ); - virtual void OnPlayerSpawn (cPlayer* a_Player ); - virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); - virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); - virtual bool OnTakeDamage (cPawn & a_Receiver, TakeDamageInfo & a_TakeDamageInfo); - virtual bool OnUpdatedSign (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); - virtual bool OnUpdatingSign (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); - virtual bool OnWeatherChanged (cWorld * a_World); - virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username); + // TODO: virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups); + virtual bool OnChat (cPlayer * a_Player, const AString & a_Message); + virtual bool OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ); + virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk); + virtual bool OnCollectPickup (cPlayer * a_Player, cPickup * a_Pickup); + virtual bool OnCraftingNoRecipe (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); + virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason); + virtual bool OnHandshake (cClientHandle * a_Client, const AString & a_Username); + virtual bool OnKilled (cPawn & a_Killed, cEntity * a_Killer); + virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username); + virtual bool OnPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta); + virtual bool OnPlayerEating (cPlayer & a_Player); + virtual bool OnPlayerJoined (cPlayer & a_Player); + virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status); + virtual bool OnPlayerMoved (cPlayer & a_Player); + virtual bool OnPlayerPlacedBlock (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); + virtual bool OnPlayerPlacingBlock (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); + virtual bool 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); + virtual bool OnPlayerShooting (cPlayer & a_Player); + virtual bool OnPlayerSpawned (cPlayer & a_Player); + virtual bool OnPlayerTossingItem (cPlayer & a_Player); + virtual bool 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); + virtual bool 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); + virtual bool 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); + virtual bool 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); + virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); + virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe); + virtual bool OnTakeDamage (cPawn & a_Receiver, TakeDamageInfo & a_TakeDamageInfo); + virtual bool OnUpdatedSign (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); + virtual bool OnUpdatingSign (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); + virtual bool OnWeatherChanged (cWorld * a_World); + + /** Called from cPluginManager::AddHook() to check if the hook can be added. + Plugin API providers may check if the plugin is written correctly (has the hook handler function) + Returns true if the hook can be added (handler exists) + Descendants should also log the specific error message as a warning if they return false. + */ + virtual bool CanAddHook(cPluginManager::PluginHook a_Hook) { return false; } - // Accessors - const AString & GetName() const { return m_Name; } - virtual void SetName( const AString & a_Name ) { m_Name = a_Name; } - - int GetVersion() const { return m_Version; } - void SetVersion( int a_Version ) { m_Version = a_Version; } - - const AString & GetDirectory(void) const {return m_Directory; } - AString GetLocalDirectory(void) const; //tolua_export - struct CommandStruct { AString Command; @@ -80,6 +95,16 @@ public: AString Permission; }; + // tolua_begin + const AString & GetName(void) const { return m_Name; } + void SetName(const AString & a_Name) { m_Name = a_Name; } + + int GetVersion(void) const { return m_Version; } + void SetVersion(int a_Version) { m_Version = a_Version; } + + const AString & GetDirectory(void) const {return m_Directory; } + AString GetLocalDirectory(void) const; + void AddCommand(const AString & a_Command, const AString & a_Description, const AString & a_Permission); // tolua_end @@ -109,7 +134,7 @@ private: int m_Version; AString m_Directory; -}; //tolua_export +}; // tolua_export |