mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Added Temp Ban
This commit is contained in:
@@ -15,4 +15,8 @@ roles-list-element=__1__, __2__
|
||||
jail-give=__1__ was jailed by __2__. Reason: __3__
|
||||
jail-remove=__1__ was unjailed by __2__.
|
||||
jail-already-jailed=__1__ is already in jail.
|
||||
jail-not-jailed=__1__ is not currently in jail.
|
||||
jail-not-jailed=__1__ is not currently in jail.
|
||||
jail-temp-ban=__1__ was temp banned until next reset by __2__. Reason: __3__
|
||||
jail-temp-ban-clear=__1__ was cleared from temp banned by __2__.
|
||||
jail-not-temp-banned=__1__ is not currently temp banned.
|
||||
jail-already-banned=__1__ is already banned.
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
local Roles = require 'expcore.roles'
|
||||
local Game = require 'utils.game'
|
||||
local Global = require 'utils.global'
|
||||
local move_items = ext_require('expcore.common','move_items')
|
||||
|
||||
local Public = {
|
||||
old_roles = {}
|
||||
old_roles = {},
|
||||
temp_bans = {}
|
||||
}
|
||||
Global.register(Public.old_roles,function(tbl)
|
||||
Public.old_roles=tbl
|
||||
Global.register({
|
||||
Public.old_roles,
|
||||
Public.temp_bans
|
||||
},function(tbl)
|
||||
Public.old_roles=tbl[1]
|
||||
Public.temp_bans=tbl[2]
|
||||
end)
|
||||
|
||||
--- Jails a player, this is only the logic there is no output to players
|
||||
@@ -38,4 +44,35 @@ function Public.unjail_player(player,by_player_name)
|
||||
return #old_roles
|
||||
end
|
||||
|
||||
--- Temp bans a player which is similar to jail but will store the reason for the action and clears items
|
||||
-- @tparam player LuaPlayer the player that will be temp baned, must not be temp banned
|
||||
-- @tparam[opt='<server>'] by_player_name string the name of the player that is doing the action
|
||||
-- @tparam[opt='None Given.'] reason string the reason that will be stored for this temp ban
|
||||
-- @treturn boolean true if successful else will return nil
|
||||
function Public.temp_ban_player(player,by_player_name,reason)
|
||||
player = Game.get_player_from_any(player)
|
||||
reason = reason or 'None Given.'
|
||||
if not player then return end
|
||||
if Public.temp_bans[player.name] then return end
|
||||
Public.jail_player(player,by_player_name)
|
||||
Public.temp_bans[player.name] = {reason,by_player_name}
|
||||
local inv = player.get_main_inventory()
|
||||
move_items(inv.get_contents())
|
||||
inv.clear()
|
||||
return true
|
||||
end
|
||||
|
||||
--- Removes temp ban from a player, note this does not restore the items
|
||||
-- @tparam player LuaPlayer the player that will be cleared from temp baned, must be temp banned
|
||||
-- @tparam[opt='<server>'] by_player_name string the name of the player that is doing the action
|
||||
-- @treturn boolean true if successful else will return nil
|
||||
function Public.clear_temp_ban_player(player,by_player_name)
|
||||
player = Game.get_player_from_any(player)
|
||||
if not player then return end
|
||||
if not Public.temp_bans[player.name] then return end
|
||||
Public.unjail_player(player,by_player_name)
|
||||
Public.temp_bans[player.name] = nil
|
||||
return true
|
||||
end
|
||||
|
||||
return Public
|
||||
@@ -3,7 +3,7 @@ local JailControl = require 'modules.addons.jail-control'
|
||||
local format_chat_player_name = ext_require('expcore.common','format_chat_player_name')
|
||||
require 'config.command_parse_roles'
|
||||
|
||||
Commands.new_command('jail','Puts a player into jail and removes all other roles')
|
||||
Commands.new_command('jail','Puts a player into jail and removes all other roles.')
|
||||
:add_param('player',false,'player-role')
|
||||
:add_param('reason',true)
|
||||
:enable_auto_concat()
|
||||
@@ -18,7 +18,7 @@ Commands.new_command('jail','Puts a player into jail and removes all other roles
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.new_command('unjail','Puts a player into jail and removes all other roles')
|
||||
Commands.new_command('unjail','Puts a player into jail and removes all other roles.')
|
||||
:add_param('player',false,'player-role')
|
||||
:enable_auto_concat()
|
||||
:register(function(player,action_player,raw)
|
||||
@@ -29,4 +29,32 @@ Commands.new_command('unjail','Puts a player into jail and removes all other rol
|
||||
else
|
||||
return Commands.error{'exp-commands.jail-not-jailed',action_player_name_color}
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.new_command('temp-ban','Temp bans a player until the next reset; this requires a reason; this will clear the players inventory.')
|
||||
:add_param('player',false,'player-role')
|
||||
:add_param('reason',false)
|
||||
:enable_auto_concat()
|
||||
:register(function(player,action_player,reason,raw)
|
||||
local action_player_name_color = format_chat_player_name(action_player)
|
||||
local by_player_name_color = format_chat_player_name(player)
|
||||
if JailControl.temp_ban_player(action_player,player.name,reason) then
|
||||
game.print{'exp-commands.jail-temp-ban',action_player_name_color,by_player_name_color,reason}
|
||||
else
|
||||
return Commands.error{'exp-commands.jail-already-banned',action_player_name_color}
|
||||
end
|
||||
end)
|
||||
|
||||
Commands.new_command('remove-temp-ban','Removes temp ban from a player; this will not restore they items.')
|
||||
:add_param('player',false,'player-role')
|
||||
:add_param('reason',false)
|
||||
:enable_auto_concat()
|
||||
:register(function(player,action_player,reason,raw)
|
||||
local action_player_name_color = format_chat_player_name(action_player)
|
||||
local by_player_name_color = format_chat_player_name(player)
|
||||
if JailControl.clear_temp_ban_player(action_player,player.name,reason) then
|
||||
game.print{'exp-commands.jail-temp-ban-clear',action_player_name_color,by_player_name_color}
|
||||
else
|
||||
return Commands.error{'exp-commands.jail-not-temp-banned',action_player_name_color}
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user