Improve error logging, reduce log level to warning

This commit is contained in:
stujones11 2017-03-22 19:00:48 +00:00
parent 348dad3d4d
commit 27a3823eed
2 changed files with 34 additions and 17 deletions

@ -288,31 +288,50 @@ armor.update_inventory = function(self, player)
-- DEPRECIATED: Legacy inventory support -- DEPRECIATED: Legacy inventory support
end end
armor.set_inventory_stack = function(self, player, i, stack)
local msg = "[set_inventory_stack]"
local name = player:get_player_name()
if not name then
minetest.log("warning", "3d_armor: Player name is nil "..msg)
return
end
local player_inv = player:get_inventory()
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
if not player_inv then
minetest.log("warning", "3d_armor: Player inventory is nil "..msg)
return
elseif not armor_inv then
minetest.log("warning", "3d_armor: Detached armor inventory is nil "..msg)
return
end
player_inv:set_stack("armor", i, stack)
armor_inv:set_stack("armor", i, stack)
end
armor.get_valid_player = function(self, player, msg) armor.get_valid_player = function(self, player, msg)
msg = msg or "" msg = msg or ""
if not player then if not player then
minetest.log("error", "3d_armor: Player reference is nil "..msg) minetest.log("warning", "3d_armor: Player reference is nil "..msg)
return return
end end
local name = player:get_player_name() local name = player:get_player_name()
if not name then if not name then
minetest.log("error", "3d_armor: Player name is nil "..msg) minetest.log("warning", "3d_armor: Player name is nil "..msg)
return return
end end
local pos = player:getpos() local pos = player:getpos()
local player_inv = player:get_inventory() local inv = player:get_inventory()
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
if not pos then if not pos then
minetest.log("error", "3d_armor: Player position is nil "..msg) minetest.log("warning", "3d_armor: Player position is nil "..msg)
return return
elseif not player_inv then elseif not inv then
minetest.log("error", "3d_armor: Player inventory is nil "..msg) minetest.log("warning", "3d_armor: Player inventory is nil "..msg)
return return
elseif not armor_inv then elseif not minetest.get_inventory({type="detached", name=name.."_armor"}) then
minetest.log("error", "3d_armor: Detached armor inventory is nil "..msg) minetest.log("warning", "3d_armor: Detached armor inventory is nil "..msg)
return return
end end
return name, player_inv, armor_inv, pos return name, inv, pos
end end
armor.drop_armor = function(pos, stack) armor.drop_armor = function(pos, stack)

@ -204,17 +204,16 @@ end)
if armor.config.drop == true or armor.config.destroy == true then if armor.config.drop == true or armor.config.destroy == true then
minetest.register_on_dieplayer(function(player) minetest.register_on_dieplayer(function(player)
local name, player_inv, armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]") local name, player_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
if not name then if not name then
return return
end end
local drop = {} local drop = {}
for i=1, player_inv:get_size("armor") do for i=1, player_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i) local stack = player_inv:get_stack("armor", i)
if stack:get_count() > 0 then if stack:get_count() > 0 then
table.insert(drop, stack) table.insert(drop, stack)
armor_inv:set_stack("armor", i, nil) armor:set_inventory_stack(player, i, nil)
player_inv:set_stack("armor", i, nil)
armor:run_callbacks("on_unequip", player, stack) armor:run_callbacks("on_unequip", player, stack)
end end
end end
@ -252,7 +251,7 @@ if armor.config.drop == true or armor.config.destroy == true then
end end
minetest.register_on_player_hpchange(function(player, hp_change) minetest.register_on_player_hpchange(function(player, hp_change)
local name, player_inv, armor_inv = armor:get_valid_player(player, "[on_hpchange]") local name, player_inv = armor:get_valid_player(player, "[on_hpchange]")
if name and hp_change < 0 then if name and hp_change < 0 then
local heal_max = 0 local heal_max = 0
local state = 0 local state = 0
@ -265,8 +264,7 @@ minetest.register_on_player_hpchange(function(player, hp_change)
local heal = def.groups["armor_heal"] or 0 local heal = def.groups["armor_heal"] or 0
local item = stack:get_name() local item = stack:get_name()
stack:add_wear(use) stack:add_wear(use)
armor_inv:set_stack("armor", i, stack) armor:set_inventory_stack("armor", i, stack)
player_inv:set_stack("armor", i, stack)
state = state + stack:get_wear() state = state + stack:get_wear()
items = items + 1 items = items + 1
if stack:get_count() == 0 then if stack:get_count() == 0 then