mirror of
https://github.com/minetest/minetest_game.git
synced 2024-11-09 17:23:51 +01:00
Add nil checks for placer
This commit is contained in:
parent
3ae382c913
commit
a2d7678ffd
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
})
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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},
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user