mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-21 17:04:00 +00:00
The entity protection module moves to exp_scenario/module/control/protection.lua in the event_handler shape the other control modules use, and the copy in exp_legacy is removed. The config lookups are built as local sets instead of rewriting the config tables in place, the two mined handlers become one, and the entity and area key helpers are exposed so the protection command no longer keeps its own copies. Event ids are exposed as Protection.on_player_mined_protected and Protection.on_repeat_violation.
48 lines
1.5 KiB
Lua
48 lines
1.5 KiB
Lua
--[[-- Control - Projection Jail
|
|
When a player triggers protection multiple times they are automatically jailed
|
|
]]
|
|
|
|
local ExpUtil = require("modules/exp_util")
|
|
local Storage = require("modules/exp_util/storage")
|
|
local Jail = require("modules.exp_legacy.modules.control.jail")
|
|
local Protection = require("modules/exp_scenario/control/protection")
|
|
|
|
local format_player_name = ExpUtil.format_player_name_locale
|
|
|
|
--- Stores how many times the repeat violation was triggered
|
|
--- @type table<number, number>
|
|
local repeat_count = {}
|
|
Storage.register(repeat_count, function(tbl)
|
|
repeat_count = tbl
|
|
end)
|
|
|
|
--- When a protection is triggered increment their counter and jail if needed
|
|
local function on_repeat_violation(event)
|
|
local player = assert(game.get_player(event.player_index))
|
|
|
|
-- Increment the counter
|
|
local count = (repeat_count[player.index] or 0) + 1
|
|
repeat_count[player.index] = count
|
|
|
|
-- Jail if needed
|
|
if count >= 3 then
|
|
Jail.jail_player(player, "<protection>", "Removed too many protected entities, please wait for a moderator.")
|
|
game.print{ "exp_protection-jail.chat-jailed", format_player_name(player) }
|
|
end
|
|
end
|
|
|
|
--- Clear the counter when they leave the game (stops a build up of data)
|
|
--- @param event EventData.on_player_left_game
|
|
local function on_player_left_game(event)
|
|
repeat_count[event.player_index] = nil
|
|
end
|
|
|
|
local e = defines.events
|
|
|
|
return {
|
|
events = {
|
|
[Protection.on_repeat_violation] = on_repeat_violation,
|
|
[e.on_player_left_game] = on_player_left_game,
|
|
}
|
|
}
|