From a1c0a1f82f95bfa7991c64f1ef3c143c562b83ea Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 5 Mar 2019 14:33:16 +0100 Subject: [PATCH] Harden mcl_skins against missing metadata --- mods/PLAYER/mcl_skins/init.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mods/PLAYER/mcl_skins/init.lua b/mods/PLAYER/mcl_skins/init.lua index f8bd82645..cfb0ff831 100644 --- a/mods/PLAYER/mcl_skins/init.lua +++ b/mods/PLAYER/mcl_skins/init.lua @@ -53,6 +53,7 @@ while true do end f = io.open(mcl_skins.modpath .. "/meta/" .. metafile) + data = nil if f then data = minetest.deserialize("return {" .. f:read('*all') .. "}") f:close() @@ -199,7 +200,12 @@ minetest.register_chatcommand("setskin", { local skinfile = "#"..skin_id local meta = mcl_skins.meta[mcl_skins.skins[playername]] - local your_msg = S("Your skin has been set to: @1 (@2)", meta.name, skinfile) + local your_msg + if not meta.name or meta.name == "" then + your_msg = S("Your skin has been set to: @1", skinfile) + else + your_msg = S("Your skin has been set to: @1 (@2)", meta.name, skinfile) + end if name == playername then return true, your_msg else @@ -233,7 +239,7 @@ mcl_skins.show_formspec = function(playername) for i = 0, mcl_skins.skin_count do - local label = S("@1 (@2)", mcl_skins.meta[mcl_skins.list[i] ].name, "#"..i) + local label = S("@1 (@2)", mcl_skins.meta[mcl_skins.list[i]].name, "#"..i) formspec = formspec .. minetest.formspec_escape(label) @@ -252,7 +258,7 @@ mcl_skins.show_formspec = function(playername) formspec = formspec .. "image[0,0;1.35,2.7;" .. mcl_skins.previews[playername] .. ".png]" if meta then - if meta.name then + if meta.name and meta.name ~= "" then formspec = formspec .. "label[2,0.5;" .. minetest.formspec_escape(S("Name: @1", meta.name)) .. "]" end end