Fix crash in craftguide when player leaves

This commit is contained in:
Wuzzy 2019-03-14 12:08:11 +01:00
parent 41842c73c6
commit 0c8db3e556
1 changed files with 17 additions and 11 deletions

View File

@ -969,16 +969,6 @@ end
M.register_on_mods_loaded(get_init_items) M.register_on_mods_loaded(get_init_items)
M.register_on_joinplayer(function(player)
local name = player:get_player_name()
init_data(name)
end)
M.register_on_leaveplayer(function(player)
local name = player:get_player_name()
player_data[name] = nil
end)
-- TODO: Remove sfinv support -- TODO: Remove sfinv support
if sfinv_only then if sfinv_only then
sfinv.register_page("craftguide:craftguide", { sfinv.register_page("craftguide:craftguide", {
@ -1106,6 +1096,8 @@ if progressive_mode then
mcl_craftguide.add_recipe_filter("Default progressive filter", progressive_filter) mcl_craftguide.add_recipe_filter("Default progressive filter", progressive_filter)
M.register_on_joinplayer(function(player) M.register_on_joinplayer(function(player)
local name = player:get_player_name()
init_data(name)
local meta = player:get_meta() local meta = player:get_meta()
local name = player:get_player_name() local name = player:get_player_name()
local data = player_data[name] local data = player_data[name]
@ -1121,7 +1113,11 @@ if progressive_mode then
meta:set_string("inv_items", serialize(data.inv_items)) meta:set_string("inv_items", serialize(data.inv_items))
end end
M.register_on_leaveplayer(save_meta) M.register_on_leaveplayer(function(player)
save_meta(player)
local name = player:get_player_name()
player_data[name] = nil
end)
M.register_on_shutdown(function() M.register_on_shutdown(function()
local players = M.get_connected_players() local players = M.get_connected_players()
@ -1130,6 +1126,16 @@ if progressive_mode then
save_meta(player) save_meta(player)
end end
end) end)
else
M.register_on_joinplayer(function(player)
local name = player:get_player_name()
init_data(name)
end)
M.register_on_leaveplayer(function(player)
local name = player:get_player_name()
player_data[name] = nil
end)
end end
function mcl_craftguide.show(name) function mcl_craftguide.show(name)