mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Fixed protection issues
This commit is contained in:
@@ -29,6 +29,7 @@ return {
|
|||||||
'modules.commands.home',
|
'modules.commands.home',
|
||||||
'modules.commands.connect',
|
'modules.commands.connect',
|
||||||
'modules.commands.last-location',
|
'modules.commands.last-location',
|
||||||
|
'modules.commands.protection',
|
||||||
|
|
||||||
--- Addons
|
--- Addons
|
||||||
'modules.addons.chat-popups',
|
'modules.addons.chat-popups',
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ Roles.new_role('Trainee','TrMod')
|
|||||||
'command/give-warning',
|
'command/give-warning',
|
||||||
'command/get-warnings',
|
'command/get-warnings',
|
||||||
'command/get-reports',
|
'command/get-reports',
|
||||||
|
'command/protect-entity',
|
||||||
|
'command/protect-area',
|
||||||
'command/jail',
|
'command/jail',
|
||||||
'command/unjail',
|
'command/unjail',
|
||||||
'command/kick',
|
'command/kick',
|
||||||
|
|||||||
@@ -82,4 +82,14 @@ offline=You cannot connect as the server is currently offline: __1__
|
|||||||
none-matching=No servers were found with that name, if you used an address please append true to the end of your command.
|
none-matching=No servers were found with that name, if you used an address please append true to the end of your command.
|
||||||
|
|
||||||
[expcom-lastlocation]
|
[expcom-lastlocation]
|
||||||
response=Last location of __1__ was [gps=__2__,__3__]
|
response=Last location of __1__ was [gps=__2__,__3__]
|
||||||
|
|
||||||
|
[expcom-protection]
|
||||||
|
entered-entity-selection=Entered entity selection, select entites to protect, hold shift to remove protection.
|
||||||
|
entered-area-selection=Entered area selection, select areas to protect, hold shift to remove protection.
|
||||||
|
protected-entities=__1__ entities have been protected.
|
||||||
|
unprotected-entities=__1__ entities have been unprotected.
|
||||||
|
already-protected=This area is already protected.
|
||||||
|
protected-area=This area is now protected.
|
||||||
|
unprotected-area=This area is now unprotected.
|
||||||
|
repeat-offence=__1__ has removed __2__ at [gps=__3__,__4__]
|
||||||
@@ -52,12 +52,12 @@ Commands.new_command('protect-area', 'Toggles area protection selection, hold sh
|
|||||||
Selection.stop(player)
|
Selection.stop(player)
|
||||||
else
|
else
|
||||||
Selection.start(player, SelectionProtectArea)
|
Selection.start(player, SelectionProtectArea)
|
||||||
return Commands.success{'expcom-protection.entered-entity-selection'}
|
return Commands.success{'expcom-protection.entered-area-selection'}
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- When an area is selected to add protection to entities
|
--- When an area is selected to add protection to entities
|
||||||
Selection.on_selection(SelectionProtectEntity, function(_, event)
|
Selection.on_selection(SelectionProtectEntity, function(event)
|
||||||
for _, entity in ipairs(event.entities) do
|
for _, entity in ipairs(event.entities) do
|
||||||
EntityProtection.add_entity(entity)
|
EntityProtection.add_entity(entity)
|
||||||
end
|
end
|
||||||
@@ -65,7 +65,7 @@ Selection.on_selection(SelectionProtectEntity, function(_, event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- When an area is selected to remove protection from entities
|
--- When an area is selected to remove protection from entities
|
||||||
Selection.on_alt_selection(SelectionProtectEntity, function(_, event)
|
Selection.on_alt_selection(SelectionProtectEntity, function(event)
|
||||||
for _, entity in ipairs(event.entities) do
|
for _, entity in ipairs(event.entities) do
|
||||||
EntityProtection.remove_entity(entity)
|
EntityProtection.remove_entity(entity)
|
||||||
end
|
end
|
||||||
@@ -73,7 +73,7 @@ Selection.on_alt_selection(SelectionProtectEntity, function(_, event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- When an area is selected to add protection to the area
|
--- When an area is selected to add protection to the area
|
||||||
Selection.on_selection(SelectionProtectEntity, function(_, event)
|
Selection.on_selection(SelectionProtectArea, function(event)
|
||||||
local area = aabb_align_expand(event.area)
|
local area = aabb_align_expand(event.area)
|
||||||
local areas = EntityProtection.get_areas(event.surface)
|
local areas = EntityProtection.get_areas(event.surface)
|
||||||
for _, next_area in pairs(areas) do
|
for _, next_area in pairs(areas) do
|
||||||
@@ -86,13 +86,19 @@ Selection.on_selection(SelectionProtectEntity, function(_, event)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
--- When an area is selected to remove protection from the area
|
--- When an area is selected to remove protection from the area
|
||||||
Selection.on_alt_selection(SelectionProtectEntity, function(_, event)
|
Selection.on_alt_selection(SelectionProtectArea, function(event)
|
||||||
local area = aabb_align_expand(event.area)
|
local area = aabb_align_expand(event.area)
|
||||||
local areas = EntityProtection.get_areas(event.surface)
|
local areas = EntityProtection.get_areas(event.surface)
|
||||||
for _, next_area in pairs(areas) do
|
for _, next_area in pairs(areas) do
|
||||||
if aabb_area_enclosed(next_area, area) then
|
if aabb_area_enclosed(next_area, area) then
|
||||||
EntityProtection.remove_area(event.surface, area)
|
EntityProtection.remove_area(event.surface, next_area)
|
||||||
Commands.print{'expcom-protection.unprotected-area'}
|
Commands.print{'expcom-protection.unprotected-area'}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
--- When there is a repeat offence print it in chat
|
||||||
|
Event.add(EntityProtection.events.on_repeat_violation, function(event)
|
||||||
|
local player_name = format_chat_player_name(event.player_index)
|
||||||
|
Roles.print_to_roles_higher('Regular', {'expcom-protection.repeat-offence', player_name, event.entity.localised_name, event.entity.position.x, event.entity.position.y})
|
||||||
end)
|
end)
|
||||||
@@ -104,6 +104,7 @@ end
|
|||||||
|
|
||||||
--- Check if an entity is protected
|
--- Check if an entity is protected
|
||||||
function EntityProtection.is_entity_protected(entity)
|
function EntityProtection.is_entity_protected(entity)
|
||||||
|
if check_always_protected(entity) then return true end
|
||||||
local entities = protected_entities[entity.surface.index]
|
local entities = protected_entities[entity.surface.index]
|
||||||
if not entities then return false end
|
if not entities then return false end
|
||||||
return entities[get_entity_key(entity)] == entity
|
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
|
if config.ignore_permission and Roles.player_allowed(player, config.ignore_permission) then return end
|
||||||
|
|
||||||
-- Check if the entity is protected
|
-- 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)
|
or EntityProtection.is_position_protected(entity.surface, entity.position)
|
||||||
then
|
then
|
||||||
-- Update repeats
|
-- Update repeats
|
||||||
@@ -190,4 +191,14 @@ Event.on_nth_tick(config.refresh_rate, function()
|
|||||||
end
|
end
|
||||||
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
|
return EntityProtection
|
||||||
@@ -82,27 +82,25 @@ function Selection.is_selecting(player, selection_name)
|
|||||||
end
|
end
|
||||||
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 string selection_name The name of the selection to listen for
|
||||||
-- @tparam function handler The event handler
|
-- @tparam function handler The event handler
|
||||||
function Selection.on_selection(selection_name, handler)
|
function Selection.on_selection(selection_name, handler)
|
||||||
Event.add(defines.events.on_player_selected_area, function(event)
|
Event.add(defines.events.on_player_selected_area, function(event)
|
||||||
local selection = selections[event.player_index]
|
local selection = selections[event.player_index]
|
||||||
if not selection or selection.name ~= selection_name then return end
|
if not selection or selection.name ~= selection_name then return end
|
||||||
local player = game.get_player(event.player_index)
|
handler(event, unpack(selection.arguments))
|
||||||
handler(player, event, unpack(selection.arguments))
|
|
||||||
end)
|
end)
|
||||||
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 string selection_name The name of the selection to listen for
|
||||||
-- @param function handler The event handler
|
-- @param function handler The event handler
|
||||||
function Selection.on_alt_selection(selection_name, handler)
|
function Selection.on_alt_selection(selection_name, handler)
|
||||||
Event.add(defines.events.on_player_alt_selected_area, function(event)
|
Event.add(defines.events.on_player_alt_selected_area, function(event)
|
||||||
local selection = selections[event.player_index]
|
local selection = selections[event.player_index]
|
||||||
if not selection or selection.name ~= selection_name then return end
|
if not selection or selection.name ~= selection_name then return end
|
||||||
local player = game.get_player(event.player_index)
|
handler(event, unpack(selection.arguments))
|
||||||
handler(player, event, unpack(selection.arguments))
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user