Allow detection of cloaking and uncloaking in leaveplayer and joinplayer callbacks (#10)

This commit is contained in:
Oversword 2024-07-22 21:23:55 +01:00 committed by GitHub
parent 80fad7a2db
commit 88efcda38d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 0 deletions

View File

@ -14,6 +14,8 @@ cloaking.get_objects_in_area = minetest.get_objects_in_area
cloaking.get_server_status = minetest.get_server_status
local cloaked_players = {}
local cloaking_players = {}
local uncloaking_players = {}
local chatcommands_modified = false
-- Override built-in functions
@ -261,11 +263,13 @@ function cloaking.cloak(player_or_name)
t = areas.hud[victim]
end
cloaking_players[victim] = true
for _, f in ipairs(minetest.registered_on_leaveplayers) do
if f ~= delayed_uncloak then
f(player, false, 'cloaking')
end
end
cloaking_players[victim] = nil
cloaked_players[victim] = true
@ -299,9 +303,11 @@ function cloaking.uncloak(player_or_name)
minetest.chat_send_all("*** " .. victim .. " joined the game.")
end
uncloaking_players[victim] = true
for _, f in ipairs(minetest.registered_on_joinplayers) do
f(player)
end
uncloaking_players[victim] = nil
minetest.log('verbose', victim .. ' was uncloaked.')
end
@ -382,6 +388,15 @@ function cloaking.is_cloaked(player)
return cloaked_players[player] and true or false
end
function cloaking.is_cloaking(player)
if type(player) ~= "string" then player = player:get_player_name() end
return cloaking_players[player] and true or false
end
function cloaking.is_uncloaking(player)
if type(player) ~= "string" then player = player:get_player_name() end
return uncloaking_players[player] and true or false
end
-- Prevent cloaked players dying
minetest.register_on_player_hpchange(function(player, hp_change)
if player and hp_change < 0 then