Add nil checks for placer
authorDTA7 <dta7e@t-online.de>
Sun, 1 Oct 2017 13:41:58 +0000 (15:41 +0200)
committerparamat <mat.gregory@virginmedia.com>
Wed, 15 Nov 2017 23:16:28 +0000 (23:16 +0000)
14 files changed:
mods/beds/api.lua
mods/boats/init.lua
mods/bucket/init.lua
mods/carts/cart_entity.lua
mods/default/functions.lua
mods/default/nodes.lua
mods/default/tools.lua
mods/default/torch.lua
mods/default/trees.lua
mods/doors/init.lua
mods/farming/api.lua
mods/flowers/init.lua
mods/screwdriver/init.lua
mods/stairs/init.lua

index 3632dc0cd3a465cbbbe3808a99e0490c2000ab17..9349545a972b421bf63a02a4a175c662c9626b6c 100644 (file)
@@ -49,7 +49,8 @@ function beds.register_bed(name, def)
                        local node = minetest.get_node(under)
                        local udef = minetest.registered_nodes[node.name]
                        if udef and udef.on_rightclick and
-                                       not (placer and placer:get_player_control().sneak) then
+                                       not (placer and placer:is_player() and
+                                       placer:get_player_control().sneak) then
                                return udef.on_rightclick(under, node, placer, itemstack,
                                        pointed_thing) or itemstack
                        end
@@ -61,9 +62,11 @@ function beds.register_bed(name, def)
                                pos = pointed_thing.above
                        end
 
-                       if minetest.is_protected(pos, placer:get_player_name()) and
-                                       not minetest.check_player_privs(placer, "protection_bypass") then
-                               minetest.record_protection_violation(pos, placer:get_player_name())
+                       local player_name = placer and placer:get_player_name() or ""
+
+                       if minetest.is_protected(pos, player_name) and
+                                       not minetest.check_player_privs(player_name, "protection_bypass") then
+                               minetest.record_protection_violation(pos, player_name)
                                return itemstack
                        end
 
@@ -72,12 +75,13 @@ function beds.register_bed(name, def)
                                return itemstack
                        end
 
-                       local dir = minetest.dir_to_facedir(placer:get_look_dir())
+                       local dir = placer and placer:get_look_dir() and
+                               minetest.dir_to_facedir(placer:get_look_dir()) or 0
                        local botpos = vector.add(pos, minetest.facedir_to_dir(dir))
 
-                       if minetest.is_protected(botpos, placer:get_player_name()) and
-                                       not minetest.check_player_privs(placer, "protection_bypass") then
-                               minetest.record_protection_violation(botpos, placer:get_player_name())
+                       if minetest.is_protected(botpos, player_name) and
+                                       not minetest.check_player_privs(player_name, "protection_bypass") then
+                               minetest.record_protection_violation(botpos, player_name)
                                return itemstack
                        end
 
@@ -90,7 +94,7 @@ function beds.register_bed(name, def)
                        minetest.set_node(botpos, {name = name .. "_top", param2 = dir})
 
                        if not (creative and creative.is_enabled_for
-                                       and creative.is_enabled_for(placer:get_player_name())) then
+                                       and creative.is_enabled_for(player_name)) then
                                itemstack:take_item()
                        end
                        return itemstack
