1
0

Corrected check for level of subcommand and fixed multiple levels not working (#3758)

* Corrected check for level of subcommand
A message instead of an error is printed, if the sub command is unknown

* Multiple levels of sub commands now works, too
This commit is contained in:
Lukas Pioch 2017-06-12 12:59:46 +02:00 committed by GitHub
parent 486ae0e832
commit 9b0eb118b3

View File

@ -59,7 +59,7 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_
-- A verb was specified, look it up in the subcommands table:
local Subcommand = a_CmdInfo.Subcommands[Verb]
if (Subcommand == nil) then
if (a_Level > 1) then
if (a_Level + 1 > 1) then
-- This is a true subcommand, display the message and make MCS think the command was handled
-- Otherwise we get weird behavior: for "/cmd verb" we get "unknown command /cmd" although "/cmd" is valid
if (a_Player == nil) then
@ -81,13 +81,14 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_
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
end
-- First check if the subcommand has subcommands
if (Subcommand.Subcommands ~= nil) then
-- Next sublevel
return MultiCommandHandler(a_Split, a_Player, a_CmdString .. " " .. Verb, Subcommand, a_Level + 1, a_EntireCommand)
elseif (Subcommand.Handler == nil) then
-- Subcommand has no subcommands and the handler is not found, report error
LOGWARNING("Cannot find handler for command " .. a_CmdString .. " " .. Verb)
return false
end
-- Execute: