InfoReg: Fixed cPluginManager usage.
This commit is contained in:
parent
7f8a4eb726
commit
26769c6113
@ -14,7 +14,7 @@ local function ListSubcommands(a_Player, a_Subcommands, a_CmdString)
|
|||||||
else
|
else
|
||||||
a_Player:SendMessage("The " .. a_CmdString .. " command requires another verb:")
|
a_Player:SendMessage("The " .. a_CmdString .. " command requires another verb:")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Enum all the subcommands:
|
-- Enum all the subcommands:
|
||||||
local Verbs = {}
|
local Verbs = {}
|
||||||
for cmd, info in pairs(a_Subcommands) do
|
for cmd, info in pairs(a_Subcommands) do
|
||||||
@ -23,7 +23,7 @@ local function ListSubcommands(a_Player, a_Subcommands, a_CmdString)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.sort(Verbs)
|
table.sort(Verbs)
|
||||||
|
|
||||||
-- Send the list:
|
-- Send the list:
|
||||||
if (a_Player == nil) then
|
if (a_Player == nil) then
|
||||||
for idx, verb in ipairs(Verbs) do
|
for idx, verb in ipairs(Verbs) do
|
||||||
@ -55,7 +55,7 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_
|
|||||||
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
|
||||||
@ -72,7 +72,7 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_
|
|||||||
-- 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;
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 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
|
||||||
@ -80,7 +80,7 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_
|
|||||||
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
|
||||||
@ -89,7 +89,7 @@ local function MultiCommandHandler(a_Split, a_Player, a_CmdString, a_CmdInfo, a_
|
|||||||
end
|
end
|
||||||
return MultiCommandHandler(a_Split, a_Player, a_CmdString .. " " .. Verb, Subcommand, a_Level + 1, a_EntireCommand)
|
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, a_EntireCommand)
|
return Subcommand.Handler(a_Split, a_Player, a_EntireCommand)
|
||||||
end
|
end
|
||||||
@ -105,10 +105,10 @@ function RegisterPluginInfoCommands()
|
|||||||
-- 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
|
||||||
@ -119,7 +119,7 @@ function RegisterPluginInfoCommands()
|
|||||||
return MultiCommandHandler(a_Split, a_Player, CmdName, info, a_Level, a_EntireCommand)
|
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
|
||||||
@ -129,14 +129,14 @@ function RegisterPluginInfoCommands()
|
|||||||
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.
|
||||||
@ -144,20 +144,20 @@ function RegisterPluginInfoCommands()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end -- else (if Handler == nil)
|
end -- else (if Handler == nil)
|
||||||
|
|
||||||
-- 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[]
|
||||||
|
|
||||||
-- Add the subcommand aliases that were off-loaded during registration:
|
-- Add the subcommand aliases that were off-loaded during registration:
|
||||||
for alias, info in pairs(AliasTable) do
|
for alias, info in pairs(AliasTable) do
|
||||||
a_Subcommands[alias] = info
|
a_Subcommands[alias] = info
|
||||||
end
|
end
|
||||||
AliasTable = {}
|
AliasTable = {}
|
||||||
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
|
||||||
@ -172,7 +172,7 @@ function RegisterPluginInfoConsoleCommands()
|
|||||||
-- 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
|
||||||
@ -181,14 +181,14 @@ function RegisterPluginInfoConsoleCommands()
|
|||||||
return MultiCommandHandler(a_Split, nil, CmdName, info, a_Level, a_EntireCommand)
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user