HOOK_PLUGINS_LOADED


Index:
Articles
Classes
Hooks

Quick navigation:
BLOCK_SPREAD
BLOCK_TO_PICKUPS
BREWING_COMPLETED
BREWING_COMPLETING
CHAT
CHUNK_AVAILABLE
CHUNK_GENERATED
CHUNK_GENERATING
CHUNK_UNLOADED
CHUNK_UNLOADING
COLLECTING_PICKUP
CRAFTING_NO_RECIPE
DISCONNECT
DROPSPENSE
ENTITY_ADD_EFFECT
ENTITY_CHANGED_WORLD
ENTITY_CHANGING_WORLD
ENTITY_TELEPORT
EXECUTE_COMMAND
EXPLODED
EXPLODING
HANDSHAKE
HOPPER_PULLING_ITEM
HOPPER_PUSHING_ITEM
KILLED
KILLING
LOGIN
LOGIN_FORGE
PLAYER_ANIMATION
PLAYER_BREAKING_BLOCK
PLAYER_BROKEN_BLOCK
PLAYER_CROUCHED
PLAYER_DESTROYED
PLAYER_EATING
PLAYER_FISHED
PLAYER_FISHING
PLAYER_FOOD_LEVEL_CHANGE
PLAYER_JOINED
PLAYER_LEFT_CLICK
PLAYER_MOVING
PLAYER_OPENING_WINDOW
PLAYER_PLACED_BLOCK
PLAYER_PLACING_BLOCK
PLAYER_RIGHT_CLICK
PLAYER_RIGHT_CLICKING_ENTITY
PLAYER_SHOOTING
PLAYER_SPAWNED
PLAYER_TOSSING_ITEM
PLAYER_USED_BLOCK
PLAYER_USED_ITEM
PLAYER_USING_BLOCK
PLAYER_USING_ITEM
PLUGINS_LOADED
PLUGIN_MESSAGE
POST_CRAFTING
PRE_CRAFTING
PROJECTILE_HIT_BLOCK
PROJECTILE_HIT_ENTITY
SERVER_PING
SPAWNED_ENTITY
SPAWNED_MONSTER
SPAWNING_ENTITY
SPAWNING_MONSTER
TAKE_DAMAGE
TICK
UPDATED_SIGN
UPDATING_SIGN
WEATHER_CHANGED
WEATHER_CHANGING
WORLD_STARTED
WORLD_TICK

This callback gets called when the server finishes loading and initializing plugins. This is the perfect occasion for a plugin to query other plugins through cPluginManager:GetPlugin() and possibly start communicating with them using the cPlugin:Call() function.


Callback function

The default name for the callback function is OnPluginsLoaded. It has the following signature:

function MyOnPluginsLoaded()

Parameters:

NameTypeNotes

The return value is ignored, all registered callbacks are called.


Code examples

Registering the callback

cPluginManager:AddHook(cPluginManager.HOOK_PLUGINS_LOADED, MyOnPluginsLoaded);

CoreMessaging

This example shows how to implement the CoreMessaging functionality - messages to players will be sent through the Core plugin, formatted by that plugin. As a fallback for when the Core plugin is not present, the messages are sent directly by this code, unformatted.

-- These are the fallback functions used when the Core is not present:
local function SendMessageFallback(a_Player, a_Message)
	a_Player:SendMessage(a_Message);
end

local function SendMessageSuccessFallback(a_Player, a_Message)
	a_Player:SendMessage(a_Message);
end

local function SendMessageFailureFallback(a_Player, a_Message)
	a_Player:SendMessage(a_Message);
end

-- These three "variables" will hold the actual functions to call.
-- By default they are initialized to the Fallback variants,
-- but will be redirected to Core when all plugins load
SendMessage        = SendMessageFallback;
SendMessageSuccess = SendMessageSuccessFallback;
SendMessageFailure = SendMessageFailureFallback;

-- The callback tries to connect to the Core
-- If successful, overwrites the three functions with Core ones
local function OnPluginsLoaded()
	local CorePlugin = cPluginManager:Get():GetPlugin("Core");
	if (CorePlugin == nil) then
		-- The Core is not loaded, keep the Fallback functions
		return;
	end
	
	-- Overwrite the three functions with Core functionality:
	SendMessage = function(a_Player, a_Message)
		CorePlugin:Call("SendMessage", a_Player, a_Message);
	end
	SendMessageSuccess = function(a_Player, a_Message)
		CorePlugin:Call("SendMessageSuccess", a_Player, a_Message);
	end
	SendMessageFailure = function(a_Player, a_Message)
		CorePlugin:Call("SendMessageFailure", a_Player, a_Message);
	end
end

-- Global scope, register the callback:
cPluginManager.AddHook(cPluginManager.HOOK_PLUGINS_LOADED, CoreMessagingPluginsLoaded);


-- Usage, anywhere else in the plugin:
SendMessageFailure(
	a_Player,
	"Cannot teleport to player, the destination player " .. PlayerName .. " was not found"
);
				
Generated by APIDump on 2022-10-28 17:00:47, Build ID Unknown, Commit approx: 21ec3ebe26bff24b5fc6d96f86a441c9c9628247