index 38025d165a447a7d31cffd701bedc8859ae19ee6..72ca478f8dc6a61a9e63023b9c0898f7daf58ddf 100644 (file)
@@ -230,7 +230,8 @@ minetest.register_craftitem("boats:boat", {
                local node = minetest.get_node(under)
                local udef = minetest.registered_nodes[node.name]
                if udef and udef.on_rightclick and
-                               not (placer and placer:get_player_control().sneak) then
+                               not (placer and placer:is_player() and
+                               placer:get_player_control().sneak) then
                        return udef.on_rightclick(under, node, placer, itemstack,
                                pointed_thing) or itemstack
                end
@@ -244,9 +245,12 @@ minetest.register_craftitem("boats:boat", {
                pointed_thing.under.y = pointed_thing.under.y + 0.5
                boat = minetest.add_entity(pointed_thing.under, "boats:boat")
                if boat then
-                       boat:setyaw(placer:get_look_horizontal())
-                       if not (creative and creative.is_enabled_for
-                                       and creative.is_enabled_for(placer:get_player_name())) then
+                       if placer then
+                               boat:setyaw(placer:get_look_horizontal())
+                       end
+                       local player_name = placer and placer:get_player_name() or ""
+                       if not (creative and creative.is_enabled_for and
+                                       creative.is_enabled_for(player_name)) then
                                itemstack:take_item()
                        end
                end
index 445653260fe265a6a7a90a05a81c60a450db256a..9c1481ef2096ac450924f271b345cf9fd789d5f3 100644 (file)
@@ -69,7 +69,8 @@ function bucket.register_liquid(source, flowing, itemname, inventory_image, name
 
                                -- Call on_rightclick if the pointed node defines it
                                if ndef and ndef.on_rightclick and
-                                  user and not user:get_player_control().sneak then
+                                               not (user and user:is_player() and
+                                               user:get_player_control().sneak) then
                                        return ndef.on_rightclick(
                                                pointed_thing.under,
                                                node, user,
index 88fd2be65ffe42f703c3d68e2a02e1b4c958475d..434ea943f9b01b41f82697fead530769dfe2ad43 100644 (file)
@@ -363,7 +363,8 @@ minetest.register_craftitem("carts:cart", {
                local node = minetest.get_node(under)
                local udef = minetest.registered_nodes[node.name]
                if udef and udef.on_rightclick and
-                               not (placer and placer:get_player_control().sneak) then
+                               not (placer and placer:is_player() and
+                               placer:get_player_control().sneak) then
                        return udef.on_rightclick(under, node, placer, itemstack,
                                pointed_thing) or itemstack
                end
index 4eb1a1c97db2bde9f303185ee2b153b4160de5b3..20cf492a3f856fae542df3a02895645310c4b9e6 100644 (file)
@@ -334,7 +334,7 @@ end
 -- Prevent decay of placed leaves
 
 default.after_place_leaves = function(pos, placer, itemstack, pointed_thing)
-       if placer and not placer:get_player_control().sneak then
+       if placer and placer:is_player() and not placer:get_player_control().sneak then
                local node = minetest.get_node(pos)
                node.param2 = 1
                minetest.set_node(pos, node)
index 545d02c0086a00db527f0bc9cf3fce5bf78a4e13..4aa35dc641518c386636ab39510710bf8c5775c3 100644 (file)
@@ -667,9 +667,7 @@ minetest.register_node("default:apple", {
        sounds = default.node_sound_leaves_defaults(),
 
        after_place_node = function(pos, placer, itemstack)
-               if placer:is_player() then
-                       minetest.set_node(pos, {name = "default:apple", param2 = 1})
-               end
+               minetest.set_node(pos, {name = "default:apple", param2 = 1})
        end,
 })
 
index 1e7197851468cf4e2a14f22e3aa607da6c34d622..067613d355bc7139b5feda24423d82e4120dc406 100644 (file)
@@ -389,7 +389,8 @@ minetest.register_tool("default:key", {
                local node = minetest.get_node(under)
                local def = minetest.registered_nodes[node.name]
                if def and def.on_rightclick and
-                               not (placer and placer:get_player_control().sneak) then
+                               not (placer and placer:is_player() and
+                               placer:get_player_control().sneak) then
                        return def.on_rightclick(under, node, placer, itemstack,
                                pointed_thing) or itemstack
                end
index 016ae685ca5106fd6d78a24a9deaa70310a6de62..a99a38db74bd4002be8f9781b46f059fb896b6b4 100644 (file)
@@ -78,7 +78,8 @@ minetest.register_node("default:torch", {
                local node = minetest.get_node(under)
                local def = minetest.registered_nodes[node.name]
                if def and def.on_rightclick and
-                       ((not placer) or (placer and not placer:get_player_control().sneak)) then
+                       not (placer and placer:is_player() and
+                       placer:get_player_control().sneak) then
                        return def.on_rightclick(under, node, placer, itemstack,
                                pointed_thing) or itemstack
                end
index d00a6b5e8caeec956f6c2f0e59f0a7bb8b9b2b82..44176d779e0ac482aa55e50cd603f08135931240 100644 (file)
@@ -468,7 +468,9 @@ function default.sapling_on_place(itemstack, placer, pointed_thing,
        local node = minetest.get_node_or_nil(pos)
        local pdef = node and minetest.registered_nodes[node.name]
 
-       if pdef and pdef.on_rightclick and not placer:get_player_control().sneak then
+       if pdef and pdef.on_rightclick and
+                       not (placer and placer:is_player() and
+                       placer:get_player_control().sneak) then
                return pdef.on_rightclick(pos, node, placer, itemstack, pointed_thing)
        end
 
@@ -481,7 +483,7 @@ function default.sapling_on_place(itemstack, placer, pointed_thing,
                end
        end
 
-       local player_name = placer:get_player_name()
+       local player_name = placer and placer:get_player_name() or ""
        -- Check sapling position for protection
        if minetest.is_protected(pos, player_name) then
                minetest.record_protection_violation(pos, player_name)
index 2fcc23de94534b73352fc0317a5b610b1f1bc05e..51879678ead7841a2ce9ea3ad2a9a01102483345 100644 (file)
@@ -266,7 +266,8 @@ function doors.register(name, def)
                        local node = minetest.get_node(pointed_thing.under)
                        local pdef = minetest.registered_nodes[node.name]
                        if pdef and pdef.on_rightclick and
-                                       not placer:get_player_control().sneak then
+                                       not (placer and placer:is_player() and
+                                       placer:get_player_control().sneak) then
                                return pdef.on_rightclick(pointed_thing.under,
                                                node, placer, itemstack, pointed_thing)
                        end
@@ -290,12 +291,12 @@ function doors.register(name, def)
                                return itemstack
                        end
 
-                       local pn = placer:get_player_name()
+                       local pn = placer and placer:get_player_name() or ""
                        if minetest.is_protected(pos, pn) or minetest.is_protected(above, pn) then
                                return itemstack
                        end
 
-                       local dir = minetest.dir_to_facedir(placer:get_look_dir())
+                       local dir = placer and minetest.dir_to_facedir(placer:get_look_dir()) or 0
 
                        local ref = {
                                {x = -1, y = 0, z = 0},
index 150301ad5b0064bfb8ff73ba55cd1a8f6fd687ea..1c63ee348e57f1c8420fc39e84dfa35918d21a7a 100644 (file)
@@ -144,12 +144,14 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
        local under = minetest.get_node(pt.under)
        local above = minetest.get_node(pt.above)
 
-       if minetest.is_protected(pt.under, placer:get_player_name()) then
-               minetest.record_protection_violation(pt.under, placer:get_player_name())
+       local player_name = placer and placer:get_player_name() or ""
+
+       if minetest.is_protected(pt.under, player_name) then
+               minetest.record_protection_violation(pt.under, player_name)
                return
        end
-       if minetest.is_protected(pt.above, placer:get_player_name()) then
-               minetest.record_protection_violation(pt.above, placer:get_player_name())
+       if minetest.is_protected(pt.above, player_name) then
+               minetest.record_protection_violation(pt.above, player_name)
                return
        end
 
@@ -180,7 +182,7 @@ farming.place_seed = function(itemstack, placer, pointed_thing, plantname)
        minetest.add_node(pt.above, {name = plantname, param2 = 1})
        tick(pt.above)
        if not (creative and creative.is_enabled_for
-                       and creative.is_enabled_for(placer:get_player_name())) then
+                       and creative.is_enabled_for(player_name)) then
                itemstack:take_item()
        end
        return itemstack
@@ -310,7 +312,8 @@ farming.register_plant = function(name, def)
                        local node = minetest.get_node(under)
                        local udef = minetest.registered_nodes[node.name]
                        if udef and udef.on_rightclick and
-                                       not (placer and placer:get_player_control().sneak) then
+                                       not (placer and placer:is_player() and
+                                       placer:get_player_control().sneak) then
                                return udef.on_rightclick(under, node, placer, itemstack,
                                        pointed_thing) or itemstack
                        end
index d28764f9a71af5a2acc73f3343a97844de52fc94..6836baa72892d5406793edec29cbf0e402e1cb7d 100644 (file)
@@ -278,7 +278,7 @@ minetest.register_node("flowers:waterlily", {
                local pos = pointed_thing.above
                local node = minetest.get_node(pointed_thing.under)
                local def = minetest.registered_nodes[node.name]
-               local player_name = placer:get_player_name()
+               local player_name = placer and placer:get_player_name() or ""
 
                if def and def.on_rightclick then
                        return def.on_rightclick(pointed_thing.under, node, placer, itemstack,
index e76f0545f1c419e6054ce72e536b8c36b9cdc3c3..634edf85a9ec6295a70ed0d87328cccd024e452e 100644 (file)
@@ -85,9 +85,10 @@ screwdriver.handler = function(itemstack, user, pointed_thing, mode, uses)
        end
 
        local pos = pointed_thing.under
+       local player_name = user and user:get_player_name() or ""
 
-       if minetest.is_protected(pos, user:get_player_name()) then
-               minetest.record_protection_violation(pos, user:get_player_name())
+       if minetest.is_protected(pos, player_name) then
+               minetest.record_protection_violation(pos, player_name)
                return
        end
 
@@ -133,8 +134,8 @@ screwdriver.handler = function(itemstack, user, pointed_thing, mode, uses)
                minetest.check_for_falling(pos)
        end
 
-       if not (creative and creative.is_enabled_for
-                       and creative.is_enabled_for(user:get_player_name())) then
+       if not (creative and creative.is_enabled_for and
+                       creative.is_enabled_for(player_name)) then
                itemstack:add_wear(65535 / ((uses or 200) - 1))
        end
 
index 8b3ceed0780fc39d897647767fae36bc023a346f..bb9f8ec83b350492d214d2677ca4494382ba74a0 100644 (file)
@@ -22,21 +22,23 @@ local function rotate_and_place(itemstack, placer, pointed_thing)
        local p1 = pointed_thing.above
        local param2 = 0
 
-       local placer_pos = placer:getpos()
-       if placer_pos then
-               param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos))
-       end
+       if placer then
+               local placer_pos = placer:getpos()
+               if placer_pos then
+                       param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos))
+               end
 
-       local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing)
-       local fpos = finepos.y % 1
+               local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing)
+               local fpos = finepos.y % 1
 
-       if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5)
-                       or (fpos < -0.5 and fpos > -0.999999999) then
-               param2 = param2 + 20
-               if param2 == 21 then
-                       param2 = 23
-               elseif param2 == 23 then
-                       param2 = 21
+               if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5)
+                               or (fpos < -0.5 and fpos > -0.999999999) then
+                       param2 = param2 + 20
+                       if param2 == 21 then
+                               param2 = 23
+                       elseif param2 == 23 then
+                               param2 = 21
+                       end
                end
        end
        return minetest.item_place(itemstack, placer, pointed_thing, param2)
@@ -175,8 +177,9 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
                on_place = function(itemstack, placer, pointed_thing)
                        local under = minetest.get_node(pointed_thing.under)
                        local wield_item = itemstack:get_name()
+                       local player_name = placer and placer:get_player_name() or ""
                        local creative_enabled = (creative and creative.is_enabled_for
-                                       and creative.is_enabled_for(placer:get_player_name()))
+                                       and creative.is_enabled_for(player_name))
 
                        if under and under.name:find("stairs:slab_") then
                                -- place slab using under node orientation
@@ -192,9 +195,8 @@ function stairs.register_slab(subname, recipeitem, groups, images, description,
                                        if not recipeitem then
                                                return itemstack
                                        end
-                                       local player_name = placer:get_player_name()
                                        if minetest.is_protected(pointed_thing.under, player_name) and not
-                                                       minetest.check_player_privs(placer, "protection_bypass") then
+                                                       minetest.check_player_privs(player_name, "protection_bypass") then
                                                minetest.record_protection_violation(pointed_thing.under,
                                                        player_name)
                                                return