mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Removed Temp ban related stuff
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
--[[-- Control Module - Jail
|
||||
- Adds a way to jail players and temp ban players.
|
||||
- Adds a way to jail players.
|
||||
@control Jail
|
||||
@alias Jail
|
||||
|
||||
@@ -14,16 +14,11 @@
|
||||
-- This will give 'MrBiter' all his roles back and remove him from jail
|
||||
-- again as above the player name is only used in the event for user feedback
|
||||
Jail.unjail_player('MrBiter', 'Cooldude2606')
|
||||
|
||||
-- Temp ban works the same as jail but will store the reason and move the players items to spawn
|
||||
-- this is meant to be used as a more permiment jail but not as strong as a ban
|
||||
Jail.temp_ban_player('MrBiter', 'Cooldude2606', 'Likes biters too much')
|
||||
]]
|
||||
|
||||
local Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||
local Game = require 'utils.game' --- @dep utils.game
|
||||
local Global = require 'utils.global' --- @dep utils.global
|
||||
local move_items = _C.move_items --- @dep expcore.common
|
||||
|
||||
local valid_player = Game.get_player_from_any
|
||||
local assign_roles = Roles.assign_player
|
||||
@@ -33,7 +28,6 @@ local get_roles = Roles.get_player_roles
|
||||
|
||||
local Jail = {
|
||||
old_roles = {},
|
||||
temp_bans = {},
|
||||
events = {
|
||||
--- When a player is assigned to jail
|
||||
-- @event on_player_jailed
|
||||
@@ -46,37 +40,22 @@ local Jail = {
|
||||
-- @tparam number player_index the index of the player who was unjailed
|
||||
-- @tparam string by_player_name the name of the player who unjailed the other player
|
||||
on_player_unjailed=script.generate_event_name(),
|
||||
--- When a player is temp banned
|
||||
-- @event on_player_temp_banned
|
||||
-- @tparam number player_index the index of the player who was temp banned
|
||||
-- @tparam string by_player_name the name of the player who temp banned the other player
|
||||
-- @tparam string reason the reason that the player was temp banned
|
||||
on_player_temp_banned=script.generate_event_name(),
|
||||
--- When a temp ban is removed from a player
|
||||
-- @event on_player_untemp_banned
|
||||
-- @tparam number player_index the index of the player who was untemp banned
|
||||
-- @tparam string by_player_name the name of the player who untemp banned the other player
|
||||
on_player_untemp_banned=script.generate_event_name()
|
||||
}
|
||||
}
|
||||
|
||||
local old_roles = Jail.old_roles
|
||||
local temp_bans = Jail.temp_bans
|
||||
Global.register({
|
||||
old_roles = old_roles,
|
||||
temp_bans = temp_bans
|
||||
old_roles = old_roles
|
||||
}, function(tbl)
|
||||
Jail.old_roles = tbl.old_roles
|
||||
Jail.temp_bans = tbl.temp_bans
|
||||
old_roles = Jail.old_roles
|
||||
temp_bans = Jail.temp_bans
|
||||
end)
|
||||
|
||||
--- Used to emit the jail related events
|
||||
-- @tparam number event the name of the event that will be emited
|
||||
-- @tparam LuaPlayer player the player who is being acted on
|
||||
-- @tparam string by_player_name the player who is doing the action
|
||||
-- @tparam string reason the reason for the action (jail and tempban only)
|
||||
-- @tparam string reason the reason for the action (jail)
|
||||
local function event_emit(event, player, by_player_name, reason)
|
||||
script.raise_event(event, {
|
||||
name=event,
|
||||
@@ -142,73 +121,4 @@ function Jail.unjail_player(player, by_player_name)
|
||||
return true
|
||||
end
|
||||
|
||||
--- Temp ban.
|
||||
-- Functions related to temp ban
|
||||
-- @section temp-ban-functions
|
||||
|
||||
--- Checks if a player is temp banned
|
||||
-- @tparam LuaPlayer player the player to check if they are temp banned
|
||||
-- @treturn boolean whether the player is temp banned
|
||||
function Jail.is_temp_banned(player)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
return temp_bans[player.name] ~= nil
|
||||
end
|
||||
|
||||
--- Temp bans a player by moving them to jail, clearing all other roles, storing the reason, and moving their items to spawn
|
||||
-- @tparam LuaPlayer player the player that will be temp banned
|
||||
-- @tparam string by_player_name the name of the player who is doing the temp ban
|
||||
-- @tparam[opt='Non given.'] string reason the reason that the player is being temp banned
|
||||
-- @treturn boolean whether the player was successfully temp banned
|
||||
function Jail.temp_ban_player(player, by_player_name, reason)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
|
||||
reason = reason or 'Non given.'
|
||||
|
||||
if temp_bans[player.name] then return end
|
||||
temp_bans[player.name] = {reason, by_player_name}
|
||||
|
||||
if not has_role(player, 'Jail') then
|
||||
local roles = get_roles(player)
|
||||
old_roles[player.name] = roles
|
||||
|
||||
assign_roles(player, 'Jail', by_player_name, nil, true)
|
||||
unassign_roles(player, roles, by_player_name, nil, true)
|
||||
end
|
||||
|
||||
local inv = player.get_main_inventory()
|
||||
move_items(inv.get_contents())
|
||||
inv.clear()
|
||||
|
||||
event_emit(Jail.events.on_player_temp_banned, player, by_player_name, reason)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
--- Rrmoves a player from temp ban by clearing the stored reason, removing them from jail, and restoring previous roles
|
||||
-- @tparam LuaPlayer player the player who is being removed from temp ban
|
||||
-- @tparam string by_player_name the name of the player who is doing the untemp ban
|
||||
-- @treturn boolean whether the player was successfully removed
|
||||
function Jail.untemp_ban_player(player, by_player_name)
|
||||
player = valid_player(player)
|
||||
if not player then return end
|
||||
if not by_player_name then return end
|
||||
|
||||
if not temp_bans[player.name] then return end
|
||||
temp_bans[player.name] = nil
|
||||
|
||||
if has_role(player, 'Jail') then
|
||||
local roles = old_roles[player.name]
|
||||
|
||||
assign_roles(player, roles, by_player_name, nil, true)
|
||||
unassign_roles(player, 'Jail', by_player_name, nil, true)
|
||||
end
|
||||
|
||||
event_emit(Jail.events.on_player_untemp_banned, player, by_player_name)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
return Jail
|
||||
Reference in New Issue
Block a user