From 4f4e6f5943b1c58b6d44b05ec6aaf51de037080e Mon Sep 17 00:00:00 2001 From: Niklp Date: Sat, 16 Mar 2024 13:43:05 +0100 Subject: [PATCH] Use early return --- 3d_armor/init.lua | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/3d_armor/init.lua b/3d_armor/init.lua index e589867..1a4028a 100644 --- a/3d_armor/init.lua +++ b/3d_armor/init.lua @@ -394,15 +394,16 @@ end if armor.config.punch_damage == true then minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities) + if hitter == nil then + return + end local name = player:get_player_name() - if hitter ~= nil then - local hit_ip = hitter:is_player() - if name and hit_ip and minetest.is_protected(player:get_pos(), "") then - return - elseif name then - armor:punch(player, hitter, time_from_last_punch, tool_capabilities) - last_punch_time[name] = minetest.get_gametime() - end + local hit_ip = hitter:is_player() + if name and hit_ip and minetest.is_protected(player:get_pos(), "") then + return + elseif name then + armor:punch(player, hitter, time_from_last_punch, tool_capabilities) + last_punch_time[name] = minetest.get_gametime() end end) end