More error logging improvements, fix #21

This commit is contained in:
stujones11 2015-04-02 20:59:45 +01:00
parent 6942aa37d2
commit 9da2395586

View File

@ -110,17 +110,8 @@ armor.update_player_visuals = function(self, player)
end
armor.set_player_armor = function(self, player)
if not player then
return
end
local name = player:get_player_name()
local name, player_inv = armor:get_valid_player(player, "[set_player_armor]")
if not name then
minetest.log("error", "3d_armor: Player name is nil [set_player_armor]")
return
end
local player_inv = player:get_inventory()
if not player_inv then
minetest.log("error", "3d_armor: Player inventory is nil [set_player_armor]")
return
end
local armor_texture = "3d_armor_trans.png"
@ -204,13 +195,8 @@ armor.set_player_armor = function(self, player)
end
armor.update_armor = function(self, player)
if not player then
minetest.log("error", "3d_armor: Player reference is nil [update_armor]")
return
end
local name = player:get_player_name()
local name, player_inv, armor_inv = armor:get_valid_player(player, "[update_armor]")
if not name then
minetest.log("error", "3d_armor: Player name is nil[update_armor]")
return
end
local hp = player:get_hp() or 0
@ -218,15 +204,6 @@ armor.update_armor = function(self, player)
return
end
if self.player_hp[name] > hp then
local player_inv = player:get_inventory()
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
if not player_inv then
minetest.log("error", "3d_armor: Player inventory is nil [update_armor]")
return
elseif not armor_inv then
minetest.log("error", "3d_armor: Detached inventory is nil [update_armor]")
return
end
local heal_max = 0
local state = 0
local items = 0
@ -280,10 +257,6 @@ armor.get_preview = function(self, name)
end
armor.get_armor_formspec = function(self, name)
if not name then
minetest.log("error", "3d_armor: Player name is nil [get_armor_formspec]")
return ""
end
if not armor.textures[name] then
minetest.log("error", "3d_armor: Player texture["..name.."] is nil [get_armor_formspec]")
return ""
@ -299,13 +272,8 @@ armor.get_armor_formspec = function(self, name)
end
armor.update_inventory = function(self, player)
if not player then
minetest.log("error", "3d_armor: Player reference is nil [update_inventory]")
return
end
local name = player:get_player_name()
local name = armor:get_valid_player(player, "[set_player_armor]")
if not name then
minetest.log("error", "3d_armor: Player name is nil [update_inventory]")
return
end
if inv_mod == "unified_inventory" then
@ -325,6 +293,33 @@ armor.update_inventory = function(self, player)
end
end
armor.get_valid_player = function(self, player, msg)
msg = msg or ""
if not player then
minetest.log("error", "3d_armor: Player reference is nil "..msg)
return
end
local name = player:get_player_name()
if not name then
minetest.log("error", "3d_armor: Player name is nil "..msg)
return
end
local pos = player:getpos()
local player_inv = player:get_inventory()
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
if not pos then
minetest.log("error", "3d_armor: Player position is nil "..msg)
return
elseif not player_inv then
minetest.log("error", "3d_armor: Player inventory is nil "..msg)
return
elseif not armor_inv then
minetest.log("error", "3d_armor: Detached armor inventory is nil "..msg)
return
end
return name, player_inv, armor_inv, pos
end
-- Register Player Model
default.player_register_model("3d_armor_character.b3d", {
@ -347,7 +342,10 @@ default.player_register_model("3d_armor_character.b3d", {
-- Register Callbacks
minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name()
local name = armor:get_valid_player(player, "[on_player_receive_fields]")
if not name then
return
end
if inv_mod == "inventory_plus" and fields.armor then
local formspec = armor:get_armor_formspec(name)
inventory_plus.set_inventory_formspec(player, formspec)
@ -467,12 +465,11 @@ end)
if ARMOR_DROP == true or ARMOR_DESTROY == true then
minetest.register_on_dieplayer(function(player)
local name = player:get_player_name()
local pos = player:getpos()
if name and pos then
local name, player_inv, armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
if not name then
return
end
local drop = {}
local player_inv = player:get_inventory()
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
for i=1, player_inv:get_size("armor") do
local stack = armor_inv:get_stack("armor", i)
if stack:get_count() > 0 then
@ -525,7 +522,6 @@ if ARMOR_DROP == true or ARMOR_DESTROY == true then
end
end
end
end
end)
end