Add support for Minetest protection API
This commit is contained in:
parent
74d2970add
commit
1d9e7a44ae
@ -18,10 +18,14 @@ for b=1, #water_buckets do
|
||||
liquids_pointable = true,
|
||||
groups = { bucket = 2, bucket_water = 1 },
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
if pointed_thing.type ~= "node" then return itemstack end
|
||||
|
||||
local pos_protected = minetest.get_pointed_thing_position(pointed_thing, true)
|
||||
if minetest.is_protected(pos_protected, user) then return end
|
||||
if minetest.is_protected(pos_protected, user:get_player_name()) and
|
||||
not minetest.check_player_privs(user, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos_protected, user:get_player_name())
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local inv=user:get_inventory()
|
||||
|
||||
@ -69,6 +73,13 @@ minetest.register_craftitem(
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
|
||||
local pos_protected = minetest.get_pointed_thing_position(pointed_thing, true)
|
||||
if minetest.is_protected(pos_protected, user:get_player_name()) and
|
||||
not minetest.check_player_privs(user, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos_protected, user:get_player_name())
|
||||
return
|
||||
end
|
||||
|
||||
local nodename=minetest.get_node(pointed_thing.under).name
|
||||
|
||||
local replace_bucket = function(itemstack, new_bucket)
|
||||
|
@ -1,5 +1,24 @@
|
||||
local S = minetest.get_translator("default")
|
||||
|
||||
local protection_check_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return 0
|
||||
else
|
||||
return count
|
||||
end
|
||||
end
|
||||
local protection_check_put_take = function(pos, listname, index, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return 0
|
||||
else
|
||||
return stack:get_count()
|
||||
end
|
||||
end
|
||||
|
||||
-- Chest and bookshelf
|
||||
|
||||
minetest.register_node(
|
||||
@ -22,6 +41,9 @@ minetest.register_node(
|
||||
|
||||
inv:set_size("main", 8 * 4)
|
||||
end,
|
||||
-- Unlike other inventory nodes in this game, chests are NOT subject to protection.
|
||||
-- This is done to allow something like "public chests" in protected areas.
|
||||
-- To protect their belongings, players are supposed locked chests instead.
|
||||
can_dig = function(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
@ -66,6 +88,9 @@ minetest.register_node(
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 4*2)
|
||||
end,
|
||||
allow_metadata_inventory_move = protection_check_move,
|
||||
allow_metadata_inventory_put = protection_check_put_take,
|
||||
allow_metadata_inventory_take = protection_check_put_take,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
|
@ -96,6 +96,13 @@ minetest.register_craftitem(
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
local pos = pointed_thing.above
|
||||
|
||||
local pos_protected = minetest.get_pointed_thing_position(pointed_thing, true)
|
||||
if minetest.is_protected(pos_protected, user:get_player_name()) and
|
||||
not minetest.check_player_privs(user, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos_protected, user:get_player_name())
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local undernode = minetest.get_node(pointed_thing.under)
|
||||
|
||||
local diff = vector.subtract(pointed_thing.above, pointed_thing.under)
|
||||
|
@ -61,6 +61,25 @@ form_furnace = form_furnace .. "image[3.25,1.75;1,1;ui_arrow_bg.png^[transformR2
|
||||
|
||||
default.ui.register_page("default_furnace_inactive", form_furnace)
|
||||
|
||||
local protection_check_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return 0
|
||||
else
|
||||
return count
|
||||
end
|
||||
end
|
||||
local protection_check_put_take = function(pos, listname, index, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return 0
|
||||
else
|
||||
return stack:get_count()
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node(
|
||||
"default:furnace",
|
||||
{
|
||||
@ -81,6 +100,9 @@ minetest.register_node(
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
end,
|
||||
allow_metadata_inventory_move = protection_check_move,
|
||||
allow_metadata_inventory_put = protection_check_put_take,
|
||||
allow_metadata_inventory_take = protection_check_put_take,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
@ -117,6 +139,9 @@ minetest.register_node(
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
end,
|
||||
allow_metadata_inventory_move = protection_check_move,
|
||||
allow_metadata_inventory_put = protection_check_put_take,
|
||||
allow_metadata_inventory_take = protection_check_put_take,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
|
@ -33,6 +33,11 @@ minetest.register_node(
|
||||
end,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
if fields.text == nil then return end
|
||||
if minetest.is_protected(pos, sender:get_player_name()) and
|
||||
not minetest.check_player_privs(sender, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, sender:get_player_name())
|
||||
return itemstack
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local text = fields.text
|
||||
if string.len(text) > SIGN_MAX_TEXT_LENGTH then
|
||||
|
@ -709,6 +709,12 @@ minetest.register_tool(
|
||||
if pointed_thing.type ~= "node" then return end
|
||||
|
||||
local pos = pointed_thing.under
|
||||
if minetest.is_protected(pos, user:get_player_name()) and
|
||||
not minetest.check_player_privs(user, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, user:get_player_name())
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local node = minetest.get_node(pos)
|
||||
local nodename = node.name
|
||||
|
||||
|
@ -184,6 +184,25 @@ minetest.register_craftitem(
|
||||
|
||||
-- Nodes
|
||||
|
||||
local protection_check_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return 0
|
||||
else
|
||||
return count
|
||||
end
|
||||
end
|
||||
local protection_check_put_take = function(pos, listname, index, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return 0
|
||||
else
|
||||
return stack:get_count()
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node(
|
||||
"jewels:bench",
|
||||
{
|
||||
@ -209,10 +228,18 @@ minetest.register_node(
|
||||
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
allow_metadata_inventory_move = protection_check_move,
|
||||
allow_metadata_inventory_put = protection_check_put_take,
|
||||
allow_metadata_inventory_take = protection_check_put_take,
|
||||
on_punch = function(pos, node, player, pointed_thing)
|
||||
local itemstack = player:get_wielded_item()
|
||||
|
||||
local itemstack_changed = false
|
||||
if itemstack:get_name() == "jewels:jewel" then
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
@ -223,6 +250,7 @@ minetest.register_node(
|
||||
|
||||
if not minetest.settings:get_bool("creative_mode") then
|
||||
itemstack:take_item()
|
||||
itemstack_changed = true
|
||||
end
|
||||
|
||||
minetest.sound_play({name="jewels_jewelling_a_tool"}, {gain=0.8, pos=pos, max_hear_distance=8})
|
||||
@ -233,7 +261,9 @@ minetest.register_node(
|
||||
end
|
||||
end
|
||||
|
||||
player:set_wielded_item(itemstack)
|
||||
if itemstack_changed then
|
||||
player:set_wielded_item(itemstack)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -63,6 +63,12 @@ minetest.register_tool(
|
||||
return itemstack
|
||||
end
|
||||
local pos = pointed_thing.under
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local node = minetest.get_node(pos)
|
||||
if minetest.get_item_group(node.name, "locked") == 0 then
|
||||
return itemstack
|
||||
@ -197,6 +203,11 @@ minetest.register_node(
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_l, from_i, to_l, to_i, cnt, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return 0
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
if locks.is_locked(meta, player) then
|
||||
return 0
|
||||
@ -204,6 +215,11 @@ minetest.register_node(
|
||||
return cnt
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, itemstack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return 0
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
if locks.is_locked(meta, player) then
|
||||
return 0
|
||||
@ -211,6 +227,11 @@ minetest.register_node(
|
||||
return itemstack:get_count()
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, itemstack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) and
|
||||
not minetest.check_player_privs(player, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, player:get_player_name())
|
||||
return 0
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
if locks.is_locked(meta, player) then
|
||||
return 0
|
||||
|
@ -1600,8 +1600,13 @@ function mobs:register_egg(mob, desc, background)
|
||||
return itemstack
|
||||
end
|
||||
local pos = pointed_thing.above
|
||||
if pointed_thing.above
|
||||
and not minetest.is_protected(pos, placer:get_player_name()) then
|
||||
if pointed_thing.above then
|
||||
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())
|
||||
return itemstack
|
||||
end
|
||||
|
||||
pos.y = pos.y + 0.5
|
||||
local mob = minetest.add_entity(pos, mob)
|
||||
local ent = mob:get_luaentity()
|
||||
|
@ -135,7 +135,12 @@ if minetest.settings:get_bool("music_enable") then
|
||||
music.stop(pos)
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos)
|
||||
on_rightclick = function(pos, node, clicker)
|
||||
if minetest.is_protected(pos, clicker:get_player_name()) and
|
||||
not minetest.check_player_privs(clicker, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, clicker:get_player_name())
|
||||
return
|
||||
end
|
||||
music.toggle(pos)
|
||||
end,
|
||||
|
||||
|
@ -265,6 +265,11 @@ minetest.register_node(
|
||||
local itemname = item:get_name()
|
||||
|
||||
if itemname == "default:flint_and_steel" then
|
||||
if minetest.is_protected(pos, puncher:get_player_name()) and
|
||||
not minetest.check_player_privs(puncher, "protection_bypass") then
|
||||
minetest.record_protection_violation(pos, puncher:get_player_name())
|
||||
return
|
||||
end
|
||||
if not minetest.settings:get_bool("creative_mode") then
|
||||
item:add_wear(800)
|
||||
puncher:set_wielded_item(item)
|
||||
|
Loading…
Reference in New Issue
Block a user