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
2013-05-26 16:18:56 -04:00
2012-06-14 09:06:06 -04:00
class cPlugin ;
2012-12-21 06:04:08 -05:00
// fwd: World.h
2012-06-14 13:30:37 -04:00
class cWorld ;
2013-01-25 05:12:29 -05:00
// fwd: ChunkDesc.h
class cChunkDesc ;
2012-06-14 13:30:37 -04:00
2013-08-08 03:13:13 -04:00
// fwd: Entities/Entity.h
2013-08-02 02:44:06 -04:00
class cEntity ;
2013-08-08 03:13:13 -04:00
// fwd: Mobs/Monster.h
class cMonster ;
2012-12-21 06:04:08 -05:00
// fwd: Player.h
2012-06-14 09:06:06 -04:00
class cPlayer ;
// fwd: CraftingRecipes.h
class cCraftingGrid ;
class cCraftingRecipe ;
2012-12-21 06:04:08 -05:00
// fwd: Pickup.h
2012-08-24 05:49:00 -04:00
class cPickup ;
2012-12-21 06:04:08 -05:00
// fwd: Pawn.h
struct TakeDamageInfo ;
class cPawn ;
2013-06-29 11:30:05 -04:00
// fwd: CommandOutput.h
class cCommandOutputCallback ;
2013-08-11 08:57:07 -04:00
// fwd: BlockEntities/HopperEntity.h
class cHopperEntity ;
// fwd: BlockEntities/BlockEntityWithItems.h
class cBlockEntityWithItems ;
2012-06-14 09:06:06 -04:00
2013-01-11 23:46:01 -05:00
class cPluginManager // tolua_export
{ // tolua_export
public : // tolua_export
2012-06-14 09:06:06 -04:00
// Called each tick
virtual void Tick ( float a_Dt ) ;
// tolua_begin
enum PluginHook
{
2013-01-26 21:00:33 -05:00
HOOK_BLOCK_TO_PICKUPS ,
2012-06-14 09:06:06 -04:00
HOOK_CHAT ,
2013-02-05 14:57:22 -05:00
HOOK_CHUNK_AVAILABLE ,
2013-01-11 23:46:01 -05:00
HOOK_CHUNK_GENERATED ,
HOOK_CHUNK_GENERATING ,
2013-02-05 14:57:22 -05:00
HOOK_CHUNK_UNLOADED ,
HOOK_CHUNK_UNLOADING ,
2013-01-28 11:17:26 -05:00
HOOK_COLLECTING_PICKUP ,
2013-01-11 23:46:01 -05:00
HOOK_CRAFTING_NO_RECIPE ,
2012-06-14 09:06:06 -04:00
HOOK_DISCONNECT ,
2013-02-21 08:47:01 -05:00
HOOK_EXECUTE_COMMAND ,
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
HOOK_EXPLODED ,
HOOK_EXPLODING ,
2012-06-14 09:06:06 -04:00
HOOK_HANDSHAKE ,
2013-08-11 08:57:07 -04:00
HOOK_HOPPER_PULLING_ITEM ,
HOOK_HOPPER_PUSHING_ITEM ,
2013-01-28 11:54:11 -05:00
HOOK_KILLING ,
2013-01-11 23:46:01 -05:00
HOOK_LOGIN ,
2013-08-11 06:12:20 -04:00
HOOK_PLAYER_ANIMATION ,
2013-01-11 23:46:01 -05:00
HOOK_PLAYER_BREAKING_BLOCK ,
HOOK_PLAYER_BROKEN_BLOCK ,
HOOK_PLAYER_EATING ,
HOOK_PLAYER_JOINED ,
HOOK_PLAYER_LEFT_CLICK ,
2013-01-26 02:50:06 -05:00
HOOK_PLAYER_MOVING ,
2013-01-11 23:46:01 -05:00
HOOK_PLAYER_PLACED_BLOCK ,
HOOK_PLAYER_PLACING_BLOCK ,
2013-01-18 13:28:27 -05:00
HOOK_PLAYER_RIGHT_CLICK ,
2013-08-02 02:44:06 -04:00
HOOK_PLAYER_RIGHT_CLICKING_ENTITY ,
2013-01-11 23:46:01 -05:00
HOOK_PLAYER_SHOOTING ,
HOOK_PLAYER_SPAWNED ,
HOOK_PLAYER_TOSSING_ITEM ,
HOOK_PLAYER_USED_BLOCK ,
HOOK_PLAYER_USED_ITEM ,
HOOK_PLAYER_USING_BLOCK ,
HOOK_PLAYER_USING_ITEM ,
HOOK_POST_CRAFTING ,
HOOK_PRE_CRAFTING ,
2013-08-08 03:13:13 -04:00
HOOK_SPAWNED_ENTITY ,
HOOK_SPAWNED_MONSTER ,
HOOK_SPAWNING_ENTITY ,
HOOK_SPAWNING_MONSTER ,
2013-01-11 23:46:01 -05:00
HOOK_TAKE_DAMAGE ,
HOOK_TICK ,
HOOK_UPDATED_SIGN ,
HOOK_UPDATING_SIGN ,
HOOK_WEATHER_CHANGED ,
2013-02-13 14:22:08 -05:00
HOOK_WEATHER_CHANGING ,
2013-08-19 03:28:22 -04:00
HOOK_WORLD_TICK ,
2012-06-14 09:06:06 -04:00
2013-02-13 14:22:08 -05:00
// Note that if a hook type is added, it may need processing in cPlugin::CanAddHook() descendants,
2013-08-19 03:39:18 -04:00
// and it definitely needs adding in cPluginLua::GetHookFnName() !
2013-08-21 15:29:30 -04:00
// Keep these two as the last items, they are used for validity checking and get their values automagically
HOOK_NUM_HOOKS ,
HOOK_MAX = HOOK_NUM_HOOKS - 1 ,
2013-01-11 23:46:01 -05:00
} ;
2012-06-14 09:06:06 -04:00
// tolua_end
2013-02-01 14:55:42 -05:00
/// Used as a callback for enumerating bound commands
class cCommandEnumCallback
{
public :
2013-02-15 08:00:59 -05:00
/** Called for each command; return true to abort enumeration
For console commands , a_Permission is not used ( set to empty string )
*/
2013-02-01 14:55:42 -05:00
virtual bool Command ( const AString & a_Command , const cPlugin * a_Plugin , const AString & a_Permission , const AString & a_HelpString ) = 0 ;
} ;
/// Returns the instance of the Plugin Manager (there is only ever one)
static cPluginManager * Get ( void ) ; // tolua_export
2012-06-14 09:06:06 -04:00
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 ;
2013-01-11 23:46:01 -05:00
cPlugin * GetPlugin ( const AString & a_Plugin ) const ; // tolua_export
2012-10-13 19:34:47 -04:00
const PluginMap & GetAllPlugins ( ) const ; // >> EXPORTED IN MANUALBINDINGS <<
2012-06-14 09:06:06 -04:00
2013-01-11 23:46:01 -05:00
void FindPlugins ( ) ; // tolua_export
void ReloadPlugins ( ) ; // tolua_export
2013-08-21 15:29:30 -04:00
/// Adds the plugin to the list of plugins called for the specified hook type. Handles multiple adds as a single add
void AddHook ( cPlugin * a_Plugin , int a_HookType ) ;
2013-01-11 23:46:01 -05:00
2013-08-08 03:13:13 -04:00
unsigned int GetNumPlugins ( ) const ; // tolua_export
// Calls for individual hooks. Each returns false if the action is to continue or true if the plugin wants to abort
2013-08-02 02:44:06 -04:00
bool CallHookBlockToPickups ( cWorld * a_World , cEntity * a_Digger , int a_BlockX , int a_BlockY , int a_BlockZ , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta , cItems & a_Pickups ) ;
bool CallHookChat ( cPlayer * a_Player , AString & a_Message ) ;
bool CallHookChunkAvailable ( cWorld * a_World , int a_ChunkX , int a_ChunkZ ) ;
bool CallHookChunkGenerated ( cWorld * a_World , int a_ChunkX , int a_ChunkZ , cChunkDesc * a_ChunkDesc ) ;
bool CallHookChunkGenerating ( cWorld * a_World , int a_ChunkX , int a_ChunkZ , cChunkDesc * a_ChunkDesc ) ;
bool CallHookChunkUnloaded ( cWorld * a_World , int a_ChunkX , int a_ChunkZ ) ;
bool CallHookChunkUnloading ( cWorld * a_World , int a_ChunkX , int a_ChunkZ ) ;
bool CallHookCollectingPickup ( cPlayer * a_Player , cPickup & a_Pickup ) ;
bool CallHookCraftingNoRecipe ( const cPlayer * a_Player , const cCraftingGrid * a_Grid , cCraftingRecipe * a_Recipe ) ;
bool CallHookDisconnect ( cPlayer * a_Player , const AString & a_Reason ) ;
bool CallHookExecuteCommand ( cPlayer * a_Player , const AStringVector & a_Split ) ; // If a_Player == NULL, it is a console cmd
Added OnExploding() and OnExploded() hooks.
As requested in FS 413, with extra parameters:
World, BlockX, BlockY, BlockZ, Size, CanCauseFire, Source, SourceData
OnExploding() can return 3 values:
StopHook, CanCauseFire, ExplosionSize
2013-08-09 08:58:43 -04:00
bool CallHookExploded ( cWorld & a_World , double a_ExplosionSize , bool a_CanCauseFire , double a_X , double a_Y , double a_Z , eExplosionSource a_Source , void * a_SourceData ) ;
bool CallHookExploding ( cWorld & a_World , double & a_ExplosionSize , bool & a_CanCauseFire , double a_X , double a_Y , double a_Z , eExplosionSource a_Source , void * a_SourceData ) ;
2013-08-02 02:44:06 -04:00
bool CallHookHandshake ( cClientHandle * a_ClientHandle , const AString & a_Username ) ;
2013-08-11 08:57:07 -04:00
bool CallHookHopperPullingItem ( cWorld & a_World , cHopperEntity & a_Hopper , int a_DstSlotNum , cBlockEntityWithItems & a_SrcEntity , int a_SrcSlotNum ) ;
bool CallHookHopperPushingItem ( cWorld & a_World , cHopperEntity & a_Hopper , int a_SrcSlotNum , cBlockEntityWithItems & a_DstEntity , int a_DstSlotNum ) ;
2013-08-02 02:44:06 -04:00
bool CallHookKilling ( cEntity & a_Victim , cEntity * a_Killer ) ;
bool CallHookLogin ( cClientHandle * a_Client , int a_ProtocolVersion , const AString & a_Username ) ;
2013-08-11 06:12:20 -04:00
bool CallHookPlayerAnimation ( cPlayer & a_Player , int a_Animation ) ;
2013-08-02 02:44:06 -04:00
bool CallHookPlayerBreakingBlock ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ) ;
bool CallHookPlayerBrokenBlock ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , BLOCKTYPE a_BlockType , NIBBLETYPE a_BlockMeta ) ;
bool CallHookPlayerEating ( cPlayer & a_Player ) ;
bool CallHookPlayerJoined ( cPlayer & a_Player ) ;
bool CallHookPlayerMoving ( cPlayer & a_Player ) ;
bool CallHookPlayerLeftClick ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , char a_Status ) ;
bool CallHookPlayerPlacedBlock ( 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 ) ;
bool CallHookPlayerPlacingBlock ( 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 ) ;
bool CallHookPlayerRightClick ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , int a_CursorX , int a_CursorY , int a_CursorZ ) ;
bool CallHookPlayerRightClickingEntity ( cPlayer & a_Player , cEntity & a_Entity ) ;
bool CallHookPlayerShooting ( cPlayer & a_Player ) ;
bool CallHookPlayerSpawned ( cPlayer & a_Player ) ;
bool CallHookPlayerTossingItem ( cPlayer & a_Player ) ;
bool CallHookPlayerUsedBlock ( 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 ) ;
bool CallHookPlayerUsedItem ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , int a_CursorX , int a_CursorY , int a_CursorZ ) ;
bool CallHookPlayerUsingBlock ( 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 ) ;
bool CallHookPlayerUsingItem ( cPlayer & a_Player , int a_BlockX , int a_BlockY , int a_BlockZ , char a_BlockFace , int a_CursorX , int a_CursorY , int a_CursorZ ) ;
bool CallHookPostCrafting ( const cPlayer * a_Player , const cCraftingGrid * a_Grid , cCraftingRecipe * a_Recipe ) ;
bool CallHookPreCrafting ( const cPlayer * a_Player , const cCraftingGrid * a_Grid , cCraftingRecipe * a_Recipe ) ;
2013-08-08 03:13:13 -04:00
bool CallHookSpawnedEntity ( cWorld & a_World , cEntity & a_Entity ) ;
bool CallHookSpawnedMonster ( cWorld & a_World , cMonster & a_Monster ) ;
bool CallHookSpawningEntity ( cWorld & a_World , cEntity & a_Entity ) ;
bool CallHookSpawningMonster ( cWorld & a_World , cMonster & a_Monster ) ;
2013-08-02 02:44:06 -04:00
bool CallHookTakeDamage ( cEntity & a_Receiver , TakeDamageInfo & a_TDI ) ;
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 ) ;
bool CallHookWeatherChanged ( cWorld & a_World ) ;
bool CallHookWeatherChanging ( cWorld & a_World , eWeather & a_NewWeather ) ;
2013-11-30 08:22:26 -05:00
bool CallHookWorldTick ( cWorld & a_World , float a_Dt , int a_LastTickDurationMSec ) ;
2013-02-01 14:55:42 -05:00
bool DisablePlugin ( const AString & a_PluginName ) ; // tolua_export
bool LoadPlugin ( const AString & a_PluginName ) ; // tolua_export
2013-01-11 23:46:01 -05:00
2013-02-01 14:55:42 -05:00
/// Removes all hooks the specified plugin has registered
void RemoveHooks ( cPlugin * a_Plugin ) ;
2012-07-09 11:53:17 -04:00
2013-02-01 14:55:42 -05:00
/// Removes the plugin from the internal structures and deletes its object.
void RemovePlugin ( cPlugin * a_Plugin ) ;
2012-07-09 11:53:17 -04:00
2013-02-01 14:55:42 -05:00
/// Removes all command bindings that the specified plugin has made
void RemovePluginCommands ( cPlugin * a_Plugin ) ;
2012-11-08 14:09:35 -05:00
2013-02-01 14:55:42 -05:00
/// Binds a command to the specified plugin. Returns true if successful, false if command already bound.
bool BindCommand ( const AString & a_Command , cPlugin * a_Plugin , const AString & a_Permission , const AString & a_HelpString ) ; // Exported in ManualBindings.cpp, without the a_Plugin param
/// Calls a_Callback for each bound command, returns true if all commands were enumerated
bool ForEachCommand ( cCommandEnumCallback & a_Callback ) ; // Exported in ManualBindings.cpp
/// Returns true if the command is in the command map
bool IsCommandBound ( const AString & a_Command ) ; // tolua_export
/// Returns the permission needed for the specified command; empty string if command not found
AString GetCommandPermission ( const AString & a_Command ) ; // tolua_export
/// Executes the command, as if it was requested by a_Player. Checks permissions first. Returns true if executed.
2013-02-13 15:05:57 -05:00
bool ExecuteCommand ( cPlayer * a_Player , const AString & a_Command ) ; // tolua_export
2013-02-01 14:55:42 -05:00
/// Executes the command, as if it was requested by a_Player. Permisssions are not checked. Returns true if executed (false if not found)
2013-02-13 15:05:57 -05:00
bool ForceExecuteCommand ( cPlayer * a_Player , const AString & a_Command ) ; // tolua_export
2013-02-15 08:00:59 -05:00
/// Removes all console command bindings that the specified plugin has made
void RemovePluginConsoleCommands ( cPlugin * a_Plugin ) ;
/// Binds a console command to the specified plugin. Returns true if successful, false if command already bound.
bool BindConsoleCommand ( const AString & a_Command , cPlugin * a_Plugin , const AString & a_HelpString ) ; // Exported in ManualBindings.cpp, without the a_Plugin param
/// Calls a_Callback for each bound console command, returns true if all commands were enumerated
bool ForEachConsoleCommand ( cCommandEnumCallback & a_Callback ) ; // Exported in ManualBindings.cpp
/// Returns true if the console command is in the command map
bool IsConsoleCommandBound ( const AString & a_Command ) ; // tolua_export
2013-06-29 11:30:05 -04:00
/// Executes the command split into a_Split, as if it was given on the console. Returns true if executed. Output is sent to the a_Output callback
bool ExecuteConsoleCommand ( const AStringVector & a_Split , cCommandOutputCallback & a_Output ) ;
2013-02-15 08:00:59 -05:00
2013-07-31 05:16:11 -04:00
/** Appends all commands beginning with a_Text (case-insensitive) into a_Results.
If a_Player is not NULL , only commands for which the player has permissions are added .
*/
void TabCompleteCommand ( const AString & a_Text , AStringVector & a_Results , cPlayer * a_Player ) ;
2013-07-30 16:48:59 -04:00
2013-08-21 15:29:30 -04:00
/// Returns true if the specified hook type is within the allowed range
static bool IsValidHookType ( int a_HookType ) ;
2013-02-01 14:55:42 -05:00
private :
2012-06-14 09:06:06 -04:00
friend class cRoot ;
2012-11-08 14:09:35 -05:00
2013-02-01 14:55:42 -05:00
class cCommandReg
{
public :
cPlugin * m_Plugin ;
2013-02-15 08:00:59 -05:00
AString m_Permission ; // Not used for console commands
2013-02-01 14:55:42 -05:00
AString m_HelpString ;
} ;
2013-08-21 15:29:30 -04:00
typedef std : : map < int , cPluginManager : : PluginList > HookMap ;
2013-02-01 14:55:42 -05:00
typedef std : : map < AString , cCommandReg > CommandMap ;
2012-06-14 09:06:06 -04:00
2012-10-13 19:34:47 -04:00
PluginList m_DisablePluginList ;
2013-02-01 14:55:42 -05:00
PluginMap m_Plugins ;
HookMap m_Hooks ;
CommandMap m_Commands ;
2013-02-15 08:00:59 -05:00
CommandMap m_ConsoleCommands ;
2013-02-01 14:55:42 -05:00
bool m_bReloadPlugins ;
2012-10-13 19:34:47 -04:00
2013-02-01 14:55:42 -05:00
cPluginManager ( ) ;
~ cPluginManager ( ) ;
2012-06-14 09:06:06 -04:00
2013-11-04 16:51:24 -05:00
/// Reloads all plugins, defaulting to settings.ini for settings location
2013-02-01 14:55:42 -05:00
void ReloadPluginsNow ( void ) ;
2013-11-04 16:51:24 -05:00
/// Reloads all plugins with a cIniFile object expected to be initialised to settings.ini
void ReloadPluginsNow ( cIniFile & a_SettingsIni ) ;
/// Unloads all plugins
2013-02-01 14:55:42 -05:00
void UnloadPluginsNow ( void ) ;
2012-06-14 09:06:06 -04:00
2013-11-05 16:15:39 -05:00
/// Handles writing default plugins if 'Plugins' key not found using a cIniFile object expected to be intialised to settings.ini
void InsertDefaultPlugins ( cIniFile & a_SettingsIni ) ;
2013-02-01 14:55:42 -05:00
/// Adds the plugin into the internal list of plugins and initializes it. If initialization fails, the plugin is removed again.
bool AddPlugin ( cPlugin * a_Plugin ) ;
/// Tries to match a_Command to the internal table of commands, if a match is found, the corresponding plugin is called. Returns true if the command is handled.
bool HandleCommand ( cPlayer * a_Player , const AString & a_Command , bool a_ShouldCheckPermissions ) ;
} ; // tolua_export
2012-11-08 14:09:35 -05:00