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