From 0722f5b84f4b25fa7dae02e7e8a8e91127401ffd Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Tue, 3 May 2022 14:58:44 +0000 Subject: [PATCH] fix crash when achievements are disabled and /awards is being used This commit fixes https://git.minetest.land/MineClone2/MineClone2/issues/2164, which crashes the game whenever /awards is called with arguments other than enable --- mods/HUD/awards/chat_commands.lua | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/mods/HUD/awards/chat_commands.lua b/mods/HUD/awards/chat_commands.lua index 88e799df..64805ac6 100644 --- a/mods/HUD/awards/chat_commands.lua +++ b/mods/HUD/awards/chat_commands.lua @@ -21,9 +21,13 @@ minetest.register_chatcommand("awards", { description = S("Show, clear, disable or enable your achievements"), func = function(name, param) if param == "clear" then - awards.clear_player(name) - minetest.chat_send_player(name, - S("All your awards and statistics have been cleared. You can now start again.")) + if awards.player(name).disabled ~= nil then + minetest.chat_send_player(name, S("Awards are disabled, enable them first by using /awards enable!")) + else + awards.clear_player(name) + minetest.chat_send_player(name, + S("All your awards and statistics have been cleared. You can now start again.")) + end elseif param == "disable" then awards.disable(name) minetest.chat_send_player(name, S("You have disabled your achievements.")) @@ -31,9 +35,17 @@ minetest.register_chatcommand("awards", { awards.enable(name) minetest.chat_send_player(name, S("You have enabled your achievements.")) elseif param == "c" then - awards.show_to(name, name, nil, true) + if awards.player(name).disabled ~= nil then + minetest.chat_send_player(name, S("Awards are disabled, enable them first by using /awards enable!")) + else + awards.show_to(name, name, nil, true) + end else - awards.show_to(name, name, nil, false) + if awards.player(name).disabled ~= nil then + minetest.chat_send_player(name, S("Awards are disabled, enable them first by using /awards enable!")) + else + awards.show_to(name, name, nil, false) + end end end })