2012-06-12 17:30:32 -04:00
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class cPacket_BlockPlace;
|
|
|
|
class cPacket_PickupSpawn;
|
|
|
|
class cPacket_EntityEquipment;
|
|
|
|
class cPacket_Disconnect;
|
|
|
|
class cPacket_Chat;
|
|
|
|
class cPacket_BlockDig;
|
|
|
|
class cPacket_Login;
|
|
|
|
class cClientHandle;
|
|
|
|
class cPlayer;
|
|
|
|
class cPickup;
|
|
|
|
class cItem;
|
|
|
|
class cEntity;
|
|
|
|
class cPawn;
|
2012-06-05 11:20:48 -04:00
|
|
|
class cWorld;
|
2012-06-11 15:25:55 -04:00
|
|
|
class cLuaChunk;
|
2011-10-03 14:41:19 -04:00
|
|
|
struct TakeDamageInfo;
|
|
|
|
|
2012-06-12 17:30:32 -04:00
|
|
|
// fwd: cPlayer.h
|
|
|
|
class cPlayer;
|
|
|
|
|
|
|
|
// fwd: CraftingRecipes.h
|
|
|
|
class cCraftingGrid;
|
|
|
|
class cCraftingRecipe;
|
|
|
|
|
2012-06-05 11:20:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-03 14:41:19 -04:00
|
|
|
// tolua_begin
|
|
|
|
class cPlugin
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cPlugin();
|
|
|
|
virtual ~cPlugin();
|
|
|
|
|
|
|
|
virtual void OnDisable() {}
|
|
|
|
virtual bool Initialize() = 0;
|
|
|
|
|
|
|
|
// Called each tick
|
|
|
|
virtual void Tick(float a_Dt);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* On all these functions, return true if you want to override default behavior
|
|
|
|
* You can also return false, so default behavior is used, but with changed PacketData
|
|
|
|
**/
|
|
|
|
virtual bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player );
|
|
|
|
virtual bool OnDisconnect( std::string a_Reason, cPlayer* a_Player );
|
|
|
|
virtual bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player );
|
|
|
|
virtual bool OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem ) { (void)a_PacketData; (void)a_Player; (void)a_PickupItem; return false; }
|
2011-11-07 20:25:01 -05:00
|
|
|
virtual bool OnChat( const char* a_Chat, cPlayer* a_Player );
|
2011-10-03 14:41:19 -04:00
|
|
|
virtual bool OnLogin( cPacket_Login* a_PacketData );
|
|
|
|
virtual void OnPlayerSpawn( cPlayer* a_Player );
|
|
|
|
virtual bool OnPlayerJoin( cPlayer* a_Player );
|
|
|
|
virtual void OnPlayerMove( cPlayer* a_Player ) { (void)a_Player; }
|
|
|
|
virtual void OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) { (void)a_Pawn; (void)a_TakeDamageInfo; }
|
|
|
|
virtual bool OnKilled( cPawn* a_Killed, cEntity* a_Killer ) { (void)a_Killed; (void)a_Killer; return false; }
|
2012-06-05 11:20:48 -04:00
|
|
|
virtual void OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ) {}
|
2012-06-11 15:25:55 -04:00
|
|
|
virtual bool OnChunkGenerating( int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk ) { return false; }
|
2012-06-12 17:30:32 -04:00
|
|
|
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) {return false; }
|
|
|
|
virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) {return false; }
|
|
|
|
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) {return false; }
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
// Accessors
|
2011-11-07 20:25:01 -05:00
|
|
|
const char* GetName() const { return m_Name.c_str(); }
|
|
|
|
void SetName( const char* a_Name ) { m_Name = a_Name; }
|
2011-10-03 14:41:19 -04:00
|
|
|
|
|
|
|
int GetVersion() const { return m_Version; }
|
|
|
|
void SetVersion( int a_Version ) { m_Version = a_Version; }
|
|
|
|
|
|
|
|
struct CommandStruct
|
|
|
|
{
|
|
|
|
std::string Command;
|
|
|
|
std::string Description;
|
|
|
|
std::string Permission;
|
|
|
|
};
|
|
|
|
|
|
|
|
void AddCommand( std::string & a_Command, std::string & a_Description, std::string & a_Permission );
|
|
|
|
// tolua_end
|
|
|
|
typedef bool (FuncCommandHandler)( std::string & a_Command, std::vector< std::string > & a_Split );
|
|
|
|
void BindCommand( FuncCommandHandler* a_Function, std::string & a_Command ); // >> EXPORTED IN MANUALBINDINGS <<
|
|
|
|
const std::vector< CommandStruct > & GetCommands() const { return m_Commands; } // >> EXPORTED IN MANUALBINDINGS <<
|
|
|
|
|
2011-11-07 20:25:01 -05:00
|
|
|
|
|
|
|
/* This should not be exposed to scripting languages */
|
|
|
|
enum PluginLanguage
|
|
|
|
{
|
|
|
|
E_CPP,
|
|
|
|
E_LUA,
|
|
|
|
E_SQUIRREL,
|
|
|
|
};
|
|
|
|
PluginLanguage GetLanguage() { return m_Language; }
|
|
|
|
void SetLanguage( PluginLanguage a_Language ) { m_Language = a_Language; }
|
|
|
|
|
2012-03-28 14:11:06 -04:00
|
|
|
bool CanBindCommands() { return m_bCanBindCommands; }
|
2011-10-03 14:41:19 -04:00
|
|
|
private:
|
2012-03-28 14:11:06 -04:00
|
|
|
friend class cPluginManager;
|
|
|
|
bool m_bCanBindCommands; // Only changed by cPluginManager
|
|
|
|
|
2011-11-07 20:25:01 -05:00
|
|
|
PluginLanguage m_Language;
|
2011-10-03 14:41:19 -04:00
|
|
|
std::vector< CommandStruct > m_Commands;
|
|
|
|
std::string m_Name;
|
|
|
|
int m_Version;
|
|
|
|
}; //tolua_export
|
2012-06-05 11:20:48 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|