forked from Mirrorlandia_minetest/minetest
Add minetest.is_player (#7013)
* Add minetest.is_player * First use for is_player
This commit is contained in:
parent
b7ff40eea2
commit
87e08b1b3a
@ -5,12 +5,11 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
function core.check_player_privs(name, ...)
|
function core.check_player_privs(name, ...)
|
||||||
local arg_type = type(name)
|
if core.is_player(name) then
|
||||||
if (arg_type == "userdata" or arg_type == "table") and
|
|
||||||
name.get_player_name then -- If it quacks like a Player...
|
|
||||||
name = name:get_player_name()
|
name = name:get_player_name()
|
||||||
elseif arg_type ~= "string" then
|
elseif type(name) ~= "string" then
|
||||||
error("Invalid core.check_player_privs argument type: " .. arg_type, 2)
|
error("core.check_player_privs expects a player or playername as " ..
|
||||||
|
"argument.", 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local requested_privs = {...}
|
local requested_privs = {...}
|
||||||
@ -85,6 +84,15 @@ function core.get_connected_players()
|
|||||||
end
|
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)
|
function minetest.player_exists(name)
|
||||||
return minetest.get_auth_handler().get_auth(name) ~= nil
|
return minetest.get_auth_handler().get_auth(name) ~= nil
|
||||||
end
|
end
|
||||||
|
@ -3329,6 +3329,7 @@ These functions return the leftover itemstack.
|
|||||||
|
|
||||||
### Misc.
|
### Misc.
|
||||||
* `minetest.get_connected_players()`: returns list of `ObjectRefs`
|
* `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.player_exists(name)`: boolean, whether player exists (regardless of online status)
|
||||||
* `minetest.hud_replace_builtin(name, hud_definition)`
|
* `minetest.hud_replace_builtin(name, hud_definition)`
|
||||||
* Replaces definition of a builtin hud element
|
* Replaces definition of a builtin hud element
|
||||||
|
Loading…
Reference in New Issue
Block a user