From bd1425956f19e5bda4e6d5d9237af7dfc1de60f0 Mon Sep 17 00:00:00 2001 From: Lynn Date: Sat, 24 Nov 2018 14:59:49 +0100 Subject: [PATCH] Added admin check and aggregate errors --- utils/command.lua | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/utils/command.lua b/utils/command.lua index cf481991..0b525a45 100644 --- a/utils/command.lua +++ b/utils/command.lua @@ -40,6 +40,11 @@ function Command.add(command_name, options, callback) end else print = player.print + + if admin_only and not player.admin then + print(string.format('The %s command is only available to admins.', command_name)) + return + end end local named_arguments = {} @@ -48,14 +53,26 @@ function Command.add(command_name, options, callback) insert(from_command, param) end + local errors = {} + for index, argument in ipairs(arguments) do local parameter = from_command[index] if not parameter then - print(string.format('Argument %s from command %s is missing.', argument, command_name)) - return + insert(errors, string.format('Argument %s from command %s is missing.', argument, command_name)) + else + named_arguments[argument] = parameter end + end - named_arguments[argument] = parameter + local return_early = false + + for _, error in ipairs(errors) do + return_early = true + print(error) + end + + if return_early then + return end if log_command then