mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Update to ExpGamingCore.Command for when command-run is printed
This commit is contained in:
@@ -7,7 +7,7 @@ local moduleIndex = require("/modules/index")
|
|||||||
local Manager = {}
|
local Manager = {}
|
||||||
|
|
||||||
-- this is a constant that is used to represent the server
|
-- this is a constant that is used to represent the server
|
||||||
SERVER = setmetatable({index=0,name='<server>',online_time=0,afk_time=0,print=print},{__index=function(tbl,key) if type(game.player[key]) == 'function' then return function() end else return nil end end})
|
SERVER = setmetatable({index=0,name='<server>',online_time=0,afk_time=0,print=print,admin=true},{__index=function(tbl,key) if type(game.players[1][key]) == 'function' then return function() end else return nil end end})
|
||||||
|
|
||||||
--- Setup for metatable of the Manager to force read only nature
|
--- Setup for metatable of the Manager to force read only nature
|
||||||
-- @usage Manager() -- runs Manager.loadModdules()
|
-- @usage Manager() -- runs Manager.loadModdules()
|
||||||
|
|||||||
@@ -206,21 +206,21 @@ end
|
|||||||
-- @tparam table command the event rasied by the command
|
-- @tparam table command the event rasied by the command
|
||||||
local function run_custom_command(command)
|
local function run_custom_command(command)
|
||||||
local data = commands.data[command.name]
|
local data = commands.data[command.name]
|
||||||
local player_name = Game.get_player(command) and Game.get_player(command).name or 'server'
|
local player = Game.get_player(command) or SERVER
|
||||||
-- runs all middle ware if any, if there is no middle where then it relyis on .default_admin_only
|
-- runs all middle ware if any, if there is no middle where then it relyis on .default_admin_only
|
||||||
if #middleware > 0 then for _,callback in pairs(middleware) do
|
if #middleware > 0 then for _,callback in pairs(middleware) do
|
||||||
local success, err = pcall(callback,player_name,command.name,command)
|
local success, err = pcall(callback,player_name,command.name,command)
|
||||||
if not success then error(err)
|
if not success then error(err)
|
||||||
elseif not err then
|
elseif not err then
|
||||||
player_return({'ExpGamingCore_Command.unauthorized'},defines.textcolor.crit)
|
player_return({'ExpGamingCore_Command.unauthorized'},defines.textcolor.crit)
|
||||||
logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command))
|
logMessage(player.name,command,'Failed to use command (Unauthorized)',commands.validate_args(command))
|
||||||
if game.player then game.player.play_sound{path='utility/cannot_build'} end
|
game.player.play_sound{path='utility/cannot_build'}
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end elseif data.default_admin_only == true and game.player and not game.player.admin then
|
end elseif data.default_admin_only == true and player and not player.admin then
|
||||||
player_return({'ExpGamingCore_Command.unauthorized'},defines.textcolor.crit)
|
player_return({'ExpGamingCore_Command.unauthorized'},defines.textcolor.crit)
|
||||||
logMessage(player_name,command,'Failed to use command (Unauthorized)',commands.validate_args(command))
|
logMessage(player.name,command,'Failed to use command (Unauthorized)',commands.validate_args(command))
|
||||||
if game.player then game.player.play_sound{path='utility/cannot_build'} end
|
game.player.play_sound{path='utility/cannot_build'}
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- gets the args for the command
|
-- gets the args for the command
|
||||||
@@ -228,15 +228,15 @@ local function run_custom_command(command)
|
|||||||
if args == commands.error then
|
if args == commands.error then
|
||||||
if is_type(err,'table') then table.insert(err,command.name) table.insert(err,commands.format_inputs(data))
|
if is_type(err,'table') then table.insert(err,command.name) table.insert(err,commands.format_inputs(data))
|
||||||
player_return(err,defines.textcolor.high) else player_return({'ExpGamingCore_Command.invalid-inputs',command.name,commands.format_inputs(data)},defines.textcolor.high) end
|
player_return(err,defines.textcolor.high) else player_return({'ExpGamingCore_Command.invalid-inputs',command.name,commands.format_inputs(data)},defines.textcolor.high) end
|
||||||
logMessage(player_name,command,'Failed to use command (Invalid Args)',args)
|
logMessage(player.name,command,'Failed to use command (Invalid Args)',args)
|
||||||
if game.player then game.player.play_sound{path='utility/deconstruct_big'} end
|
player.play_sound{path='utility/deconstruct_big'}
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- runs the command
|
-- runs the command
|
||||||
local success, err = pcall(data.callback,command,args)
|
local success, err = pcall(data.callback,command,args)
|
||||||
if not success then error(err) end
|
if not success then error(err) end
|
||||||
if err ~= commands.error and player_name ~= 'server' then player_return({'ExpGamingCore_Command.command-ran'},defines.textcolor.info) end
|
if err ~= commands.error and player ~= SERVER then player_return({'ExpGamingCore_Command.command-ran'},defines.textcolor.info) end
|
||||||
logMessage(player_name,command,'Used command',args)
|
logMessage(player.name,command,'Used command',args)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Used to define commands
|
--- Used to define commands
|
||||||
|
|||||||
Reference in New Issue
Block a user