Skip to content

Commit

Permalink
#48 Allow setting/using machine_use_priv (#49)
Browse files Browse the repository at this point in the history
Co-authored-by: SX <sx@minetest>
  • Loading branch information
S-S-X and SX committed Oct 18, 2020
1 parent d0ee2ae commit e28402d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions luatool/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ local tool = metatool:register_tool('luatool', {
name = 'LuaTool',
texture = 'luatool_wand.png',
recipe = recipe,
settings = {
machine_use_priv = 'server'
},
on_read_node = function(tooldef, player, pointed_thing, node, pos)
local data, group = tooldef:copy(node, pos, player)
local description = type(data) == 'table' and data.description or ('Data from ' .. minetest.pos_to_string(pos))
Expand Down
17 changes: 12 additions & 5 deletions metatool/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,18 @@ end

-- Called when registered tool is used
metatool.on_use = function(self, toolname, itemstack, player, pointed_thing)
if not player or type(player) == 'table' then
return
end

local tool = self.tools[toolname]
if not player or not tool then return end

if type(player) ~= 'userdata' then
-- if tool has machine_use_priv and player has it allow using tool even if player is not userdata (fake player)
local machine_use_priv = tool.settings.machine_use_priv
if not machine_use_priv or not metatool.check_privs(player, machine_use_priv) then
return
end
end

if self.privileged_tools[toolname] then
if not metatool.check_privs(player, tool.privs) then
minetest.chat_send_player(player:get_player_name(), 'You are not allowed to use this tool.')
Expand Down Expand Up @@ -397,8 +404,8 @@ metatool.register_node = function(self, toolname, name, definition, override)
end

metatool.get_node = function(self, tool, player, pointed_thing)
if not player or type(player) == 'table' or not pointed_thing then
-- not valid player or fake player, fake player is not supported (yet)
if not player or not pointed_thing then
-- not valid player or pointed_thing
return
end

Expand Down

0 comments on commit e28402d

Please sign in to comment.