diff options
author | you <ovvv@web.de> | 2018-02-05 15:17:10 +0100 |
---|---|---|
committer | SmallJoker <mk939@ymail.com> | 2018-06-03 17:32:00 +0200 |
commit | 880a25c92182bd10e8a80930909cf505e851ea65 (patch) | |
tree | 4ea500131cc1da7bd64b533af6c62f51a85ba181 | |
parent | 0268c9d7c9925daeeb2ac847aca090de635ba43c (diff) | |
download | minetest-880a25c92182bd10e8a80930909cf505e851ea65.tar.gz minetest-880a25c92182bd10e8a80930909cf505e851ea65.tar.bz2 minetest-880a25c92182bd10e8a80930909cf505e851ea65.zip |
Add minetest.is_player (#7013)
* Add minetest.is_player
* First use for is_player
-rw-r--r-- | builtin/game/misc.lua | 19 | ||||
-rw-r--r-- | doc/lua_api.txt | 1 |
2 files changed, 15 insertions, 5 deletions
diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua index bfe407b9d..d8f7a638d 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 = {...} @@ -70,6 +69,16 @@ function core.get_connected_players() return temp_table 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 diff --git a/doc/lua_api.txt b/doc/lua_api.txt index b35c816a1..73572ac78 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -3013,6 +3013,7 @@ These functions return the leftover itemstack. ### Misc. * `minetest.get_connected_players()`: returns list of `ObjectRefs` +* `minetest.is_player(o)`: boolean, whether `o` is a player * `minetest.player_exists(name)`: boolean, whether player exists (regardless of online status) * `minetest.hud_replace_builtin(name, hud_definition)` * Replaces definition of a builtin hud element |