minetest-mod-metatools/assertions.lua
LeMagnesium c875a96af7
Add user alerts and check on node digging
- Bump to version 1.2.2
 - Add `metatools.alert_users` which sends the string passed as argument
   to all players currently operating on nodes
 - Register a dignode callback in which we alert users about players
   trying to dig operated nodes, or open nodes in general. Only node
   operated by a person different from the person digging are blocked
 - Add `metatools.get_context_from_pos`. It receives a table, but does
   no assertions (yet?)
 - Move `playerlocks` over to `metatools.playerlocks` for similar
   reasons to why we moved `nodelock`
 - Create field `success` for meta_exec, a function run when the command
   is successful; it receives the executed function's parameters and its
   output (status, msg) as arguments
 - Update /meta help's message
 - Fix instances of `contexts` not replaced by `metatools.contexts`
 - Assert that the context id is correct upon running `metatools.show`
2016-09-20 18:33:20 +02:00

39 lines
936 B
Lua

-- Assertion tools for Metatools
function assert_contextid(ctid)
return metatools.contexts[ctid] ~= nil
end
function assert_ownership(ctid, name)
return metatools.playerlocks[name] == ctid
end
function assert_pos(pos)
if type(pos) ~= "string" then
return pos and pos.x and pos.y and pos.z and minetest.pos_to_string(pos)
else
return minetest.string_to_pos(pos) ~= nil
end
end
function assert_mode(mode)
return mode and (mode == "fields" or mode == "inventory")
end
function assert_poslock(pos)
return nodelock[minetest.pos_to_string(pos)] == nil
end
function assert_specific_mode(contextid, mode)
return assert_contextid(contextid) and metatools.contexts[contextid].mode == mode
end
function assert_field_type(ftype)
return ftype and type(ftype) == "string" and (ftype == "int" or ftype == "float" or ftype == "string")
end
function assert_integer(int)
return int and tonumber(int) and tonumber(int) % 1 == 0
end