summaryrefslogtreecommitdiff
path: root/builtin/game
diff options
context:
space:
mode:
authoryou <ovvv@web.de>2018-02-05 15:17:10 +0100
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-02-05 15:17:10 +0100
commit87e08b1b3af097e5ba86d31179e58fe38477fe15 (patch)
tree3f031735c75e0062c643d2c6f7e276bb4b2d06b5 /builtin/game
parentb7ff40eea22488a240aeaeb393922d3c8d23a9b5 (diff)
downloadminetest-87e08b1b3af097e5ba86d31179e58fe38477fe15.tar.gz
minetest-87e08b1b3af097e5ba86d31179e58fe38477fe15.tar.bz2
minetest-87e08b1b3af097e5ba86d31179e58fe38477fe15.zip
Add minetest.is_player (#7013)
* Add minetest.is_player * First use for is_player
Diffstat (limited to 'builtin/game')
-rw-r--r--builtin/game/misc.lua18
1 files changed, 13 insertions, 5 deletions
diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua
index 79ca40217..6e54dad5e 100644
--- a/builtin/game/misc.lua
+++ b/builtin/game/misc.lua
@@ -5,12 +5,11 @@
--
function core.check_player_privs(name, ...)
- local arg_type = type(name)
- if (arg_type == "userdata" or arg_type == "table") and
- name.get_player_name then -- If it quacks like a Player...
+ if core.is_player(name) then
name = name:get_player_name()
- elseif arg_type ~= "string" then
- error("Invalid core.check_player_privs argument type: " .. arg_type, 2)
+ elseif type(name) ~= "string" then
+ error("core.check_player_privs expects a player or playername as " ..
+ "argument.", 2)
end
local requested_privs = {...}
@@ -85,6 +84,15 @@ function core.get_connected_players()
end
+function core.is_player(player)
+ -- a table being a player is also supported because it quacks sufficiently
+ -- like a player if it has the is_player function
+ local t = type(player)
+ return (t == "userdata" or t == "table") and
+ type(player.is_player) == "function" and player:is_player()
+end
+
+
function minetest.player_exists(name)
return minetest.get_auth_handler().get_auth(name) ~= nil
end