diff --git a/config/protection.lua b/config/protection.lua index fbba783d..6f051c37 100644 --- a/config/protection.lua +++ b/config/protection.lua @@ -1,19 +1,19 @@ return { ignore_admins = true, --- @setting ignore_admins If admins are ignored by the protection filter ignore_permission = 'bypass-entity-protection', --- @setting ignore_permission Players with this permission will be ignored by the protection filter, leave nil if expcore.roles is not used - repeat_count = 5, --- @setting repeat_count Number of protected entities to be removed to count as repeated - repeat_lifetime = 3600*20, --- @setting repeat_lifetime How old repeats must be before being removed - refresh_rate = 3600*5, --- @setting refresh_rate How often old repeats will be removed + repeat_count = 5, --- @setting repeat_count Number of protected entities that must be removed within repeat_lifetime in order to trigger repeated removal protection + repeat_lifetime = 3600*20, --- @setting repeat_lifetime The length of time, in ticks, that protected removals will be remembered for + refresh_rate = 3600*5, --- @setting refresh_rate How often the age of protected removals are checked against repeat_lifetime always_protected_names = { --- @setting always_protected_names Names of entities which are always protected }, always_protected_types = { --- @setting always_protected_types Types of entities which are always protected 'boiler', 'generator', 'offshore-pump', 'power-switch', 'reactor', 'rocket-silo' }, - skip_repeat_names = { --- @setting skip_repeat_names Names of entities which always trigger protection repeated + always_trigger_repeat_names = { --- @setting always_trigger_repeat_names Names of entities which always trigger repeated removal protection }, - skip_repeat_types = { --- @setting skip_repeat_types Types of entities which trigger protection repeated + always_trigger_repeat_types = { --- @setting always_trigger_repeat_types Types of entities which always trigger repeated removal protection 'reactor', 'rocket-silo' } } \ No newline at end of file diff --git a/modules/addons/discord-alerts.lua b/modules/addons/discord-alerts.lua index fe13ec5c..acab30e6 100644 --- a/modules/addons/discord-alerts.lua +++ b/modules/addons/discord-alerts.lua @@ -76,7 +76,7 @@ local function emit_event(args) }) end ---- Repeat protected entity mining +--- Repeated protected entity mining if config.entity_protection then local EntityProtection = require 'modules.control.protection' --- @dep modules.control.protection Event.add(EntityProtection.events.on_repeat_violation, function(event) diff --git a/modules/commands/protection.lua b/modules/commands/protection.lua index c48454d1..01066d35 100644 --- a/modules/commands/protection.lua +++ b/modules/commands/protection.lua @@ -1,5 +1,5 @@ --[[-- Commands Module - Protection - - Adds a commands that can add and remove protection + - Adds commands that can add and remove protection @commands Protection ]] @@ -72,7 +72,7 @@ local function show_protected_entity(player, entity) renders[player.index][key] = render_id end ---- Show a protected are to a player +--- Show a protected area to a player local function show_protected_area(player, surface, area) local key = get_area_key(area) if renders[player.index][key] then return end @@ -200,7 +200,7 @@ Event.add(Selection.events.on_player_selection_start, function(event) end end) ---- When selection ends show hide protected entities on screen and protected areas +--- When selection ends hide protected entities and protected areas Event.add(Selection.events.on_player_selection_end, function(event) if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end for _, id in pairs(renders[event.player_index]) do diff --git a/modules/control/protection.lua b/modules/control/protection.lua index e0d1c7cc..61b5f5c6 100644 --- a/modules/control/protection.lua +++ b/modules/control/protection.lua @@ -16,7 +16,7 @@ local EntityProtection = { -- @tparam number player_index the player index of the player who got mined the entity -- @tparam LuaEntity entity the entity which was mined on_player_mined_protected = script.generate_event_name(), - --- When a player mines a many protected entities + --- When a player repeatedly mines protected entities -- @event on_repeat_violation -- @tparam number player_index the player index of the player who got mined the entities -- @tparam LuaEntity entity the last entity which was mined @@ -24,8 +24,8 @@ local EntityProtection = { } } --- convert config tables into lookup tables -for _, config_key in ipairs{'always_protected_names', 'always_protected_types', 'skip_repeat_names', 'skip_repeat_types'} do +-- Convert config tables into lookup tables +for _, config_key in ipairs{'always_protected_names', 'always_protected_types', 'always_trigger_repeat_names', 'always_trigger_repeat_types'} do local tbl = config[config_key] for key, value in ipairs(tbl) do tbl[key] = nil @@ -33,10 +33,10 @@ for _, config_key in ipairs{'always_protected_names', 'always_protected_types', end end --- convert ignore role if present +-- Require roles if a permission is assigned in the config local Roles if config.ignore_permission then - Roles = require 'expcore.roles' --- @dep expcore.roles + Roles = require 'expcore.roles' --- @dep expcore.roles end ----- Global Variables ----- @@ -74,9 +74,9 @@ local function check_always_protected(entity) return config.always_protected_names[entity.name] or config.always_protected_types[entity.type] or false end ---- Check if an entity skips repeated -local function check_skip_repeat(entity) - return config.skip_repeat_names[entity.name] or config.skip_repeat_types[entity.type] or false +--- Check if an entity always triggers repeat protection +local function check_always_trigger_repeat(entity) + return config.always_trigger_repeat_names[entity.name] or config.always_trigger_repeat_types[entity.type] or false end ----- Public Functions ----- @@ -175,7 +175,7 @@ Event.add(defines.events.on_pre_player_mined_item, function(event) -- Send events event.name = EntityProtection.events.on_player_mined_protected script.raise_event(EntityProtection.events.on_player_mined_protected, event) - if check_skip_repeat(entity) or player_repeats.count >= config.repeat_count then + if check_always_trigger_repeat(entity) or player_repeats.count >= config.repeat_count then player_repeats.count = 0 -- Reset to avoid spamming of events event.name = EntityProtection.events.on_repeat_violation script.raise_event(EntityProtection.events.on_repeat_violation, event) diff --git a/modules/control/selection.lua b/modules/control/selection.lua index 0b009b40..4939253b 100644 --- a/modules/control/selection.lua +++ b/modules/control/selection.lua @@ -8,7 +8,7 @@ local Event = require 'utils.event' --- @dep utils.event local Global = require 'utils.global' --- @dep utils.global local Selection = { events = { - --- When a player enterers selection mode + --- When a player enters selection mode -- @event on_player_selection_start -- @tparam number player_index the player index of the player who entered selection mode -- @tparam string selection the name of the selection being made @@ -158,7 +158,8 @@ end Event.add(defines.events.on_pre_player_left_game, stop_after_event) Event.add(defines.events.on_pre_player_died, stop_after_event) ---- Stop selection after a single use if the option was used + +--- Stop selection after a single use if single_use was true during Selection.start local function stop_after_use(event) if not selections[event.player_index] then return end if not selections[event.player_index].single_use then return end