mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-01-01 05:01:40 +09:00
fix: LuaItemStack could be invalid
Fixed an issue with clearing inventories of players where the command failed due to it attempting to access LuaItemStacks that were invalid for read
This commit is contained in:
@@ -645,11 +645,13 @@ function Common.move_items_stack(items, surface, position, radius, chest_type)
|
|||||||
local last_chest
|
local last_chest
|
||||||
for i=1,#items do
|
for i=1,#items do
|
||||||
local item = items[i]
|
local item = items[i]
|
||||||
|
if item.valid_for_read then
|
||||||
local chest = next_chest(item)
|
local chest = next_chest(item)
|
||||||
if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
|
if not chest or not chest.valid then return error(string.format('Cant move item %s to %s{%s, %s} no valid chest in radius', item_name, surface.name, p.x, p.y)) end
|
||||||
chest.insert(item)
|
chest.insert(item)
|
||||||
last_chest = chest
|
last_chest = chest
|
||||||
end
|
end
|
||||||
|
end
|
||||||
return last_chest
|
return last_chest
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
local Event = require 'utils.event' --- @dep utils.event
|
local Event = require 'utils.event' --- @dep utils.event
|
||||||
local events = require 'config.inventory_clear' --- @dep config.inventory_clear
|
local events = require 'config.inventory_clear' --- @dep config.inventory_clear
|
||||||
local move_items = _C.move_items --- @dep expcore.common
|
local move_items_stack = _C.move_items_stack --- @dep expcore.common
|
||||||
|
|
||||||
local function clear_items(event)
|
local function clear_items(event)
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
local inv = player.get_main_inventory()
|
local inv = player.get_main_inventory()
|
||||||
move_items(inv.get_contents())
|
move_items_stack(inv)
|
||||||
inv.clear()
|
inv.clear()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
local Commands = require 'expcore.commands' --- @dep expcore.commands
|
||||||
local move_items = _C.move_items --- @dep expcore.common
|
local move_items_stack = _C.move_items_stack --- @dep expcore.common
|
||||||
require 'config.expcore.command_role_parse'
|
require 'config.expcore.command_role_parse'
|
||||||
|
|
||||||
--- Clears a players inventory
|
--- Clears a players inventory
|
||||||
@@ -18,6 +18,6 @@ Commands.new_command('clear-inventory', 'Clears a players inventory')
|
|||||||
if not inv then
|
if not inv then
|
||||||
return Commands.error{'expcore-commands.reject-player-alive'}
|
return Commands.error{'expcore-commands.reject-player-alive'}
|
||||||
end
|
end
|
||||||
move_items(inv.get_contents())
|
move_items_stack(inv)
|
||||||
inv.clear()
|
inv.clear()
|
||||||
end)
|
end)
|
||||||
Reference in New Issue
Block a user