diff --git a/config/_file_loader.lua b/config/_file_loader.lua index eb9ce62c..404261bf 100644 --- a/config/_file_loader.lua +++ b/config/_file_loader.lua @@ -49,6 +49,7 @@ return { 'modules.addons.tree-decon', 'modules.addons.afk-kick', 'modules.addons.report-jail', + 'modules.addons.protection-jail', --- Data 'modules.data.statistics', diff --git a/locale/en/addons.cfg b/locale/en/addons.cfg index cd717eab..1cac74dc 100644 --- a/locale/en/addons.cfg +++ b/locale/en/addons.cfg @@ -79,4 +79,7 @@ verify=Please return to our discord and type r!verify __1__ message=All players were kicked because everyone was AFK. [report-jail] -jail=__1__ was jailed because they were reported too many times. +jail=__1__ was jailed because they were reported too many times. Please wait for a moderator. + +[protection-jail] +jail=__1__ was jailed because they removed too many protected entities. Please wait for a moderator. diff --git a/modules/addons/protection-jail.lua b/modules/addons/protection-jail.lua new file mode 100644 index 00000000..6ff07118 --- /dev/null +++ b/modules/addons/protection-jail.lua @@ -0,0 +1,37 @@ +--- When a player triggers protection multiple times they are automatically jailed +-- @addon protection-jail + +local Event = require 'utils.event' ---@dep utils.event +local Global = require 'utils.global' ---@dep utils.global +local Jail = require 'modules.control.jail' ---@dep modules.control.jail +local Protection = require 'modules.control.protection' --- @dep modules.control.protection +local format_chat_player_name = _C.format_chat_player_name --- @dep expcore.common + +--- Stores how many times the repeat violation was triggered +local repeat_count = {} +Global.register(repeat_count, function(tbl) + repeat_count = tbl +end) + +--- When a protection is triggered increment their counter and jail if needed +Event.add(Protection.events.on_repeat_violation, function(event) + local player = game.get_player(event.player_index) + + -- Increment the counter + if repeat_count[player.index] then + repeat_count[player.index] = repeat_count[player.index] + 1 + else + repeat_count[player.index] = 1 + end + + -- Jail if needed + if repeat_count[player.index] < 3 then return end + local player_name_color = format_chat_player_name(player) + Jail.jail_player(player, '', 'Removed too many protected entities, please wait for a moderator.') + game.print{'protection-jail.jail', player_name_color} +end) + +--- Clear the counter when they leave the game (stops a build up of data) +Event.add(defines.events.on_player_left_game, function(event) + repeat_count[event.player_index] = nil +end) \ No newline at end of file