16 #define LUA_PLUGIN_INSTANCE_VAR_NAME "_CuberiteInternal_PluginInstance"
62 virtual bool Load(
void)
override;
63 virtual void Unload(
void)
override;
65 virtual void Tick(
float a_Dt)
override;
80 virtual bool OnEntityAddEffect (
cEntity & a_Entity,
int a_EffectType,
int a_EffectDurationTicks,
int a_EffectIntensity,
double a_DistanceModifier)
override;
84 virtual bool OnExploded (
cWorld & a_World,
double a_ExplosionSize,
bool a_CanCauseFire,
double a_X,
double a_Y,
double a_Z,
eExplosionSource a_Source,
void * a_SourceData)
override;
85 virtual bool OnExploding (
cWorld & a_World,
double & a_ExplosionSize,
bool & a_CanCauseFire,
double a_X,
double a_Y,
double a_Z,
eExplosionSource a_Source,
void * a_SourceData)
override;
109 virtual bool OnPlayerRightClick (
cPlayer & a_Player,
int a_BlockX,
int a_BlockY,
int a_BlockZ,
eBlockFace a_BlockFace,
int a_CursorX,
int a_CursorY,
int a_CursorZ)
override;
116 virtual bool OnPlayerUsedItem (
cPlayer & a_Player,
int a_BlockX,
int a_BlockY,
int a_BlockZ,
eBlockFace a_BlockFace,
int a_CursorX,
int a_CursorY,
int a_CursorZ)
override;
118 virtual bool OnPlayerUsingItem (
cPlayer & a_Player,
int a_BlockX,
int a_BlockY,
int a_BlockZ,
eBlockFace a_BlockFace,
int a_CursorX,
int a_CursorY,
int a_CursorZ)
override;
136 virtual bool OnWorldTick (
cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec)
override;
152 const AString & a_FunctionName,
159 template <
typename FnT,
typename... Args>
160 bool Call(FnT a_Fn, Args && ... a_Args)
192 template <
typename... Args>
198 for (
auto & hook: hooks)
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.
Encapsulates a Lua state and provides some syntactic sugar for common operations.
std::unique_ptr< cCallback > cCallbackPtr
Provides a RAII-style locking for the LuaState.
cPlugin(const AString &a_FolderName)
Creates a new instance.
virtual bool OnPlayerFished(cPlayer &a_Player, const cItems &a_Reward, const int ExperienceAmount) override
virtual bool OnChat(cPlayer &a_Player, AString &a_Message) override
virtual bool OnExploded(cWorld &a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void *a_SourceData) override
virtual bool OnSpawningMonster(cWorld &a_World, cMonster &a_Monster) override
virtual bool OnChunkAvailable(cWorld &a_World, int a_ChunkX, int a_ChunkZ) override
bool CanAddOldStyleHook(int a_HookType)
Returns true if the plugin contains the function for the specified hook type, using the old-style reg...
virtual void Tick(float a_Dt) override
virtual bool OnPostCrafting(cPlayer &a_Player, cCraftingGrid &a_Grid, cCraftingRecipe &a_Recipe) override
virtual bool OnWorldStarted(cWorld &a_World) override
virtual bool OnChunkGenerated(cWorld &a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc *a_ChunkDesc) override
virtual bool OnLogin(cClientHandle &a_Client, UInt32 a_ProtocolVersion, const AString &a_Username) override
virtual bool OnPlayerMoving(cPlayer &a_Player, const Vector3d &a_OldPosition, const Vector3d &a_NewPosition, bool a_PreviousIsOnGround) override
virtual bool OnSpawnedEntity(cWorld &a_World, cEntity &a_Entity) override
virtual bool OnPlayerDestroyed(cPlayer &a_Player) override
void Close(void)
Releases all Lua references, notifies and removes all m_Resettables[] and closes the m_LuaState.
virtual bool OnCollectingPickup(cPlayer &a_Player, cPickup &a_Pickup) override
static const char * GetHookFnName(int a_HookType)
Returns the name of Lua function that should handle the specified hook type in the older (#121) API.
virtual bool OnKilled(cEntity &a_Victim, TakeDamageInfo &a_TDI, AString &a_DeathMessage) override
virtual ~cPluginLua() override
virtual void OnDisable(void) override
Called as the last call into the plugin before it is unloaded.
bool AddHookCallback(int a_HookType, cLuaState::cCallbackPtr &&a_Callback)
Adds a Lua callback to be called for the specified hook.
virtual bool OnDisconnect(cClientHandle &a_Client, const AString &a_Reason) override
virtual bool OnPlayerSpawned(cPlayer &a_Player) override
virtual bool OnPreCrafting(cPlayer &a_Player, cCraftingGrid &a_Grid, cCraftingRecipe &a_Recipe) override
virtual bool OnPluginsLoaded(void) override
virtual bool OnSpawnedMonster(cWorld &a_World, cMonster &a_Monster) override
virtual bool OnPlayerRightClickingEntity(cPlayer &a_Player, cEntity &a_Entity) override
virtual bool OnKilling(cEntity &a_Victim, cEntity *a_Killer, TakeDamageInfo &a_TDI) override
virtual bool OnWeatherChanging(cWorld &a_World, eWeather &a_NewWeather) override
std::map< int, cLuaCallbacks > cHookMap
Maps hook types into arrays of Lua function references to call for each hook type.
virtual bool OnServerPing(cClientHandle &a_ClientHandle, AString &a_ServerDescription, int &a_OnlinePlayersCount, int &a_MaxPlayersCount, AString &a_Favicon) override
virtual bool OnBrewingCompleting(cWorld &a_World, cBrewingstandEntity &a_BrewingstandEntity) override
int CallFunctionFromForeignState(const AString &a_FunctionName, cLuaState &a_ForeignState, int a_ParamStart, int a_ParamEnd)
Calls a function in this plugin's LuaState with parameters copied over from a_ForeignState.
virtual bool OnExploding(cWorld &a_World, double &a_ExplosionSize, bool &a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void *a_SourceData) override
virtual bool OnPlayerJoined(cPlayer &a_Player) override
virtual bool OnHopperPushingItem(cWorld &a_World, cHopperEntity &a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems &a_DstEntity, int a_DstSlotNum) override
virtual bool OnPlayerOpeningWindow(cPlayer &a_Player, cWindow &a_Window) override
virtual bool OnPlayerAnimation(cPlayer &a_Player, int a_Animation) override
virtual bool OnPlayerUsedItem(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
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) override
virtual bool OnEntityChangedWorld(cEntity &a_Entity, cWorld &a_World) override
virtual bool OnPlayerBrokenBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
virtual bool OnLoginForge(cClientHandle &a_Client, const AStringMap &a_Mods) override
virtual bool OnPluginMessage(cClientHandle &a_Client, const AString &a_Channel, ContiguousByteBufferView a_Message) override
virtual bool OnPlayerUsingItem(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
cPluginLua(const AString &a_PluginDirectory, cDeadlockDetect &a_DeadlockDetect)
virtual bool OnHopperPullingItem(cWorld &a_World, cHopperEntity &a_Hopper, int a_DstSlotNum, cBlockEntityWithItems &a_SrcEntity, int a_SrcSlotNum) override
cLuaState m_LuaState
The plugin's Lua state.
virtual bool OnEntityAddEffect(cEntity &a_Entity, int a_EffectType, int a_EffectDurationTicks, int a_EffectIntensity, double a_DistanceModifier) override
virtual bool OnSpawningEntity(cWorld &a_World, cEntity &a_Entity) override
virtual bool OnPlayerFoodLevelChange(cPlayer &a_Player, int a_NewFoodLevel) override
virtual bool OnProjectileHitEntity(cProjectileEntity &a_Projectile, cEntity &a_HitEntity) override
bool Call(FnT a_Fn, Args &&... a_Args)
Call a Lua function residing in the plugin.
virtual bool OnPlayerEating(cPlayer &a_Player) override
bool CallSimpleHooks(int a_HookType, Args &&... a_Args)
Calls a hook that has the simple format - single bool return value specifying whether the chain shoul...
virtual bool OnBlockToPickups(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) override
virtual bool OnPlayerUsedBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
virtual bool OnChunkUnloading(cWorld &a_World, int a_ChunkX, int a_ChunkZ) override
virtual bool OnPlayerShooting(cPlayer &a_Player) override
virtual bool OnChunkUnloaded(cWorld &a_World, int a_ChunkX, int a_ChunkZ) override
virtual bool OnPlayerUsingBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
virtual bool OnHandshake(cClientHandle &a_Client, const AString &a_Username) override
virtual bool OnEntityChangingWorld(cEntity &a_Entity, cWorld &a_World) override
virtual bool OnPlayerPlacingBlock(cPlayer &a_Player, const sSetBlock &a_BlockChange) override
virtual bool OnPlayerBreakingBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
virtual bool OnEntityTeleport(cEntity &a_Entity, const Vector3d &a_OldPosition, const Vector3d &a_NewPosition) override
virtual bool OnProjectileHitBlock(cProjectileEntity &a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d &a_BlockHitPos) override
virtual bool OnExecuteCommand(cPlayer *a_Player, const AStringVector &a_Split, const AString &a_EntireCommand, cPluginManager::CommandResult &a_Result) override
std::vector< cLuaState::cCallbackPtr > cLuaCallbacks
Provides an array of Lua function references.
void ClearWebTabs(void)
Removes all WebTabs currently registered for this plugin from the WebAdmin.
virtual bool OnCraftingNoRecipe(cPlayer &a_Player, cCraftingGrid &a_Grid, cCraftingRecipe &a_Recipe) override
virtual bool OnWeatherChanged(cWorld &a_World) override
virtual bool OnPlayerFishing(cPlayer &a_Player, cItems &a_Reward, int &ExperienceAmount) override
virtual bool OnChunkGenerating(cWorld &a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc *a_ChunkDesc) override
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) override
virtual bool OnPlayerCrouched(cPlayer &a_Player) override
virtual bool Load(void) override
Loads and initializes the plugin.
virtual bool OnPlayerLeftClick(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, char a_Status) override
cDeadlockDetect & m_DeadlockDetect
The DeadlockDetect object to which the plugin's CS is tracked.
virtual bool OnTakeDamage(cEntity &a_Receiver, TakeDamageInfo &a_TakeDamageInfo) override
virtual bool OnBlockSpread(cWorld &a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) override
Calls the specified hook with the params given.
cHookMap m_HookMap
Hooks that the plugin has registered.
virtual bool OnPlayerPlacedBlock(cPlayer &a_Player, const sSetBlock &a_BlockChange) override
virtual bool OnWorldTick(cWorld &a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec) override
virtual bool OnPlayerRightClick(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
virtual void Unload(void) override
Unloads the plugin.
virtual bool OnBrewingCompleted(cWorld &a_World, cBrewingstandEntity &a_BrewingstandEntity) override
virtual bool OnDropSpense(cWorld &a_World, cDropSpenserEntity &a_DropSpenser, int a_SlotNum) override
virtual bool OnPlayerTossingItem(cPlayer &a_Player) override
A RAII-style mutex lock for accessing the internal LuaState.
cLuaState & operator()(void)
cOperation(cPluginLua &a_Plugin)
cLuaState::cLock m_Lock
RAII lock for the Lua state.
This class bridges a vector of cItem for safe access via Lua.