Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed Temp ban related stuff #187

Merged
merged 2 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config/discord_alerts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ return {
player_kicks=true,
player_promotes=false,
player_jail=true,
player_temp_ban=true,
['config']=true,
['purge']=true,
['c']=true,
Expand Down
2 changes: 0 additions & 2 deletions config/expcore/roles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Roles.new_role('Moderator','Mod')
'command/go-to-spawn/always',
'command/clear-reports',
'command/clear-warnings',
'command/clear-temp-ban',
'command/clear-inventory',
'command/bonus',
'command/home',
Expand All @@ -96,7 +95,6 @@ Roles.new_role('Trainee','TrMod')
'command/teleport',
'command/bring',
'command/goto',
'command/temp-ban',
'command/give-warning',
'command/get-warnings',
'command/get-reports',
Expand Down
24 changes: 0 additions & 24 deletions config/gui/player_list_actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,25 +150,6 @@ local function jail_player_callback(player,reason)
Jail.jail_player(selected_player_name,player.name,reason)
end

--- Temp bans the action player, requires a reason
-- @element temp_ban_player
local temp_ban_player = new_button('utility/warning_white',{'player-list.temp-ban-player'})
:on_click(function(player)
local selected_player_name, selected_player_color = get_action_player_name(player)
if Jail.is_jailed(selected_player_name) then
player.print({'expcom-jail.already-banned', selected_player_color},Colors.orange_red)
else
SelectedAction:set(player, 'command/temp-ban')
end
end)

local function temp_ban_player_callback(player,reason)
local selected_player, selected_player_color = get_action_player_name(player)
local by_player_name_color = format_chat_player_name(player)
game.print{'expcom-jail.temp-ban', selected_player_color,by_player_name_color,reason}
Jail.temp_ban_player(selected_player,player.name,reason)
end

--- Kicks the action player, requires a reason
-- @element kick_player
local kick_player = new_button('utility/warning_icon',{'player-list.kick-player'})
Expand Down Expand Up @@ -232,11 +213,6 @@ return {
reason_callback=jail_player_callback,
jail_player
},
['command/temp-ban'] = {
auth=auth_lower_role,
reason_callback=temp_ban_player_callback,
temp_ban_player
},
['command/kick'] = {
auth=auth_lower_role,
reason_callback=kick_player_callback,
Expand Down
4 changes: 0 additions & 4 deletions locale/en/commands.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ give=__1__ was jailed by __2__. Reason: __3__
remove=__1__ was unjailed by __2__.
already-jailed=__1__ is already in jail.
not-jailed=__1__ is not currently in jail.
temp-ban=__1__ was temp banned until next reset by __2__. Reason: __3__
temp-ban-clear=__1__ was cleared from temp banned by __2__.
not-temp-banned=__1__ is not currently temp banned.
already-banned=__1__ is already banned.

[expcom-report]
player-immune=This player can not be reported.
Expand Down
1 change: 0 additions & 1 deletion locale/en/gui.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ kill-player=Kill player
report-player=Report player
warn-player=Warn player
jail-player=Jail player
temp-ban-player=Temp ban player
kick-player=Kick player
ban-player=Ban player
afk-time=__1__% of total map time\nLast moved __2__ ago
Expand Down
26 changes: 0 additions & 26 deletions modules/addons/discord-alerts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,6 @@ if config.player_jail then
end)
end

--- When a player is tempbanned
if config.player_temp_ban then
local Jail = require 'modules.control.jail'
Event.add(Jail.events.on_player_temp_banned, function(event)
local player_name, by_player_name = get_player_name(event)
emit_event{
title='Temp Ban',
description='A player has been temp banned',
color=Colors.red,
['Player']='<inline>'..player_name,
['By']='<inline>'..by_player_name,
['Reason']=event.reason
}
end)
Event.add(Jail.events.on_player_untemp_banned, function(event)
local player_name, by_player_name = get_player_name(event)
emit_event{
title='Temp Ban Removed',
description='A player has been untemp banned',
color=Colors.green,
['Player']='<inline>'..player_name,
['By']='<inline>'..by_player_name
}
end)
end

--- Ban and unban
if config.player_bans then
Event.add(defines.events.on_player_banned, function(event)
Expand Down
37 changes: 1 addition & 36 deletions modules/commands/jail.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[-- Commands Module - Jail
- Adds a commands that allow admins to jail, unjail, and temp ban players
- Adds a commands that allow admins to jail and unjail
@commands Jail
]]

Expand Down Expand Up @@ -45,38 +45,3 @@ Commands.new_command('unjail', 'Removes a player from jail.')
return Commands.error{'expcom-jail.not-jailed', action_player_name_color}
end
end)

--- Temp bans a player until the next reset; this requires a reason; this will clear the players inventory.
-- @command temp-ban
-- @tparam LuaPlayer player the player that will be temp banned
-- @tparam string reason the reason that the player is being temp banned
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)
local action_player_name_color = format_chat_player_name(action_player)
local by_player_name_color = format_chat_player_name(player)
if Jail.temp_ban_player(action_player, player.name, reason) then
game.print{'expcom-jail.temp-ban', action_player_name_color, by_player_name_color, reason}
else
return Commands.error{'expcom-jail.already-banned', action_player_name_color}
end
end)

--- Removes temp ban from a player; this will not restore their items.
-- @command clear-temp-ban
-- @tparam LuaPlayer player the player to revoke the temp ban from
Commands.new_command('clear-temp-ban', 'Removes temp ban from a player; this will not restore their items.')
:add_param('player', false, 'player-role')
:add_alias('untemp-ban', 'remove-temp-ban')
:enable_auto_concat()
:register(function(player, action_player)
local action_player_name_color = format_chat_player_name(action_player)
local by_player_name_color = format_chat_player_name(player)
if Jail.untemp_ban_player(action_player, player.name) then
game.print{'expcom-jail.temp-ban-clear', action_player_name_color, by_player_name_color}
else
return Commands.error{'expcom-jail.not-temp-banned', action_player_name_color}
end
end)
102 changes: 5 additions & 97 deletions modules/control/jail.lua
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -46,37 +40,20 @@ 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
}, function(tbl)
Jail.old_roles = tbl.old_roles
Jail.temp_bans = tbl.temp_bans
old_roles = Jail.old_roles
temp_bans = Jail.temp_bans
Global.register(old_roles, function(tbl)
Jail.old_roles = tbl
old_roles = tbl
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,
Expand Down Expand Up @@ -142,73 +119,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