mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Implemented requested changes
This commit is contained in:
@@ -1,19 +1,19 @@
|
|||||||
return {
|
return {
|
||||||
ignore_admins = true, --- @setting ignore_admins If admins are ignored by the protection filter
|
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
|
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_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 How old repeats must be before being removed
|
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 old repeats will be removed
|
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_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
|
always_protected_types = { --- @setting always_protected_types Types of entities which are always protected
|
||||||
'boiler', 'generator', 'offshore-pump', 'power-switch', 'reactor', 'rocket-silo'
|
'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'
|
'reactor', 'rocket-silo'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ local function emit_event(args)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Repeat protected entity mining
|
--- Repeated protected entity mining
|
||||||
if config.entity_protection then
|
if config.entity_protection then
|
||||||
local EntityProtection = require 'modules.control.protection' --- @dep modules.control.protection
|
local EntityProtection = require 'modules.control.protection' --- @dep modules.control.protection
|
||||||
Event.add(EntityProtection.events.on_repeat_violation, function(event)
|
Event.add(EntityProtection.events.on_repeat_violation, function(event)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
--[[-- Commands Module - Protection
|
--[[-- Commands Module - Protection
|
||||||
- Adds a commands that can add and remove protection
|
- Adds commands that can add and remove protection
|
||||||
@commands Protection
|
@commands Protection
|
||||||
]]
|
]]
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ local function show_protected_entity(player, entity)
|
|||||||
renders[player.index][key] = render_id
|
renders[player.index][key] = render_id
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Show a protected are to a player
|
--- Show a protected area to a player
|
||||||
local function show_protected_area(player, surface, area)
|
local function show_protected_area(player, surface, area)
|
||||||
local key = get_area_key(area)
|
local key = get_area_key(area)
|
||||||
if renders[player.index][key] then return end
|
if renders[player.index][key] then return end
|
||||||
@@ -200,7 +200,7 @@ Event.add(Selection.events.on_player_selection_start, function(event)
|
|||||||
end
|
end
|
||||||
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)
|
Event.add(Selection.events.on_player_selection_end, function(event)
|
||||||
if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end
|
if event.selection ~= SelectionProtectEntity and event.selection ~= SelectionProtectArea then return end
|
||||||
for _, id in pairs(renders[event.player_index]) do
|
for _, id in pairs(renders[event.player_index]) do
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ local EntityProtection = {
|
|||||||
-- @tparam number player_index the player index of the player who got mined the entity
|
-- @tparam number player_index the player index of the player who got mined the entity
|
||||||
-- @tparam LuaEntity entity the entity which was mined
|
-- @tparam LuaEntity entity the entity which was mined
|
||||||
on_player_mined_protected = script.generate_event_name(),
|
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
|
-- @event on_repeat_violation
|
||||||
-- @tparam number player_index the player index of the player who got mined the entities
|
-- @tparam number player_index the player index of the player who got mined the entities
|
||||||
-- @tparam LuaEntity entity the last entity which was mined
|
-- @tparam LuaEntity entity the last entity which was mined
|
||||||
@@ -24,8 +24,8 @@ local EntityProtection = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- convert config tables into lookup tables
|
-- Convert config tables into lookup tables
|
||||||
for _, config_key in ipairs{'always_protected_names', 'always_protected_types', 'skip_repeat_names', 'skip_repeat_types'} do
|
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]
|
local tbl = config[config_key]
|
||||||
for key, value in ipairs(tbl) do
|
for key, value in ipairs(tbl) do
|
||||||
tbl[key] = nil
|
tbl[key] = nil
|
||||||
@@ -33,7 +33,7 @@ for _, config_key in ipairs{'always_protected_names', 'always_protected_types',
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- convert ignore role if present
|
-- Require roles if a permission is assigned in the config
|
||||||
local Roles
|
local Roles
|
||||||
if config.ignore_permission then
|
if config.ignore_permission then
|
||||||
Roles = require 'expcore.roles' --- @dep expcore.roles
|
Roles = require 'expcore.roles' --- @dep expcore.roles
|
||||||
@@ -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
|
return config.always_protected_names[entity.name] or config.always_protected_types[entity.type] or false
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if an entity skips repeated
|
--- Check if an entity always triggers repeat protection
|
||||||
local function check_skip_repeat(entity)
|
local function check_always_trigger_repeat(entity)
|
||||||
return config.skip_repeat_names[entity.name] or config.skip_repeat_types[entity.type] or false
|
return config.always_trigger_repeat_names[entity.name] or config.always_trigger_repeat_types[entity.type] or false
|
||||||
end
|
end
|
||||||
|
|
||||||
----- Public Functions -----
|
----- Public Functions -----
|
||||||
@@ -175,7 +175,7 @@ Event.add(defines.events.on_pre_player_mined_item, function(event)
|
|||||||
-- Send events
|
-- Send events
|
||||||
event.name = EntityProtection.events.on_player_mined_protected
|
event.name = EntityProtection.events.on_player_mined_protected
|
||||||
script.raise_event(EntityProtection.events.on_player_mined_protected, event)
|
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
|
player_repeats.count = 0 -- Reset to avoid spamming of events
|
||||||
event.name = EntityProtection.events.on_repeat_violation
|
event.name = EntityProtection.events.on_repeat_violation
|
||||||
script.raise_event(EntityProtection.events.on_repeat_violation, event)
|
script.raise_event(EntityProtection.events.on_repeat_violation, event)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ local Event = require 'utils.event' --- @dep utils.event
|
|||||||
local Global = require 'utils.global' --- @dep utils.global
|
local Global = require 'utils.global' --- @dep utils.global
|
||||||
local Selection = {
|
local Selection = {
|
||||||
events = {
|
events = {
|
||||||
--- When a player enterers selection mode
|
--- When a player enters selection mode
|
||||||
-- @event on_player_selection_start
|
-- @event on_player_selection_start
|
||||||
-- @tparam number player_index the player index of the player who entered selection mode
|
-- @tparam number player_index the player index of the player who entered selection mode
|
||||||
-- @tparam string selection the name of the selection being made
|
-- @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_left_game, stop_after_event)
|
||||||
Event.add(defines.events.on_pre_player_died, 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)
|
local function stop_after_use(event)
|
||||||
if not selections[event.player_index] then return end
|
if not selections[event.player_index] then return end
|
||||||
if not selections[event.player_index].single_use then return end
|
if not selections[event.player_index].single_use then return end
|
||||||
|
|||||||
Reference in New Issue
Block a user