Implemented requested changes

This commit is contained in:
Cooldude2606
2021-04-26 00:20:55 +01:00
parent e38eda0076
commit 2df7482a77
5 changed files with 21 additions and 20 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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)

View File

@@ -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