forked from whosit/waypoint_compass
add owner check - first user is owner and only owner can edit
This commit is contained in:
parent
ac9d3f2368
commit
cbc5cda07b
34
init.lua
34
init.lua
@ -50,6 +50,16 @@ local function get_compass_meta_color(meta)
|
||||
end
|
||||
|
||||
|
||||
local function set_compass_meta_owner(meta, player_name)
|
||||
meta:set_string("waypoint_compass:owner", player_name)
|
||||
end
|
||||
|
||||
|
||||
local function get_compass_meta_owner(meta)
|
||||
return meta:get_string("waypoint_compass:owner")
|
||||
end
|
||||
|
||||
|
||||
-- local function set_compass_meta_pos(meta, pos)
|
||||
-- local pos_hash = minetest.hash_node_position(pos)
|
||||
-- meta:set_int("waypoint_compass:position", pos_hash)
|
||||
@ -188,6 +198,7 @@ local compass_dialog_context = {}
|
||||
|
||||
local function show_basic_dialog(itemstack, player)
|
||||
local meta = itemstack:get_meta()
|
||||
-- set focus to "close" button to preven accidental edting
|
||||
local formspec_head = "formspec_version[4]size[10,3]set_focus[close;]"
|
||||
local coords = coords_to_string(get_compass_meta_pos(meta))
|
||||
local field_coords = ("field[0.5,0.6;2.5,0.8;coords;Coords;%s]"):format(minetest.formspec_escape(coords))
|
||||
@ -208,6 +219,22 @@ end
|
||||
|
||||
|
||||
local function compass_use_callback(itemstack, user, pointed_thing)
|
||||
if not (user and user:is_player()) then
|
||||
return itemstack
|
||||
end
|
||||
local meta = itemstack:get_meta()
|
||||
local owner = get_compass_meta_owner(meta)
|
||||
print("owner", owner)
|
||||
if owner == "" then
|
||||
-- set first user as owner
|
||||
print("set owner", user:get_player_name())
|
||||
set_compass_meta_owner(meta, user:get_player_name())
|
||||
elseif owner ~= user:get_player_name() then
|
||||
-- already has owner
|
||||
-- TODO show message "You are not the owner" (or maybe limit editing to color change?)
|
||||
print("You are not the owner. Owner is " .. owner)
|
||||
return itemstack
|
||||
end
|
||||
if user:get_player_control()["sneak"] then
|
||||
if pointed_thing.type == "nothing" then
|
||||
if user and user:is_player() then
|
||||
@ -221,6 +248,7 @@ local function compass_use_callback(itemstack, user, pointed_thing)
|
||||
show_basic_dialog(itemstack, user)
|
||||
end
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
|
||||
@ -270,12 +298,10 @@ minetest.register_tool(
|
||||
wield_scale = {x = 0.5, y = 0.5, z = 0.5},
|
||||
range = 2.0, -- TODO what's the good range?
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
compass_use_callback(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
return compass_use_callback(itemstack, placer, pointed_thing)
|
||||
end,
|
||||
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||
compass_use_callback(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
return compass_use_callback(itemstack, user, pointed_thing)
|
||||
end,
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user