16 #define LUA_PLUGIN_NAME_VAR_NAME "_CuberiteInternal_PluginName" 17 #define LUA_PLUGIN_INSTANCE_VAR_NAME "_CuberiteInternal_PluginInstance" 63 virtual bool Load(
void)
override;
64 virtual void Unload(
void)
override;
66 virtual void Tick(
float a_Dt)
override;
81 virtual bool OnEntityAddEffect (
cEntity & a_Entity,
int a_EffectType,
int a_EffectDurationTicks,
int a_EffectIntensity,
double a_DistanceModifier)
override;
85 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;
86 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;
103 virtual bool OnPlayerLeftClick (
cPlayer & a_Player,
int a_BlockX,
int a_BlockY,
int a_BlockZ,
char a_BlockFace,
char a_Status)
override;
108 virtual bool OnPlayerRightClick (
cPlayer & a_Player,
int a_BlockX,
int a_BlockY,
int a_BlockZ,
char a_BlockFace,
int a_CursorX,
int a_CursorY,
int a_CursorZ)
override;
114 virtual bool OnPlayerUsedBlock (
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)
override;
115 virtual bool OnPlayerUsedItem (
cPlayer & a_Player,
int a_BlockX,
int a_BlockY,
int a_BlockZ,
char a_BlockFace,
int a_CursorX,
int a_CursorY,
int a_CursorZ)
override;
117 virtual bool OnPlayerUsingItem (
cPlayer & a_Player,
int a_BlockX,
int a_BlockY,
int a_BlockZ,
char a_BlockFace,
int a_CursorX,
int a_CursorY,
int a_CursorZ)
override;
135 virtual bool OnWorldTick (
cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec)
override;
151 const AString & a_FunctionName,
158 template <
typename FnT,
typename... Args>
159 bool Call(FnT a_Fn, Args && ... a_Args)
191 template <
typename... Args>
195 auto & hooks = m_HookMap[a_HookType];
197 for (
auto & hook: hooks)
std::vector< cLuaState::cCallbackPtr > cLuaCallbacks
Provides an array of Lua function references.
virtual bool OnPlayerPlacedBlock(cPlayer &a_Player, const sSetBlock &a_BlockChange) 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 OnBrewingCompleted(cWorld &a_World, cBrewingstandEntity &a_BrewingstandEntity) override
virtual bool OnWeatherChanging(cWorld &a_World, eWeather &a_NewWeather) override
virtual bool OnChunkUnloaded(cWorld &a_World, int a_ChunkX, int a_ChunkZ) 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.
void Close(void)
Releases all Lua references, notifies and removes all m_Resettables[] and closes the m_LuaState...
virtual void OnDisable(void) override
Called as the last call into the plugin before it is unloaded.
virtual bool OnChunkAvailable(cWorld &a_World, int a_ChunkX, int a_ChunkZ) override
virtual bool OnWorldStarted(cWorld &a_World) 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 OnPlayerOpeningWindow(cPlayer &a_Player, cWindow &a_Window) override
unsigned char BLOCKTYPE
The datatype used by blockdata.
void ClearWebTabs(void)
Removes all WebTabs currently registered for this plugin from the WebAdmin.
virtual bool OnEntityChangedWorld(cEntity &a_Entity, cWorld &a_World) override
virtual ~cPluginLua() override
virtual bool OnPlayerFished(cPlayer &a_Player, const cItems &a_Reward) override
virtual bool OnKilling(cEntity &a_Victim, cEntity *a_Killer, TakeDamageInfo &a_TDI) override
virtual bool OnEntityAddEffect(cEntity &a_Entity, int a_EffectType, int a_EffectDurationTicks, int a_EffectIntensity, double a_DistanceModifier) override
virtual bool OnSpawnedEntity(cWorld &a_World, cEntity &a_Entity) override
cLuaState & operator()(void)
cLuaState::cLock m_Lock
RAII lock for the Lua state.
virtual bool OnPlayerRightClickingEntity(cPlayer &a_Player, cEntity &a_Entity) 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.
virtual bool OnWeatherChanged(cWorld &a_World) override
virtual bool OnPlayerShooting(cPlayer &a_Player) override
cDeadlockDetect & m_DeadlockDetect
The DeadlockDetect object to which the plugin's CS is tracked.
virtual bool OnPlayerTossingItem(cPlayer &a_Player) override
bool AddHookCallback(int a_HookType, cLuaState::cCallbackPtr &&a_Callback)
Adds a Lua callback to be called for the specified hook.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
virtual bool OnPluginMessage(cClientHandle &a_Client, const AString &a_Channel, const AString &a_Message) override
Encapsulates a Lua state and provides some syntactic sugar for common operations. ...
virtual bool OnCraftingNoRecipe(cPlayer &a_Player, cCraftingGrid &a_Grid, cCraftingRecipe &a_Recipe) override
A RAII-style mutex lock for accessing the internal LuaState.
virtual bool OnServerPing(cClientHandle &a_ClientHandle, AString &a_ServerDescription, int &a_OnlinePlayersCount, int &a_MaxPlayersCount, AString &a_Favicon) override
virtual bool OnPlayerLeftClick(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) override
virtual bool OnLogin(cClientHandle &a_Client, UInt32 a_ProtocolVersion, const AString &a_Username) 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 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
cLuaState m_LuaState
The plugin's Lua state.
virtual bool OnChunkGenerating(cWorld &a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc *a_ChunkDesc) override
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
cHookMap m_HookMap
Hooks that the plugin has registered.
std::vector< AString > AStringVector
virtual bool OnPlayerJoined(cPlayer &a_Player) 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 OnHopperPullingItem(cWorld &a_World, cHopperEntity &a_Hopper, int a_DstSlotNum, cBlockEntityWithItems &a_SrcEntity, int a_SrcSlotNum) override
virtual bool OnKilled(cEntity &a_Victim, TakeDamageInfo &a_TDI, AString &a_DeathMessage) override
std::map< int, cLuaCallbacks > cHookMap
Maps hook types into arrays of Lua function references to call for each hook type.
virtual bool OnPlayerUsingBlock(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) override
virtual bool Load(void) override
Loads and initializes the plugin.
virtual bool OnPreCrafting(cPlayer &a_Player, cCraftingGrid &a_Grid, cCraftingRecipe &a_Recipe) override
virtual bool OnCollectingPickup(cPlayer &a_Player, cPickup &a_Pickup) override
virtual bool OnPlayerEating(cPlayer &a_Player) override
std::unique_ptr< cCallback > cCallbackPtr
cOperation(cPluginLua &a_Plugin)
virtual bool OnSpawnedMonster(cWorld &a_World, cMonster &a_Monster) override
std::map< AString, AString > AStringMap
A string dictionary, used for key-value pairs.
virtual bool OnPluginsLoaded(void) override
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 OnPlayerFoodLevelChange(cPlayer &a_Player, int a_NewFoodLevel) override
virtual bool OnChunkGenerated(cWorld &a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc *a_ChunkDesc) override
virtual bool OnHopperPushingItem(cWorld &a_World, cHopperEntity &a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems &a_DstEntity, int a_DstSlotNum) override
virtual bool OnPlayerUsingItem(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
eExplosionSource
The source of an explosion.
cPluginLua(const AString &a_PluginDirectory, cDeadlockDetect &a_DeadlockDetect)
virtual bool OnProjectileHitEntity(cProjectileEntity &a_Projectile, cEntity &a_HitEntity) override
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
virtual bool OnPlayerRightClick(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
virtual bool OnPostCrafting(cPlayer &a_Player, cCraftingGrid &a_Grid, cCraftingRecipe &a_Recipe) override
virtual bool OnSpawningMonster(cWorld &a_World, cMonster &a_Monster) override
virtual bool OnSpawningEntity(cWorld &a_World, cEntity &a_Entity) override
virtual void Tick(float a_Dt) override
Provides a RAII-style locking for the LuaState.
virtual bool OnHandshake(cClientHandle &a_Client, const AString &a_Username) 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 bool OnWorldTick(cWorld &a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec) override
virtual bool OnChat(cPlayer &a_Player, AString &a_Message) override
virtual bool OnPlayerMoving(cPlayer &a_Player, const Vector3d &a_OldPosition, const Vector3d &a_NewPosition) override
virtual bool OnDisconnect(cClientHandle &a_Client, const AString &a_Reason) override
virtual void Unload(void) override
Unloads the plugin.
virtual bool OnPlayerUsedBlock(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) override
virtual bool OnTakeDamage(cEntity &a_Receiver, TakeDamageInfo &a_TakeDamageInfo) override
bool Call(FnT a_Fn, Args &&...a_Args)
Call a Lua function residing in the plugin.
virtual bool OnLoginForge(cClientHandle &a_Client, const AStringMap &a_Mods) override
virtual bool OnPlayerAnimation(cPlayer &a_Player, int a_Animation) override
virtual bool OnPlayerSpawned(cPlayer &a_Player) override
virtual bool OnEntityTeleport(cEntity &a_Entity, const Vector3d &a_OldPosition, const Vector3d &a_NewPosition) override
virtual bool OnPlayerBrokenBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
virtual bool OnEntityChangingWorld(cEntity &a_Entity, cWorld &a_World) override
virtual bool OnExecuteCommand(cPlayer *a_Player, const AStringVector &a_Split, const AString &a_EntireCommand, cPluginManager::CommandResult &a_Result) override
virtual bool OnPlayerFishing(cPlayer &a_Player, cItems &a_Reward) 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 OnPlayerPlacingBlock(cPlayer &a_Player, const sSetBlock &a_BlockChange) override
virtual bool OnPlayerBreakingBlock(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override
This class bridges a vector of cItem for safe access via Lua.
virtual bool OnChunkUnloading(cWorld &a_World, int a_ChunkX, int a_ChunkZ) override
virtual bool OnPlayerDestroyed(cPlayer &a_Player) override
virtual bool OnBrewingCompleting(cWorld &a_World, cBrewingstandEntity &a_BrewingstandEntity) override
virtual bool OnPlayerUsedItem(cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override