Skip to content

Commit 87e08b1

Browse files
HybridDognerzhul
authored andcommittedFeb 5, 2018
Add minetest.is_player (#7013)
* Add minetest.is_player * First use for is_player
1 parent b7ff40e commit 87e08b1

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed
 

Diff for: ‎builtin/game/misc.lua

+13-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
--
66

77
function core.check_player_privs(name, ...)
8-
local arg_type = type(name)
9-
if (arg_type == "userdata" or arg_type == "table") and
10-
name.get_player_name then -- If it quacks like a Player...
8+
if core.is_player(name) then
119
name = name:get_player_name()
12-
elseif arg_type ~= "string" then
13-
error("Invalid core.check_player_privs argument type: " .. arg_type, 2)
10+
elseif type(name) ~= "string" then
11+
error("core.check_player_privs expects a player or playername as " ..
12+
"argument.", 2)
1413
end
1514

1615
local requested_privs = {...}
@@ -85,6 +84,15 @@ function core.get_connected_players()
8584
end
8685

8786

87+
function core.is_player(player)
88+
-- a table being a player is also supported because it quacks sufficiently
89+
-- like a player if it has the is_player function
90+
local t = type(player)
91+
return (t == "userdata" or t == "table") and
92+
type(player.is_player) == "function" and player:is_player()
93+
end
94+
95+
8896
function minetest.player_exists(name)
8997
return minetest.get_auth_handler().get_auth(name) ~= nil
9098
end

Diff for: ‎doc/lua_api.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -2753,9 +2753,9 @@ and `minetest.auth_reload` call the authentication handler.
27532753
* Set node on all positions set in the first argument.
27542754
* e.g. `minetest.bulk_set_node({{x=0, y=1, z=1}, {x=1, y=2, z=2}}, {name="default:stone"})`
27552755
* For node specification or position syntax see `minetest.set_node` call
2756-
* Faster than set_node due to single call, but still considerably slower than
2756+
* Faster than set_node due to single call, but still considerably slower than
27572757
Voxel Manipulators (LVM) for large numbers of nodes.
2758-
Unlike LVMs, this will call node callbacks. It also allows setting nodes in spread out
2758+
Unlike LVMs, this will call node callbacks. It also allows setting nodes in spread out
27592759
positions which would cause LVMs to waste memory.
27602760
For setting a cube, this is 1.3x faster than set_node whereas LVM is 20x faster.
27612761
* `minetest.swap_node(pos, node)`
@@ -3329,6 +3329,7 @@ These functions return the leftover itemstack.
33293329

33303330
### Misc.
33313331
* `minetest.get_connected_players()`: returns list of `ObjectRefs`
3332+
* `minetest.is_player(o)`: boolean, whether `o` is a player
33323333
* `minetest.player_exists(name)`: boolean, whether player exists (regardless of online status)
33333334
* `minetest.hud_replace_builtin(name, hud_definition)`
33343335
* Replaces definition of a builtin hud element

0 commit comments

Comments
 (0)
Please sign in to comment.