1
0

InfoReg: Fixed EntireCommand handling for MultiCommandHandler().

The EntireCommand wasn't propagated into the handlers.
This commit is contained in:
Mattes D 2015-05-10 21:33:49 +02:00
parent cbb1eff17a
commit 87f1cf5622

View File

@ -43,21 +43,21 @@ end
--- This is a generic command callback used for handling multicommands' parent commands --- 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 -- 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 -- 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 function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_Level, a_EntireCommand)
local Verb = a_Split[a_Level + 1]; local Verb = a_Split[a_Level + 1]
if (Verb == nil) then if (Verb == nil) then
-- No verb was specified. If there is a handler for the upper level command, call it: -- No verb was specified. If there is a handler for the upper level command, call it:
if (a_CmdInfo.Handler ~= nil) then 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 end
-- Let the player know they need to give a subcommand: -- 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) 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); ListSubcommands(a_Player, a_CmdInfo.Subcommands, a_CmdString)
return true; return true
end end
-- A verb was specified, look it up in the subcommands table: -- 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 (Subcommand == nil) then
if (a_Level > 1) then if (a_Level > 1) then
-- This is a true subcommand, display the message and make MCS think the command was handled -- 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 else
a_Player:SendMessage("The " .. a_CmdString .. " command doesn't support verb " .. Verb) a_Player:SendMessage("The " .. a_CmdString .. " command doesn't support verb " .. Verb)
end end
return true; return true
end end
-- This is a top-level command, let MCS handle the unknown message -- This is a top-level command, let MCS handle the unknown message
return false; return false;
@ -76,22 +76,22 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_
-- Check the permission: -- Check the permission:
if (a_Player ~= nil) then if (a_Player ~= nil) then
if not(a_Player:HasPermission(Subcommand.Permission or "")) then if not(a_Player:HasPermission(Subcommand.Permission or "")) then
a_Player:SendMessage("You don't have permission to execute this command"); a_Player:SendMessage("You don't have permission to execute this command")
return true; return true
end end
end end
-- If the handler is not valid, check the next sublevel: -- If the handler is not valid, check the next sublevel:
if (Subcommand.Handler == nil) then if (Subcommand.Handler == nil) then
if (Subcommand.Subcommands == nil) then if (Subcommand.Subcommands == nil) then
LOG("Cannot find handler for command " .. a_CmdString .. " " .. Verb); LOG("Cannot find handler for command " .. a_CmdString .. " " .. Verb)
return false; return false
end 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 end
-- Execute: -- Execute:
return Subcommand.Handler(a_Split, a_Player); return Subcommand.Handler(a_Split, a_Player, a_EntireCommand)
end end
@ -104,39 +104,39 @@ function RegisterPluginInfoCommands()
-- The a_Prefix param already contains the space after the previous command -- 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 -- 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) 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 -- A table that will hold aliases to subcommands temporarily, during subcommand iteration
local AliasTable = {} local AliasTable = {}
-- Iterate through the subcommands, register them, and accumulate aliases: -- Iterate through the subcommands, register them, and accumulate aliases:
for cmd, info in pairs(a_Subcommands) do for cmd, info in pairs(a_Subcommands) do
local CmdName = a_Prefix .. cmd; local CmdName = a_Prefix .. cmd
local Handler = info.Handler; local Handler = info.Handler
-- Provide a special handler for multicommands: -- Provide a special handler for multicommands:
if (info.Subcommands ~= nil) then if (info.Subcommands ~= nil) then
Handler = function(a_Split, a_Player) Handler = function(a_Split, a_Player, a_EntireCommand)
return MultiCommandHandler(a_Split, a_Player, CmdName, info, a_Level); return MultiCommandHandler(a_Split, a_Player, CmdName, info, a_Level, a_EntireCommand)
end end
end end
if (Handler == nil) then 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 else
local HelpString; local HelpString
if (info.HelpString ~= nil) then if (info.HelpString ~= nil) then
HelpString = " - " .. info.HelpString; HelpString = " - " .. info.HelpString
else else
HelpString = ""; HelpString = ""
end end
cPluginManager.BindCommand(CmdName, info.Permission or "", Handler, HelpString); cPluginManager.BindCommand(CmdName, info.Permission or "", Handler, HelpString)
-- Register all aliases for the command: -- Register all aliases for the command:
if (info.Alias ~= nil) then if (info.Alias ~= nil) then
if (type(info.Alias) == "string") then if (type(info.Alias) == "string") then
info.Alias = {info.Alias}; info.Alias = {info.Alias}
end end
for idx, alias in ipairs(info.Alias) do 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, -- 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 -- 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. -- than the one we're currently iterating and join after the iterating.
@ -147,7 +147,7 @@ function RegisterPluginInfoCommands()
-- Recursively register any subcommands: -- Recursively register any subcommands:
if (info.Subcommands ~= nil) then 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 -- for cmd, info - a_Subcommands[] end -- for cmd, info - a_Subcommands[]
@ -159,7 +159,7 @@ function RegisterPluginInfoCommands()
end end
-- Loop through all commands in the plugin info, register each: -- Loop through all commands in the plugin info, register each:
RegisterSubcommands("", g_PluginInfo.Commands, 1); RegisterSubcommands("", g_PluginInfo.Commands, 1)
end end
@ -171,26 +171,26 @@ function RegisterPluginInfoConsoleCommands()
-- A sub-function that registers all subcommands of a single command, using the command's Subcommands table -- 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 -- The a_Prefix param already contains the space after the previous command
local function RegisterSubcommands(a_Prefix, a_Subcommands, a_Level) 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 for cmd, info in pairs(a_Subcommands) do
local CmdName = a_Prefix .. cmd; local CmdName = a_Prefix .. cmd
local Handler = info.Handler local Handler = info.Handler
if (Handler == nil) then if (Handler == nil) then
Handler = function(a_Split) Handler = function(a_Split, a_EntireCommand)
return MultiCommandHandler(a_Split, nil, CmdName, info, a_Level); return MultiCommandHandler(a_Split, nil, CmdName, info, a_Level, a_EntireCommand)
end end
end end
cPluginManager.BindConsoleCommand(CmdName, Handler, info.HelpString or ""); cPluginManager.BindConsoleCommand(CmdName, Handler, info.HelpString or "")
-- Recursively register any subcommands: -- Recursively register any subcommands:
if (info.Subcommands ~= nil) then 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 end
end end
-- Loop through all commands in the plugin info, register each: -- Loop through all commands in the plugin info, register each:
RegisterSubcommands("", g_PluginInfo.ConsoleCommands, 1); RegisterSubcommands("", g_PluginInfo.ConsoleCommands, 1)
end end