cmd
Functions:
register
cmd.register(command_name: string, permission: string, handler: function): cmd
command_name
string
Command name
permission
string
Permission. An empty string "" means no permission is required.
handler
function
A handler with sender and args as the argument.
Registers a new command. Returns an object cmd
representing a registered command.
exec
cmd.exec(command: string): boolean
command
string
The complete command string to be executed (does not need to include "/").
Execute a command.
Methods:
:add_args
cmd:add_args(position: number, args_table: table[, permission: string]): cmd
position
number
Position of the argument, counting from 1.
args_table
table
A table that contains the possible completion items (string list) at this position.
permission
string
Optional. View or use the permission nodes required for these completion items. The default is to inherit the permissions of the cmd itself.
Adds argument suggestions to a command. Returns the cmd
object itself. Allow chainable calls.
:add_args_for
cmd:add_args_for(position: number, previous_arg: string, args_table: table[, permission: string]): cmd
position
number
Position of the argument, counting from 1.
previous_arg
string
Pre argument of this argument
args_table
table
A table that contains the possible completion items (string list) at this position.
permission
string
Optional. View or use the permission nodes required for these completion items. The default is to inherit the permission of the pre agrument.
Adds argument suggestions to a command, but only if a previous argument is present. Returns the cmd
object itself. Allow chainable calls.
Example:
local test_cmd = cmd.register("test", "luagin.user", function(sender, args)
print("Executed command: /test " .. table.concat(args, " "))
print("Sender: " .. sender:get_name())
if args[1] == "reload" then
-- /test reload
reload()
end
if args[1] == "admin" then
-- /test admin
if #args >= 2 and args[2] == "tp" then
-- /test admin tp
if #args == 5 then
-- /test admin tp <x> <y> <z>
tp(args[3], args[4], args[5])
else
print_chat("Usage: /test admin tp <x> <y> <z>", sender:get_name())
end
end
end
end)
test_cmd:add_args(1, { "reload" })
test_cmd:add_args(1, { "admin", }, "luagin.admin")
test_cmd:add_args_for(2, "admin", { "tp" })
Last updated