mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +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:
@@ -3,13 +3,13 @@
|
||||
|
||||
local Event = require 'utils.event' --- @dep utils.event
|
||||
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 player = game.players[event.player_index]
|
||||
local inv = player.get_main_inventory()
|
||||
move_items(inv.get_contents())
|
||||
move_items_stack(inv)
|
||||
inv.clear()
|
||||
end
|
||||
|
||||
for _, event_name in ipairs(events) do Event.add(event_name, clear_items) end
|
||||
for _, event_name in ipairs(events) do Event.add(event_name, clear_items) end
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
]]
|
||||
|
||||
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'
|
||||
|
||||
--- Clears a players inventory
|
||||
@@ -14,10 +14,10 @@ Commands.new_command('clear-inventory', 'Clears a players inventory')
|
||||
:add_param('player', false, 'player-role')
|
||||
:add_alias('clear-inv', 'move-inventory', 'move-inv')
|
||||
:register(function(_, player)
|
||||
local inv = player.get_main_inventory()
|
||||
if not inv then
|
||||
return Commands.error{'expcore-commands.reject-player-alive'}
|
||||
end
|
||||
move_items(inv.get_contents())
|
||||
inv.clear()
|
||||
end)
|
||||
local inv = player.get_main_inventory()
|
||||
if not inv then
|
||||
return Commands.error{'expcore-commands.reject-player-alive'}
|
||||
end
|
||||
move_items_stack(inv)
|
||||
inv.clear()
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user