From e9a43822773aa10a5b625bebd80252825272a1d3 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Tue, 9 Apr 2019 16:16:05 +0100 Subject: [PATCH] Changed add_tag to set_flag on commands --- expcore/commands.lua | 16 ++++++++-------- modules/commands/admin-chat.lua | 2 +- modules/commands/cheat-mode.lua | 4 ++-- modules/commands/help.lua | 2 +- modules/commands/interface.lua | 2 +- modules/commands/kill.lua | 4 ++-- modules/commands/tag.lua | 2 +- modules/commands/teleport.lua | 6 +++--- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/expcore/commands.lua b/expcore/commands.lua index a3c90991..e096cc19 100644 --- a/expcore/commands.lua +++ b/expcore/commands.lua @@ -60,8 +60,8 @@ return false -- false is returned other wise end end) - :add_defaults{smiley=false} -- adds false as the default for smiley - :add_tag('admin_only',true) -- adds the tag admin_only: true which because of the above authenticator means you must be added to use this command + :set_defaults{smiley=false} -- adds false as the default for smiley + :set_flag('admin_only',true) -- adds the tag admin_only: true which because of the above authenticator means you must be added to use this command :add_alias('name','rname') -- adds two aliases "name" and "rname" for this command which will work as if the ordinal name was used --:enable_auto_concat() -- cant be used due to optional param here, but this will make all user input params after the last expected one be added to the last expected one :register(function(player,repeat_count,smiley,raw) -- this registers the command to the game, notice the params are what were defined above @@ -119,8 +119,8 @@ return false end end) - :add_defaults{smiley=false} - :add_tag('admin_only',true) + :set_defaults{smiley=false} + :set_flag('admin_only',true) :add_alias('name','rname') :register(function(player,repeat_count,smiley,raw) game.print(player.name..' used a command with input: '..raw) @@ -147,8 +147,8 @@ Commands.add_command(name,help) --- Creates a new command object to added details to, note this does not register the command to the game Commands._prototype:add_param(name,optional,parse,...) --- Adds a new param to the command this will be displayed in the help and used to parse the input - Commands._prototype:add_defaults(defaults) --- Adds default values to params only matters if the param is optional - Commands._prototype:add_tag(name,value) --- Adds a tag to the command which is passed via the tags param to the authenticators, can be used to assign command roles or type + Commands._prototype:set_defaults(defaults) --- Adds default values to params only matters if the param is optional + Commands._prototype:set_flag(name,value) --- Adds a tag to the command which is passed via the tags param to the authenticators, can be used to assign command roles or type Commands._prototype:add_alias(...) --- Adds an alias or multiple that will also be registered with the same callback, eg /teleport can be /tp with both working Commands._prototype:enable_auto_concat() --- Enables auto concatenation of any params on the end so quotes are not needed for last param Commands._prototype:register(callback) --- Adds the callback to the command and registers all aliases, params and help message with the game @@ -399,7 +399,7 @@ end -- @tparam defaults table a table keyed by the name of the param with the value as the default value {paramName=defaultValue} -- callback param - player: LuaPlayer - the player using the command, default value does not need to be a function callback -- @treturn Commands._prototype pass through to allow more functions to be called -function Commands._prototype:add_defaults(defaults) +function Commands._prototype:set_defaults(defaults) for name,value in pairs(defaults) do if self.params[name] then self.params[name].default = value @@ -413,7 +413,7 @@ end -- @tparam value any the tag that you want can be anything that the authenticators are expecting -- nb: if value is nil then name will be assumed as the value and added at a numbered index -- @treturn Commands._prototype pass through to allow more functions to be called -function Commands._prototype:add_tag(name,value) +function Commands._prototype:set_flag(name,value) if not value then -- value not given so name is the value table.insert(self.tags,name) diff --git a/modules/commands/admin-chat.lua b/modules/commands/admin-chat.lua index 2f9df730..c3fb6e5f 100644 --- a/modules/commands/admin-chat.lua +++ b/modules/commands/admin-chat.lua @@ -4,7 +4,7 @@ require 'config.command_parse_general' Commands.new_command('admin-chat','Sends a message in chat that only admins can see.') :add_param('message',false) -- the message to send in the admin chat :enable_auto_concat() -:add_tag('admin_only',true) +:set_flag('admin_only',true) :add_alias('ac') :register(function(player,message,raw) local pcc = player and player.chat_color or {r=255,g=255,b=255} diff --git a/modules/commands/cheat-mode.lua b/modules/commands/cheat-mode.lua index dbbdc54d..6aef5fca 100644 --- a/modules/commands/cheat-mode.lua +++ b/modules/commands/cheat-mode.lua @@ -3,10 +3,10 @@ require 'config.command_parse_general' Commands.new_command('toggle-cheat-mode','Toggles cheat mode for your player, or another player.') :add_param('player',true,'player') -- player to toggle chest mode of, can be nil for self -:add_defaults{player=function(player) +:set_defaults{player=function(player) return player -- default is the user using the command end} -:add_tag('admin_only',true) +:set_flag('admin_only',true) :register(function(player,action_player,raw) action_player.cheat_mode = not action_player.cheat_mode end) \ No newline at end of file diff --git a/modules/commands/help.lua b/modules/commands/help.lua index 9d8a2183..c4a78567 100644 --- a/modules/commands/help.lua +++ b/modules/commands/help.lua @@ -12,7 +12,7 @@ end) Commands.new_command('chelp','Searches for a keyword in all commands you are allowed to use.') :add_param('keyword',true) -- the keyword that will be looked for :add_param('page',true,'integer') -- the keyword that will be looked for -:add_defaults{keyword='',page=1} +:set_defaults{keyword='',page=1} :register(function(player,keyword,page,raw) local player_index = player and player.index or 0 -- if keyword is a number then treat it as page number diff --git a/modules/commands/interface.lua b/modules/commands/interface.lua index da03fdd1..6ee924c0 100644 --- a/modules/commands/interface.lua +++ b/modules/commands/interface.lua @@ -48,7 +48,7 @@ end Commands.new_command('interface','Sends an innovation to be ran and returns the result.') :add_param('innovation',false) -- the message to send in the admin chat :enable_auto_concat() -:add_tag('admin_only',true) +:set_flag('admin_only',true) :register(function(player,innovation,raw) if not innovation:find('%s') and not innovation:find('return') then -- if there are no spaces and return is not present then return is appended to the start diff --git a/modules/commands/kill.lua b/modules/commands/kill.lua index d1e4de25..24dc16bc 100644 --- a/modules/commands/kill.lua +++ b/modules/commands/kill.lua @@ -3,13 +3,13 @@ require 'config.command_parse_general' Commands.new_command('kill','Kills yourself or another player.') :add_param('player',true,'player-alive') -- the player to kill, must be alive to be valid -:add_defaults{player=function(player) +:set_defaults{player=function(player) -- default is the player unless they are dead if player.character and player.character.health > 0 then return player end end} -:add_tag('admin_only',true) +:set_flag('admin_only',true) :register(function(player,action_player,raw) if not action_player then -- can only be nil if no player given and the user is dead diff --git a/modules/commands/tag.lua b/modules/commands/tag.lua index 97ae6c21..4105d92a 100644 --- a/modules/commands/tag.lua +++ b/modules/commands/tag.lua @@ -10,7 +10,7 @@ end) Commands.new_command('tag-clear','Clears your tag. Or another player if you are admin.') :add_param('player',true,'player') -- player to remove the tag of, nil to apply to self -:add_defaults{player=function(player) +:set_defaults{player=function(player) return player -- default is the user using the command end} :register(function(player,action_player,raw) diff --git a/modules/commands/teleport.lua b/modules/commands/teleport.lua index 7275f56a..dc87b024 100644 --- a/modules/commands/teleport.lua +++ b/modules/commands/teleport.lua @@ -14,7 +14,7 @@ Commands.new_command('teleport','Teleports a player to another player.') :add_param('from_player',false,'player-alive') -- player that will be teleported, must be alive :add_param('to_player',false,'player-online') -- player to teleport to, must be online (if dead goes to where they died) :add_alias('tp') -:add_tag('admin_only',true) +:set_flag('admin_only',true) :register(function(player,from_player,to_player,raw) if from_player.index == to_player.index then -- return if attempting to teleport to self @@ -28,7 +28,7 @@ end) Commands.new_command('bring','Teleports a player to you.') :add_param('player',false,'player-alive') -- player that will be teleported, must be alive -:add_tag('admin_only',true) +:set_flag('admin_only',true) :register(function(player,from_player,raw) if from_player.index == player.index then -- return if attempting to teleport to self @@ -43,7 +43,7 @@ end) Commands.new_command('goto','Teleports you to a player.') :add_param('player',false,'player-online') -- player to teleport to, must be online (if dead goes to where they died) :add_alias('tp-me','tpme') -:add_tag('admin_only',true) +:set_flag('admin_only',true) :register(function(player,to_player,raw) if to_player.index == player.index then -- return if attempting to teleport to self