From aa3450808d237d0a8c6e8cbf02c59759f951a6d1 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Wed, 6 May 2015 19:11:25 +0100 Subject: Properly fix the docs for FindAndDoWithPlayer. Removed F accidentially added. Made the two FindAndDoWithPlayers documentation consistent. --- MCServer/Plugins/APIDump/APIDesc.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index ad86837e3..79340434d 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -8,7 +8,7 @@ g_APIDesc = { Classes = -F --[[ + --[[ -- What the APIDump plugin understands / how to document stuff: ExampleClassName = { @@ -2046,7 +2046,7 @@ a_Player:OpenWindow(Window); BroadcastChatSuccess = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtSuccess. Use for success messages." }, BroadcastChatWarning = { Params = "MessageText", Return = "", Notes = "Broadcasts the specified message to all players, with its message type set to mtWarning. Use for concerning events, such as plugin reload etc." }, CreateAndInitializeWorld = { Params = "WorldName", Return = "{{cWorld|cWorld}}", Notes = "Creates a new world and initializes it. If there is a world whith the same name it returns nil.

NOTEThis function is currently unsafe, do not use!" }, - FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "", Notes = "Calls the given callback function for all players with names partially (or fully) matching the name string provided.
This function is not case-sensitive." }, + FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "bool", Notes = "Calls the given callback function for the player with the name best matching the name string provided.
This function is case-insensitive and will match partial names.
Returns false if player not found or there is ambiguity, true otherwise. The CallbackFunction has the following signature:
function Callback({{cPlayer|Player}})
" }, DoWithPlayerByUUID = { Params = "PlayerUUID, CallbackFunction", Return = "bool", Notes = "If there is the player with the uuid, calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature:
function Callback({{cPlayer|Player}})
The function returns false if the player was not found, or whatever bool value the callback returned if the player was found." }, ForEachPlayer = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each player. The callback function has the following signature:
function Callback({{cPlayer|cPlayer}})
" }, ForEachWorld = { Params = "CallbackFunction", Return = "", Notes = "Calls the given callback function for each world. The callback function has the following signature:
function Callback({{cWorld|cWorld}})
" }, @@ -2330,7 +2330,7 @@ local CompressedString = cStringCompression.CompressStringGZIP("DataToCompress") { Params = "BlockX, BlockY, BlockZ, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, without waking up the simulators or replacing the block entities for the previous block type. Do not use if the block being replaced has a block entity tied to it!" }, { Params = "{{Vector3i|BlockCoords}}, BlockType, BlockMeta", Return = "", Notes = "Sets the block at the specified coords, without waking up the simulators or replacing the block entities for the previous block type. Do not use if the block being replaced has a block entity tied to it!" }, }, - FindAndDoWithPlayer = { Params = "PlayerNameHint, CallbackFunction", Return = "bool", Notes = "If there is a player of a name similar to the specified name (weighted-match), calls the CallbackFunction with the {{cPlayer}} parameter representing the player. The CallbackFunction has the following signature:
function Callback({{cPlayer|Player}})
The function returns false if the player was not found, or whatever bool value the callback returned if the player was found. Note that the name matching is very loose, so it is a good idea to check the player name in the callback function." }, + FindAndDoWithPlayer = { Params = "PlayerName, CallbackFunction", Return = "bool", Notes = "Calls the given callback function for the player with the name best matching the name string provided.
This function is case-insensitive and will match partial names.
Returns false if player not found or there is ambiguity, true otherwise. The CallbackFunction has the following signature:
function Callback({{cPlayer|Player}})
" }, ForEachBlockEntityInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each block entity in the chunk. Returns true if all block entities in the chunk have been processed (including when there are zero block entities), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature:
function Callback({{cBlockEntity|BlockEntity}})
The callback should return false or no value to continue with the next block entity, or true to abort the enumeration. Use {{tolua}}.cast() to cast the Callback's BlockEntity parameter to the correct {{cBlockEntity}} descendant." }, ForEachChestInChunk = { Params = "ChunkX, ChunkZ, CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each chest in the chunk. Returns true if all chests in the chunk have been processed (including when there are zero chests), or false if the callback has aborted the enumeration by returning true. The CallbackFunction has the following signature:
function Callback({{cChestEntity|ChestEntity}})
The callback should return false or no value to continue with the next chest, or true to abort the enumeration." }, ForEachEntity = { Params = "CallbackFunction", Return = "bool", Notes = "Calls the specified callback for each entity in the loaded world. Returns true if all the entities have been processed (including when there are zero entities), or false if the callback function has aborted the enumeration by returning true. The callback function has the following signature:
function Callback({{cEntity|Entity}})
The callback should return false or no value to continue with the next entity, or true to abort the enumeration." }, -- cgit v1.2.3 From fee690a3d1412860b19447b2b390d3521adae7c6 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Thu, 7 May 2015 23:02:18 +0200 Subject: Fixed inter-plugin calls. When an inter-plugin call failed due to function not found, the server would maul the LuaState and "yield". Fixes #1959. --- MCServer/Plugins/Debuggers/Debuggers.lua | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index bffc6e844..a49f8b5a6 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -54,7 +54,7 @@ function Initialize(a_Plugin) -- TestBlockAreas() -- TestSQLiteBindings() -- TestExpatBindings() - -- TestPluginCalls() + TestPluginCalls() TestBlockAreasString() TestStringBase64() @@ -157,26 +157,18 @@ function TestPluginCalls() -- The Split parameter should be a table, but it is not used in that function anyway, -- so we can get away with passing nil to it. - -- Use the old, deprecated and unsafe method: - local Core = cPluginManager:Get():GetPlugin("Core") - if (Core ~= nil) then - LOGINFO("Calling Core::ReturnColorFromChar() the old-fashioned way...") - local Gray = Core:Call("ReturnColorFromChar", nil, "8") - if (Gray ~= cChatColor.Gray) then - LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "")) - else - LOGINFO("Call succeeded") - end - end - - -- Use the new method: - LOGINFO("Calling Core::ReturnColorFromChar() the recommended way...") - local Gray = cPluginManager:CallPlugin("Core", "ReturnColorFromChar", nil, "8") + LOG("Debuggers: Calling NoSuchPlugin.FnName()...") + cPluginManager:CallPlugin("NoSuchPlugin", "FnName", "SomeParam") + LOG("Debuggers: Calling Core.NoSuchFunction()...") + cPluginManager:CallPlugin("Core", "NoSuchFunction", "SomeParam") + LOG("Debuggers: Calling Core.ReturnColorFromChar(..., \"8\")...") + local Gray = cPluginManager:CallPlugin("Core", "ReturnColorFromChar", "split", "8") if (Gray ~= cChatColor.Gray) then - LOGWARNING("Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "")) + LOGWARNING("Debuggers: Call failed, exp " .. cChatColor.Gray .. ", got " .. (Gray or "")) else - LOGINFO("Call succeeded") + LOG("Debuggers: Call succeeded") end + LOG("Debuggers: Inter-plugin calls done.") end -- cgit v1.2.3 From 05db1904f93fb2c218e1855924d4cddadba941ce Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Fri, 8 May 2015 15:13:58 +0100 Subject: Fixed syntax error --- MCServer/Plugins/APIDump/APIDesc.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua index 79340434d..2c26ccecc 100644 --- a/MCServer/Plugins/APIDump/APIDesc.lua +++ b/MCServer/Plugins/APIDump/APIDesc.lua @@ -8,6 +8,7 @@ g_APIDesc = { Classes = + { --[[ -- What the APIDump plugin understands / how to document stuff: ExampleClassName = -- cgit v1.2.3 From 3853db94e28b584678394ad468e1405036532e78 Mon Sep 17 00:00:00 2001 From: jammet Date: Fri, 8 May 2015 17:06:39 +0200 Subject: Corrected hopper recipe --- MCServer/crafting.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MCServer') diff --git a/MCServer/crafting.txt b/MCServer/crafting.txt index 1e1f06156..e7d11ab92 100644 --- a/MCServer/crafting.txt +++ b/MCServer/crafting.txt @@ -304,7 +304,7 @@ Dropper = Cobblestone, 1:1, 2:1, 3:1, 1:2, 1:3, 3:2, 3:3 | Hopper, 2:2 Repeater = Stone, 1:2, 2:2, 3:2 | RedstoneTorchOn, 1:1, 3:1 | RedstoneDust, 2:1 Comparator = RedstoneTorchOn, 2:1, 1:2, 3:2 | NetherQuartz, 2:2 | Stone, 1:3, 2:3, 3:3 DaylightSensor = Glass, 1:1, 2:1, 3:1 | NetherQuartz, 1:2, 2:2, 3:2 | Woodslab, 1:3, 2:3, 3:3 -Hopper = Ironbars, 1:1, 3:1, 1:2, 3:2, 2:3 | Chest, 2:2 +Hopper = IronIngot, 1:1, 3:1, 1:2, 3:2, 2:3 | Chest, 2:2 Piston = Planks^-1, 1:1, 2:1, 3:1 | RedstoneDust, 2:3 | Cobblestone, 1:2, 3:2, 1:3, 3:3 | IronIngot, 2:2 StickyPiston = Piston, * | SlimeBall, * RedstoneLamp = RedstoneDust, 2:1, 1:2, 3:2, 2:3 | Glowstone, 2:2 -- cgit v1.2.3 From cbb1eff17a085f57472f67cbe3682232fb3a4aeb Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 10 May 2015 21:29:06 +0200 Subject: Added the EntireCommand parameter to HOOK_EXECUTE_COMMAND. Fixes #1996. --- MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua b/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua index dadc4e94f..d7a5d383d 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua @@ -16,7 +16,8 @@ return Params = { { Name = "Player", Type = "{{cPlayer}}", Notes = "For in-game commands, the player who has sent the message. For console commands, nil" }, - { Name = "Command", Type = "table of strings", Notes = "The command and its parameters, broken into a table by spaces" }, + { Name = "CommandSplit", Type = "array-table of strings", Notes = "The command and its parameters, broken into a table by spaces" }, + { Name = "EntireCommand", Type = "string", Notes = "The entire command as a single string" }, }, Returns = [[ If the plugin returns true, the command will be blocked and none of the remaining hook handlers will -- cgit v1.2.3 From 87f1cf5622eb5fa6d7b6378166c8cc6926aaaa72 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 10 May 2015 21:33:49 +0200 Subject: InfoReg: Fixed EntireCommand handling for MultiCommandHandler(). The EntireCommand wasn't propagated into the handlers. --- MCServer/Plugins/InfoReg.lua | 68 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/InfoReg.lua b/MCServer/Plugins/InfoReg.lua index e34b79564..cc075c0b8 100644 --- a/MCServer/Plugins/InfoReg.lua +++ b/MCServer/Plugins/InfoReg.lua @@ -43,21 +43,21 @@ end --- This is a generic command callback used for handling multicommands' parent commands -- For example, if there are "/gal save" and "/gal load" commands, this callback handles the "/gal" command -- It is used for both console and in-game commands; the console version has a_Player set to nil -local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_Level) - local Verb = a_Split[a_Level + 1]; +local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_Level, a_EntireCommand) + local Verb = a_Split[a_Level + 1] if (Verb == nil) then -- No verb was specified. If there is a handler for the upper level command, call it: if (a_CmdInfo.Handler ~= nil) then - return a_CmdInfo.Handler(a_Split, a_Player); + return a_CmdInfo.Handler(a_Split, a_Player, a_EntireCommand) end -- Let the player know they need to give a subcommand: assert(type(a_CmdInfo.Subcommands) == "table", "Info.lua error: There is no handler for command \"" .. a_CmdString .. "\" and there are no subcommands defined at level " .. a_Level) - ListSubcommands(a_Player, a_CmdInfo.Subcommands, a_CmdString); - return true; + ListSubcommands(a_Player, a_CmdInfo.Subcommands, a_CmdString) + return true end -- A verb was specified, look it up in the subcommands table: - local Subcommand = a_CmdInfo.Subcommands[Verb]; + local Subcommand = a_CmdInfo.Subcommands[Verb] if (Subcommand == nil) then if (a_Level > 1) then -- This is a true subcommand, display the message and make MCS think the command was handled @@ -67,7 +67,7 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_ else a_Player:SendMessage("The " .. a_CmdString .. " command doesn't support verb " .. Verb) end - return true; + return true end -- This is a top-level command, let MCS handle the unknown message return false; @@ -76,22 +76,22 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_ -- Check the permission: if (a_Player ~= nil) then if not(a_Player:HasPermission(Subcommand.Permission or "")) then - a_Player:SendMessage("You don't have permission to execute this command"); - return true; + a_Player:SendMessage("You don't have permission to execute this command") + return true end end -- If the handler is not valid, check the next sublevel: if (Subcommand.Handler == nil) then if (Subcommand.Subcommands == nil) then - LOG("Cannot find handler for command " .. a_CmdString .. " " .. Verb); - return false; + LOG("Cannot find handler for command " .. a_CmdString .. " " .. Verb) + return false end - return MultiCommandHandler(a_Split, a_Player, a_CmdString .. " " .. Verb, Subcommand, a_Level + 1); + return MultiCommandHandler(a_Split, a_Player, a_CmdString .. " " .. Verb, Subcommand, a_Level + 1, a_EntireCommand) end -- Execute: - return Subcommand.Handler(a_Split, a_Player); + return Subcommand.Handler(a_Split, a_Player, a_EntireCommand) end @@ -104,39 +104,39 @@ function RegisterPluginInfoCommands() -- The a_Prefix param already contains the space after the previous command -- a_Level is the depth of the subcommands being registered, with 1 being the top level command local function RegisterSubcommands(a_Prefix, a_Subcommands, a_Level) - assert(a_Subcommands ~= nil); + assert(a_Subcommands ~= nil) -- A table that will hold aliases to subcommands temporarily, during subcommand iteration local AliasTable = {} -- Iterate through the subcommands, register them, and accumulate aliases: for cmd, info in pairs(a_Subcommands) do - local CmdName = a_Prefix .. cmd; - local Handler = info.Handler; + local CmdName = a_Prefix .. cmd + local Handler = info.Handler -- Provide a special handler for multicommands: if (info.Subcommands ~= nil) then - Handler = function(a_Split, a_Player) - return MultiCommandHandler(a_Split, a_Player, CmdName, info, a_Level); + Handler = function(a_Split, a_Player, a_EntireCommand) + return MultiCommandHandler(a_Split, a_Player, CmdName, info, a_Level, a_EntireCommand) end end if (Handler == nil) then - LOGWARNING(g_PluginInfo.Name .. ": Invalid handler for command " .. CmdName .. ", command will not be registered."); + LOGWARNING(g_PluginInfo.Name .. ": Invalid handler for command " .. CmdName .. ", command will not be registered.") else - local HelpString; + local HelpString if (info.HelpString ~= nil) then - HelpString = " - " .. info.HelpString; + HelpString = " - " .. info.HelpString else - HelpString = ""; + HelpString = "" end - cPluginManager.BindCommand(CmdName, info.Permission or "", Handler, HelpString); + cPluginManager.BindCommand(CmdName, info.Permission or "", Handler, HelpString) -- Register all aliases for the command: if (info.Alias ~= nil) then if (type(info.Alias) == "string") then - info.Alias = {info.Alias}; + info.Alias = {info.Alias} end for idx, alias in ipairs(info.Alias) do - cPluginManager.BindCommand(a_Prefix .. alias, info.Permission or "", Handler, HelpString); + cPluginManager.BindCommand(a_Prefix .. alias, info.Permission or "", Handler, HelpString) -- Also copy the alias's info table as a separate subcommand, -- so that MultiCommandHandler() handles it properly. Need to off-load into a separate table -- than the one we're currently iterating and join after the iterating. @@ -147,7 +147,7 @@ function RegisterPluginInfoCommands() -- Recursively register any subcommands: if (info.Subcommands ~= nil) then - RegisterSubcommands(a_Prefix .. cmd .. " ", info.Subcommands, a_Level + 1); + RegisterSubcommands(a_Prefix .. cmd .. " ", info.Subcommands, a_Level + 1) end end -- for cmd, info - a_Subcommands[] @@ -159,7 +159,7 @@ function RegisterPluginInfoCommands() end -- Loop through all commands in the plugin info, register each: - RegisterSubcommands("", g_PluginInfo.Commands, 1); + RegisterSubcommands("", g_PluginInfo.Commands, 1) end @@ -171,26 +171,26 @@ function RegisterPluginInfoConsoleCommands() -- A sub-function that registers all subcommands of a single command, using the command's Subcommands table -- The a_Prefix param already contains the space after the previous command local function RegisterSubcommands(a_Prefix, a_Subcommands, a_Level) - assert(a_Subcommands ~= nil); + assert(a_Subcommands ~= nil) for cmd, info in pairs(a_Subcommands) do - local CmdName = a_Prefix .. cmd; + local CmdName = a_Prefix .. cmd local Handler = info.Handler if (Handler == nil) then - Handler = function(a_Split) - return MultiCommandHandler(a_Split, nil, CmdName, info, a_Level); + Handler = function(a_Split, a_EntireCommand) + return MultiCommandHandler(a_Split, nil, CmdName, info, a_Level, a_EntireCommand) end end - cPluginManager.BindConsoleCommand(CmdName, Handler, info.HelpString or ""); + cPluginManager.BindConsoleCommand(CmdName, Handler, info.HelpString or "") -- Recursively register any subcommands: if (info.Subcommands ~= nil) then - RegisterSubcommands(a_Prefix .. cmd .. " ", info.Subcommands, a_Level + 1); + RegisterSubcommands(a_Prefix .. cmd .. " ", info.Subcommands, a_Level + 1) end end end -- Loop through all commands in the plugin info, register each: - RegisterSubcommands("", g_PluginInfo.ConsoleCommands, 1); + RegisterSubcommands("", g_PluginInfo.ConsoleCommands, 1) end -- cgit v1.2.3 From 6c53abed23011423e95a30d2ad50bbe95aca365e Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 10 May 2015 21:46:25 +0200 Subject: Call HOOK_EXECUTE_COMMAND even for unknown console commands. This allows plugins such as Aliases to intercept even unknown commands. --- MCServer/Plugins/APIDump/Hooks/OnChat.lua | 3 ++- MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/Hooks/OnChat.lua b/MCServer/Plugins/APIDump/Hooks/OnChat.lua index d98df008a..a15d09cc7 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnChat.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnChat.lua @@ -7,7 +7,8 @@ return Desc = [[ A plugin may implement an OnChat() function and register it as a Hook to process chat messages from the players. The function is then called for every in-game message sent from any player. Note that - commands are handled separately using a command framework API. + registered in-game commands are not sent through this hook. Use the + {{OnExecuteCommand|HOOK_EXECUTE_COMMAND}} to intercept registered in-game commands. ]], Params = { { Name = "Player", Type = "{{cPlayer}}", Notes = "The player who sent the message" }, diff --git a/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua b/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua index d7a5d383d..d920a83ba 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua @@ -2,7 +2,10 @@ return { HOOK_EXECUTE_COMMAND = { - CalledWhen = "A player executes an in-game command, or the admin issues a console command. Note that built-in console commands are exempt to this hook - they are always performed and the hook is not called.", + CalledWhen = [[ + A player executes an in-game command, or the admin issues a console command. Note that built-in + console commands are exempt to this hook - they are always performed and the hook is not called. + ]], DefaultFnName = "OnExecuteCommand", -- also used as pagename Desc = [[ A plugin may implement a callback for this hook to intercept both in-game commands executed by the @@ -11,7 +14,12 @@ return server.

If the command is in-game, the first parameter to the hook function is the {{cPlayer|player}} who's - executing the command. If the command comes from the server console, the first parameter is nil. + executing the command. If the command comes from the server console, the first parameter is nil.

+

+ The server calls this hook even for unregistered (unknown) console commands. However, it doesn't call + the hook for unregistered in-game commands, simply because there's no way to distinguish between a + command and a chat message. If a plugin needs to intercept unknown in-game commands, it should use the + {{OnChat|HOOK_CHAT}} hook. ]], Params = { -- cgit v1.2.3 From 693ffb689c1b970e97cca1bb7d3982695e277eca Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 10 May 2015 22:51:16 +0200 Subject: Exported cPluginManager:ExecuteConsoleCommand() to Lua API. Fixes #1999. --- MCServer/Plugins/APIDump/Classes/Plugins.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/Classes/Plugins.lua b/MCServer/Plugins/APIDump/Classes/Plugins.lua index ff5d4a180..87f864950 100644 --- a/MCServer/Plugins/APIDump/Classes/Plugins.lua +++ b/MCServer/Plugins/APIDump/Classes/Plugins.lua @@ -68,6 +68,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage); CallPlugin = { Params = "PluginName, FunctionName, [FunctionArgs...]", Return = "[FunctionRets]", Notes = "(STATIC) Calls the specified function in the specified plugin, passing all the given arguments to it. If it succeeds, it returns all the values returned by that function. If it fails, returns no value at all. Note that only strings, numbers, bools, nils and classes can be used for parameters and return values; tables and functions cannot be copied across plugins." }, DoWithPlugin = { Params = "PluginName, CallbackFn", Return = "bool", Notes = "(STATIC) Calls the CallbackFn for the specified plugin, if found. A plugin can be found even if it is currently unloaded, disabled or errored, the callback should check the plugin status. If the plugin is not found, this function returns false, otherwise it returns the bool value that the callback has returned. The CallbackFn has the following signature:

function ({{cPlugin|Plugin}})
" }, ExecuteCommand = { Params = "{{cPlayer|Player}}, CommandStr", Return = "{{cPluginManager#CommandResult|CommandResult}}", Notes = "Executes the command as if given by the specified Player. Checks permissions." }, + ExecuteConsoleCommand = { Params = "CommandStr", Return = "bool, string", Notes = "Executes the console command as if given by the admin on the console. If the command is successfully executed, returns true and the text that would be output to the console normally. On error it returns false and an error message." }, FindPlugins = { Params = "", Return = "", Notes = "OBSOLETE, use RefreshPluginList() instead"}, ForceExecuteCommand = { Params = "{{cPlayer|Player}}, CommandStr", Return = "{{cPluginManager#CommandResult|CommandResult}}", Notes = "Same as ExecuteCommand, but doesn't check permissions" }, ForEachCommand = { Params = "CallbackFn", Return = "bool", Notes = "Calls the CallbackFn function for each command that has been bound using BindCommand(). The CallbackFn has the following signature:
function(Command, Permission, HelpString)
If the callback returns true, the enumeration is aborted and this API function returns false; if it returns false or no value, the enumeration continues with the next command, and the API function returns true." }, -- cgit v1.2.3 From dd10ffb63ad98cf2f4df2141a8fd64c21d414529 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 10 May 2015 23:11:30 +0200 Subject: OnExecuteCommand hook can override the command result (crXXX). --- MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua b/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua index d920a83ba..79b7bb055 100644 --- a/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua +++ b/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua @@ -28,9 +28,11 @@ return { Name = "EntireCommand", Type = "string", Notes = "The entire command as a single string" }, }, Returns = [[ - If the plugin returns true, the command will be blocked and none of the remaining hook handlers will - be called. If the plugin returns false, MCServer calls all the remaining hook handlers and finally - the command will be executed. + If the plugin returns false, MCServer calls all the remaining hook handlers and finally the command + will be executed. If the plugin returns true, the none of the remaining hook handlers will be called. + In this case the plugin can return a second value, specifying whether what the command result should + be set to, one of the {{cPluginManager#CommandResult|CommandResult}} constants. If not + provided, the value defaults to crBlocked. ]], }, -- HOOK_EXECUTE_COMMAND } -- cgit v1.2.3 From 66945e4847bed70dc4a8d724292753b79d4231a9 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 10 May 2015 23:14:25 +0200 Subject: APIDump: Added linkification to hook return values. --- MCServer/Plugins/APIDump/main_APIDump.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index 013ec7bef..4ca06b974 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -285,7 +285,7 @@ local function WriteHtmlHook(a_Hook, a_HookNav) for _, param in ipairs(a_Hook.Params) do f:write("", param.Name, "", LinkifyString(param.Type, HookName), "", LinkifyString(param.Notes, HookName), "\n"); end - f:write("\n

" .. (a_Hook.Returns or "") .. "

\n\n"); + f:write("\n

" .. LinkifyString(a_Hook.Returns or "", HookName) .. "

\n\n"); f:write([[

Code examples

Registering the callback

]]); f:write("
\n");
 	f:write([[cPluginManager:AddHook(cPluginManager.]] .. a_Hook.Name .. ", My" .. a_Hook.DefaultFnName .. [[);]]);
-- 
cgit v1.2.3


From f36b00f4d496cb90c8c77d0e6ae570502f3199ae Mon Sep 17 00:00:00 2001
From: Mattes D 
Date: Wed, 13 May 2015 18:31:01 +0200
Subject: All in-game commands go through the OnExecuteCommand hook.

Everything that has a slash at the beginning, doesn't matter if it is a registered command or not.
---
 MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

(limited to 'MCServer')

diff --git a/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua b/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua
index 79b7bb055..db7eb97d1 100644
--- a/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua
+++ b/MCServer/Plugins/APIDump/Hooks/OnExecuteCommand.lua
@@ -16,10 +16,9 @@ return
 			If the command is in-game, the first parameter to the hook function is the {{cPlayer|player}} who's
 			executing the command. If the command comes from the server console, the first parameter is nil.

- The server calls this hook even for unregistered (unknown) console commands. However, it doesn't call - the hook for unregistered in-game commands, simply because there's no way to distinguish between a - command and a chat message. If a plugin needs to intercept unknown in-game commands, it should use the - {{OnChat|HOOK_CHAT}} hook. + The server calls this hook even for unregistered (unknown) console commands. It also calls the hook + for unknown in-game commands, as long as they begin with a slash ('/'). If a plugin needs to intercept + in-game chat messages not beginning with a slash, it should use the {{OnChat|HOOK_CHAT}} hook. ]], Params = { -- cgit v1.2.3 From 394192bdaf6bc285be8258ead6553c3cb4054d2f Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 13 May 2015 19:20:53 +0200 Subject: InfoDump: Added support for links. Also fixed processing of lists and list items. --- MCServer/Plugins/InfoDump.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index ab4dfd861..433827ce7 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -65,8 +65,12 @@ local function ForumizeString(a_Str) a_Str = a_Str:gsub("{%%p}", "\n\n") a_Str = a_Str:gsub("{%%b}", "[b]"):gsub("{%%/b}", "[/b]") a_Str = a_Str:gsub("{%%i}", "[i]"):gsub("{%%/i}", "[/i]") - a_Str = a_Str:gsub("{%%list}", "[list]"):gsub("{%%/list}", "[/list]") - a_Str = a_Str:gsub("{%%li}", "[*]"):gsub("{%%/li}", "") + a_Str = a_Str:gsub("{%%list}", "\n[list]"):gsub("{%%/list}", "[/list]") + a_Str = a_Str:gsub("{%%li}", "\n[*]"):gsub("{%%/li}", "\n") + + -- Process links: {%a LinkDestination}LinkText{%/a} + a_Str = a_Str:gsub("{%%a%s([^}]*)}([^{]*){%%/a}", "[url=%1]%2[/url]") + -- TODO: Other formatting return a_Str @@ -106,8 +110,12 @@ local function GithubizeString(a_Str) a_Str = a_Str:gsub("{%%p}", "\n\n") a_Str = a_Str:gsub("{%%b}", "**"):gsub("{%%/b}", "**") a_Str = a_Str:gsub("{%%i}", "*"):gsub("{%%/i}", "*") - a_Str = a_Str:gsub("{%%list}", ""):gsub("{%%/list}", "") - a_Str = a_Str:gsub("{%%li}", " - "):gsub("{%%/li}", "") + a_Str = a_Str:gsub("{%%list}", "\n"):gsub("{%%/list}", "\n") + a_Str = a_Str:gsub("{%%li}", "\n - "):gsub("{%%/li}", "") + + -- Process links: {%a LinkDestination}LinkText{%/a} + a_Str = a_Str:gsub("{%%a%s([^}]*)}([^{]*){%%/a}", "[%2](%1)") + -- TODO: Other formatting return a_Str -- cgit v1.2.3 From b34fd9c6d9a65987f3e0f55f33ddb03a89d8853f Mon Sep 17 00:00:00 2001 From: Mattes D Date: Wed, 13 May 2015 19:24:57 +0200 Subject: InfoDump: Added DownloadLocation to forum post generator. --- MCServer/Plugins/InfoDump.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/InfoDump.lua b/MCServer/Plugins/InfoDump.lua index 433827ce7..a715c9a18 100644 --- a/MCServer/Plugins/InfoDump.lua +++ b/MCServer/Plugins/InfoDump.lua @@ -600,7 +600,10 @@ local function DumpPluginInfoForum(a_PluginFolder, a_PluginInfo) DumpCommandsForum(a_PluginInfo, f) DumpPermissionsForum(a_PluginInfo, f) if (a_PluginInfo.SourceLocation ~= nil) then - f:write("[b][color=blue]Source:[/color] [url=", a_PluginInfo.SourceLocation, "]Link[/url][/b]") + f:write("\n[b]Source[/b]: ", a_PluginInfo.SourceLocation, "\n") + end + if (a_PluginInfo.DownloadLocation ~= nil) then + f:write("[b]Download[/b]: ", a_PluginInfo.DownloadLocation) end f:close() return true -- cgit v1.2.3 From 1f3f64fccd229a70b9f1b71cf4ecba8e764d98c9 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Sun, 17 May 2015 22:33:43 +0200 Subject: APIDump: Removed an unneeded global variable. --- MCServer/Plugins/APIDump/main_APIDump.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/main_APIDump.lua b/MCServer/Plugins/APIDump/main_APIDump.lua index 4ca06b974..e841922b6 100644 --- a/MCServer/Plugins/APIDump/main_APIDump.lua +++ b/MCServer/Plugins/APIDump/main_APIDump.lua @@ -971,7 +971,7 @@ end --- Writes a list of undocumented objects into a file local function ListUndocumentedObjects(API, UndocumentedHooks) - f = io.open("API/_undocumented.lua", "w"); + local f = io.open("API/_undocumented.lua", "w"); if (f ~= nil) then f:write("\n-- This is the list of undocumented API objects, automatically generated by APIDump\n\n"); f:write("g_APIDesc =\n{\n\tClasses =\n\t{\n"); -- cgit v1.2.3 From 9aced8cd856eb66b7ff136cc77bca32cb4901354 Mon Sep 17 00:00:00 2001 From: Lukas Pioch Date: Tue, 19 May 2015 06:34:40 +0200 Subject: Added OnEntityChangeWorld.lua and OnEntityChangedWorld.lua hooks to APIDump --- .../Plugins/APIDump/Hooks/OnEntityChangeWorld.lua | 29 ++++++++++++++++++++++ .../Plugins/APIDump/Hooks/OnEntityChangedWorld.lua | 28 +++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 MCServer/Plugins/APIDump/Hooks/OnEntityChangeWorld.lua create mode 100644 MCServer/Plugins/APIDump/Hooks/OnEntityChangedWorld.lua (limited to 'MCServer') diff --git a/MCServer/Plugins/APIDump/Hooks/OnEntityChangeWorld.lua b/MCServer/Plugins/APIDump/Hooks/OnEntityChangeWorld.lua new file mode 100644 index 000000000..25072ca5c --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnEntityChangeWorld.lua @@ -0,0 +1,29 @@ +return +{ + HOOK_ENTITY_CHANGE_WORLD = + { + CalledWhen = "Before a entity is changing the world.", + DefaultFnName = "OnEntityChangeWorld", -- also used as pagename + Desc = [[ + This hook is called before the server moves the {{cEntity|entity}} to the given world. Plugins may + refuse the changing of the entity to the new world.

+ See also the {{OnEntityChangedWorld|HOOK_ENTITY_CHANGED_WORLD}} hook for a similar hook is called after the + entity has been moved to the world. + ]], + Params = + { + { Name = "Entity", Type = "{{cEntity}}", Notes = "The entity that wants to change the world" }, + { Name = "World", Type = "{{cWorld}}", Notes = "The world to which the entity wants to change" }, + }, + Returns = [[ + If the function returns false or no value, the next plugin's callback is called. If the function + returns true, no other callback is called for this event and the change of the entity to the world is + cancelled. + ]], + }, -- HOOK_ENTITY_CHANGE_WORLD +} + + + + + diff --git a/MCServer/Plugins/APIDump/Hooks/OnEntityChangedWorld.lua b/MCServer/Plugins/APIDump/Hooks/OnEntityChangedWorld.lua new file mode 100644 index 000000000..00645c152 --- /dev/null +++ b/MCServer/Plugins/APIDump/Hooks/OnEntityChangedWorld.lua @@ -0,0 +1,28 @@ +return +{ + HOOK_ENTITY_CHANGED_WORLD = + { + CalledWhen = "After a entity has changed the world.", + DefaultFnName = "OnEntityChangedWorld", -- also used as pagename + Desc = [[ + This hook is called after the server has moved the {{cEntity|entity}} to the given world. This is an information-only + callback, the entity is already in the new world.

+ See also the {{OnEntityChangeWorld|HOOK_ENTITY_CHANGE_WORLD}} hook for a similar hook called before the + entity is moved to the new world. + ]], + Params = + { + { Name = "Entity", Type = "{{cEntity}}", Notes = "The entity that has changed the world" }, + { Name = "World", Type = "{{cWorld}}", Notes = "The world from which the entity has come" }, + }, + Returns = [[ + If the function returns false or no value, the next plugin's callback is called. If the function + returns true, no other callback is called for this event. + ]], + }, -- HOOK_ENTITY_CHANGED_WORLD +} + + + + + -- cgit v1.2.3