Fixed protection issues

This commit is contained in:
Cooldude2606
2021-04-24 21:05:11 +01:00
parent 891663edb9
commit d83f1e3aea
6 changed files with 42 additions and 14 deletions

View File

@@ -104,6 +104,7 @@ end
--- Check if an entity is protected
function EntityProtection.is_entity_protected(entity)
if check_always_protected(entity) then return true end
local entities = protected_entities[entity.surface.index]
if not entities then return false end
return entities[get_entity_key(entity)] == entity
@@ -158,7 +159,7 @@ Event.add(defines.events.on_pre_player_mined_item, function(event)
if config.ignore_permission and Roles.player_allowed(player, config.ignore_permission) then return end
-- Check if the entity is protected
if check_always_protected(entity) or EntityProtection.is_entity_protected(entity)
if EntityProtection.is_entity_protected(entity)
or EntityProtection.is_position_protected(entity.surface, entity.position)
then
-- Update repeats
@@ -190,4 +191,14 @@ Event.on_nth_tick(config.refresh_rate, function()
end
end)
--- When an entity is removed remove it from the protection list
local function event_remove_entity(event)
EntityProtection.remove_entity(event.entity)
end
Event.add(defines.events.on_pre_player_mined_item, event_remove_entity)
Event.add(defines.events.on_robot_pre_mined, event_remove_entity)
Event.add(defines.events.on_entity_died, event_remove_entity)
Event.add(defines.events.script_raised_destroy, event_remove_entity)
return EntityProtection

View File

@@ -82,27 +82,25 @@ function Selection.is_selecting(player, selection_name)
end
end
--- Filter on_player_selected_area to this custom selection, pretends with player and appends with selection arguments
--- Filter on_player_selected_area to this custom selection, appends the selection arguments
-- @tparam string selection_name The name of the selection to listen for
-- @tparam function handler The event handler
function Selection.on_selection(selection_name, handler)
Event.add(defines.events.on_player_selected_area, function(event)
local selection = selections[event.player_index]
if not selection or selection.name ~= selection_name then return end
local player = game.get_player(event.player_index)
handler(player, event, unpack(selection.arguments))
handler(event, unpack(selection.arguments))
end)
end
--- Filter on_player_alt_selected_area to this custom selection, pretends with player and appends with selection arguments
--- Filter on_player_alt_selected_area to this custom selection, appends the selection arguments
-- @param string selection_name The name of the selection to listen for
-- @param function handler The event handler
function Selection.on_alt_selection(selection_name, handler)
Event.add(defines.events.on_player_alt_selected_area, function(event)
local selection = selections[event.player_index]
if not selection or selection.name ~= selection_name then return end
local player = game.get_player(event.player_index)
handler(player, event, unpack(selection.arguments))
handler(event, unpack(selection.arguments))
end)
end