From def4aac944ba3f738fecc15994dd53c8b81d262c Mon Sep 17 00:00:00 2001 From: MysticTempest Date: Wed, 13 Jul 2022 09:36:24 -0500 Subject: [PATCH] Fix some crashes, try to preserve privs, and properly set gamemode meta. --- mods/HUD/mcl_inventory/init.lua | 1 - mods/PLAYER/mcl_hardcore/init.lua | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index 3794402b06..3008162df2 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -215,7 +215,6 @@ function mcl_inventory.player_set_gamemode(p,g) mcl_experience.remove_hud(p) mcl_hardcore.spectator_mode_disabled(p) elseif g == "spectator" then - mcl_experience.remove_hud(p) mcl_hardcore.spectator_mode(p) end set_inventory(p) diff --git a/mods/PLAYER/mcl_hardcore/init.lua b/mods/PLAYER/mcl_hardcore/init.lua index 6798860d32..7c32d8ba9e 100644 --- a/mods/PLAYER/mcl_hardcore/init.lua +++ b/mods/PLAYER/mcl_hardcore/init.lua @@ -25,25 +25,38 @@ function mcl_hardcore.spectator_mode(player) -- Have to wait since mcl_potions clears old effects on startup. minetest.after(3, function(player) + mcl_potions._reset_player_effects(player, true) -- Fix some cases of not clearing. mcl_potions.invisiblility_func(player, null, 86400) -- Invisible for 24 hours. hb.hide_hudbar(player, "hunger") hb.change_hudbar(player, "health", nil, nil, "blank.png", nil, "hudbars_bar_health.png") + mcl_experience.remove_hud(player) end, player) + if meta:get_string("gamemode") ~= "spectator" then + meta:set_string("gamemode","spectator") + end end function mcl_hardcore.spectator_mode_disabled(player) local meta = player:get_meta() local player_name = player:get_player_name() + local privs = minetest.get_player_privs(player_name) + minetest.after(3, function(player) -- Fix startup crash conflict by waiting slightly. mcl_potions._reset_player_effects(player, true) hb.unhide_hudbar(player, "hunger") meta:set_int("mcl_privs:interact_revoked", 0) player:set_armor_groups({immortal=0}) + + -- Try to preserve privs somewhat if meta:get_string("gamemode") == "creative" then - minetest.set_player_privs(player_name, {basic_privs=true,fly=true}) - else + privs.fast = nil + privs.noclip = nil + privs.interact = true + minetest.set_player_privs(player_name, privs) + else -- survival; only basic privs minetest.set_player_privs(player_name, {basic_privs=true}) end + end, player) end