1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Add minetest.is_player (#7013)

* Add minetest.is_player

* First use for is_player
This commit is contained in:
you 2018-02-05 15:17:10 +01:00 committed by SmallJoker
parent 0268c9d7c9
commit 880a25c921
2 changed files with 15 additions and 5 deletions

View file

@ -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