5 #include "../Defines.h" 6 #include "../FunctionRef.h" 204 void Tick(
float a_Dt);
268 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);
274 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);
276 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);
294 bool CallHookWorldTick (
cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec);
322 cCommandHandlerPtr a_Handler,
351 cCommandHandlerPtr a_Handler,
401 typedef std::map<int, cPluginManager::PluginList>
HookMap;
451 template <
typename HookFunction>
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)
void RemoveHooks(cPlugin *a_Plugin)
Removes all hooks the specified plugin has registered.
bool CallHookBlockSpread(cWorld &a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source)
void RefreshPluginList()
Refreshes the m_Plugins list based on the current contents of the Plugins folder. ...
bool CallHookProjectileHitEntity(cProjectileEntity &a_Projectile, cEntity &a_HitEntity)
bool CallHookPlayerOpeningWindow(cPlayer &a_Player, cWindow &a_Window)
bool CallHookPlayerFoodLevelChange(cPlayer &a_Player, int a_NewFoodLevel)
void RemovePluginConsoleCommands(cPlugin *a_Plugin)
Removes all console command bindings that the specified plugin has made.
bool CallHookBlockToPickups(cWorld &a_World, Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cBlockEntity *a_BlockEntity, const cEntity *a_Digger, const cItem *a_Tool, cItems &a_Pickups)
bool CallHookPlayerFished(cPlayer &a_Player, const cItems &a_Reward)
bool CallHookPluginMessage(cClientHandle &a_Client, const AString &a_Channel, const AString &a_Message)
std::map< AString, cCommandReg > CommandMap
bool CallHookDisconnect(cClientHandle &a_Client, const AString &a_Reason)
void UnloadPlugin(const AString &a_PluginFolder)
Queues the specified plugin to be unloaded in the next call to Tick().
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)
Interface that must be provided by any class that implements a command handler, either in-game or con...
void AddHook(cPlugin *a_Plugin, int a_HookType)
Adds the plugin to the list of plugins called for the specified hook type.
bool CallHookCraftingNoRecipe(cPlayer &a_Player, cCraftingGrid &a_Grid, cCraftingRecipe &a_Recipe)
unsigned char BLOCKTYPE
The datatype used by blockdata.
virtual ~cPluginManager()
ePluginStatus
Defines the status of a single plugin - whether it is loaded, disabled or errored.
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 CallHookPlayerLeftClick(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status)
bool IsConsoleCommandBound(const AString &a_Command)
Returns true if the console command is in the command map.
void ReloadPlugins()
Schedules a reload of the plugins to happen within the next call to Tick().
AStringVector GetFoldersToLoad(cSettingsRepositoryInterface &a_Settings)
Returns the folders that are specified in the settings ini to load plugins from.
size_t GetNumLoadedPlugins(void) const
Returns the number of plugins that are psLoaded.
bool CallHookWeatherChanging(cWorld &a_World, eWeather &a_NewWeather)
bool BindCommand(const AString &a_Command, cPlugin *a_Plugin, cCommandHandlerPtr a_Handler, const AString &a_Permission, const AString &a_HelpString)
Binds a command to the specified handler.
cDeadlockDetect & m_DeadlockDetect
The deadlock detect in which all plugins should track their CSs.
void TabCompleteCommand(const AString &a_Text, AStringVector &a_Results, cPlayer *a_Player)
Appends all commands beginning with a_Text (case-insensitive) into a_Results.
static bool IsValidHookType(int a_HookType)
Returns true if the specified hook type is within the allowed range.
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)
void UnloadPluginsNow(void)
Unloads all plugins.
void RemovePlugin(const AString &a_PluginName)
Removes the plugin of the specified name from the internal structures and deletes its object...
bool CallHookServerPing(cClientHandle &a_ClientHandle, AString &a_ServerDescription, int &a_OnlinePlayersCount, int &a_MaxPlayersCount, AString &a_Favicon)
bool CallHookEntityChangedWorld(cEntity &a_Entity, cWorld &a_World)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
bool BindConsoleCommand(const AString &a_Command, cPlugin *a_Plugin, cCommandHandlerPtr a_Handler, const AString &a_HelpString)
Binds a console command to the specified handler.
bool CallHookKilled(cEntity &a_Victim, TakeDamageInfo &a_TDI, AString &a_DeathMessage)
bool CallHookHopperPushingItem(cWorld &a_World, cHopperEntity &a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems &a_DstEntity, int a_DstSlotNum)
bool CallHookBrewingCompleting(cWorld &a_World, cBrewingstandEntity &a_Brewingstand)
bool CallHookSpawningMonster(cWorld &a_World, cMonster &a_Monster)
static cPluginManager * Get(void)
Returns the instance of the Plugin Manager (there is only ever one)
bool LoadPlugin(const AString &a_PluginFolder)
Loads the plugin from the specified plugin folder.
bool CallHookPlayerAnimation(cPlayer &a_Player, int a_Animation)
bool CallHookEntityChangingWorld(cEntity &a_Entity, cWorld &a_World)
void RemovePluginCommands(cPlugin *a_Plugin)
Removes all command bindings that the specified plugin has made.
bool CallHookChunkUnloading(cWorld &a_World, int a_ChunkX, int a_ChunkZ)
void Tick(float a_Dt)
Called each tick, calls the plugins' OnTick hook, as well as processes plugin events (addition...
bool CallHookChunkGenerated(cWorld &a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc *a_ChunkDesc)
bool CallHookSpawnedEntity(cWorld &a_World, cEntity &a_Entity)
AString GetPluginFolderName(const AString &a_PluginName)
Returns the name of the folder (cPlugin::GetFolderName()) from which the specified plugin was loaded...
bool CallHookPlayerRightClickingEntity(cPlayer &a_Player, cEntity &a_Entity)
std::vector< AString > AStringVector
bool DoWithPlugin(const AString &a_PluginName, cPluginCallback a_Callback)
Calls the specified callback with the plugin object of the specified plugin.
bool CallHookPreCrafting(cPlayer &a_Player, cCraftingGrid &a_Grid, cCraftingRecipe &a_Recipe)
bool CallHookTakeDamage(cEntity &a_Receiver, TakeDamageInfo &a_TDI)
bool CallHookPlayerPlacingBlock(cPlayer &a_Player, const sSetBlock &a_BlockChange)
bool CallHookExecuteCommand(cPlayer *a_Player, const AStringVector &a_Split, const AString &a_EntireCommand, CommandResult &a_Result)
bool CallHookHopperPullingItem(cWorld &a_World, cHopperEntity &a_Hopper, int a_DstSlotNum, cBlockEntityWithItems &a_SrcEntity, int a_SrcSlotNum)
bool CallHookEntityAddEffect(cEntity &a_Entity, int a_EffectType, int a_EffectDurationTicks, int a_EffectIntensity, double a_DistanceModifier)
virtual ~cCommandEnumCallback()
AString GetCommandPermission(const AString &a_Command)
Returns the permission needed for the specified command; empty string if command not found...
bool CallHookPlayerDestroyed(cPlayer &a_Player)
bool CallHookChunkAvailable(cWorld &a_World, int a_ChunkX, int a_ChunkZ)
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 CallHookPlayerTossingItem(cPlayer &a_Player)
bool CallHookPlayerPlacedBlock(cPlayer &a_Player, const sSetBlock &a_BlockChange)
CommandResult ExecuteCommand(cPlayer &a_Player, const AString &a_Command)
Executes the command, as if it was requested by a_Player.
std::shared_ptr< cCommandHandler > cCommandHandlerPtr
bool CallHookPlayerSpawned(cPlayer &a_Player)
std::map< int, cPluginManager::PluginList > HookMap
bool IsCommandBound(const AString &a_Command)
Returns true if the command is in the command map.
std::map< AString, AString > AStringMap
A string dictionary, used for key-value pairs.
bool m_bReloadPlugins
If set to true, all the plugins will be reloaded within the next call to Tick().
void InsertDefaultPlugins(cSettingsRepositoryInterface &a_Settings)
Handles writing default plugins if 'Plugins' key not found using a settings repo expected to be intia...
bool CallHookKilling(cEntity &a_Victim, cEntity *a_Killer, TakeDamageInfo &a_TDI)
bool ExecuteConsoleCommand(const AStringVector &a_Split, cCommandOutputCallback &a_Output, const AString &a_Command)
Executes the command split into a_Split, as if it was given on the console.
void ReloadPluginsNow(void)
Reloads all plugins, defaulting to settings.ini for settings location.
bool CallHookPlayerShooting(cPlayer &a_Player)
cCommandHandlerPtr m_Handler
The root of the object hierarchy.
bool CallHookWorldStarted(cWorld &a_World)
cCriticalSection m_CSPluginsToUnload
Protects m_PluginsToUnload against multithreaded access.
size_t GetNumPlugins() const
Returns the number of all plugins in m_Plugins (includes disabled, unloaded and errored plugins)...
The plugin is enabled in settings.ini but has failed to load.
eExplosionSource
The source of an explosion.
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 CallHookPlayerJoined(cPlayer &a_Player)
static AString GetPluginsPath(void)
Returns the path where individual plugins' folders are expected.
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
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 CallHookLoginForge(cClientHandle &a_Client, AStringMap &a_Mods)
bool CallHookSpawningEntity(cWorld &a_World, cEntity &a_Entity)
std::shared_ptr< cPlugin > cPluginPtr
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)
cPluginManager(cDeadlockDetect &a_DeadlockDetect)
virtual ~cCommandHandler()
std::vector< cPluginPtr > cPluginPtrs
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)
CommandResult ForceExecuteCommand(cPlayer &a_Player, const AString &a_Command)
Executes the command, as if it was requested by a_Player.
bool CallHookEntityTeleport(cEntity &a_Entity, const Vector3d &a_OldPosition, const Vector3d &a_NewPosition)
bool CallHookPlayerFishing(cPlayer &a_Player, cItems a_Reward)
bool CallHookPlayerBreakingBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
bool CallHookWeatherChanged(cWorld &a_World)
The plugin is enabled in settings.ini but has been unloaded (by a command).
bool CallHookPostCrafting(cPlayer &a_Player, cCraftingGrid &a_Grid, cCraftingRecipe &a_Recipe)
bool CallHookPlayerEating(cPlayer &a_Player)
bool CallHookBrewingCompleted(cWorld &a_World, cBrewingstandEntity &a_Brewingstand)
bool GenericCallHook(PluginHook a_HookName, HookFunction a_HookFunction)
Calls a_HookFunction on each plugin registered to the hook HookName.
bool CallHookPlayerMoving(cPlayer &a_Player, const Vector3d &a_OldPosition, const Vector3d &a_NewPosition)
cPluginPtrs m_Plugins
All plugins that have been found in the Plugins folder.
CommandMap m_ConsoleCommands
bool CallHookChunkUnloaded(cWorld &a_World, int a_ChunkX, int a_ChunkZ)
bool CallHookWorldTick(cWorld &a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec)
bool CallHookProjectileHitBlock(cProjectileEntity &a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d &a_BlockHitPos)
bool CallHookHandshake(cClientHandle &a_ClientHandle, const AString &a_Username)
bool ForEachConsoleCommand(cCommandEnumCallback &a_Callback)
Calls a_Callback for each bound console command, returns true if all commands were enumerated...
The plugin has been loaded before, but after a folder refresh it is no longer present.
bool IsPluginLoaded(const AString &a_PluginName)
Returns true if the specified plugin is loaded.
bool CallHookCollectingPickup(cPlayer &a_Player, cPickup &a_Pickup)
AStringVector m_PluginsToUnload
FolderNames of plugins that should be unloaded.
Interface for a callback that receives command output The Out() function is called for any output the...
virtual bool Command(const AString &a_Command, const cPlugin *a_Plugin, const AString &a_Permission, const AString &a_HelpString)=0
Called for each command; return true to abort enumeration For console commands, a_Permission is not u...
bool CallHookChunkGenerating(cWorld &a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc *a_ChunkDesc)
bool CallHookSpawnedMonster(cWorld &a_World, cMonster &a_Monster)
Used as a callback for enumerating bound commands.
std::list< cPlugin * > PluginList
bool CallHookPlayerBrokenBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
The plugin has been loaded successfully.
bool CallHookLogin(cClientHandle &a_Client, UInt32 a_ProtocolVersion, const AString &a_Username)
bool CallHookPluginsLoaded(void)
The plugin is disabled in settings.ini.
bool ForEachCommand(cCommandEnumCallback &a_Callback)
Calls a_Callback for each bound command, returns true if all commands were enumerated.
This class bridges a vector of cItem for safe access via Lua.
bool ForEachPlugin(cPluginCallback a_Callback)
Calls the specified callback for each plugin in m_Plugins.
bool CallHookChat(cPlayer &a_Player, AString &a_Message)
CommandResult HandleCommand(cPlayer &a_Player, const AString &a_Command, bool a_ShouldCheckPermissions)
Tries to match a_Command to the internal table of commands, if a match is found, the corresponding pl...