diff options
Diffstat (limited to 'commands/clear_penalty.lua')
-rw-r--r-- | commands/clear_penalty.lua | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/commands/clear_penalty.lua b/commands/clear_penalty.lua new file mode 100644 index 0000000..cf64103 --- /dev/null +++ b/commands/clear_penalty.lua @@ -0,0 +1,33 @@ +local penalty_clear_cooldown = mesecons_debug.settings.penalty_clear_cooldown + +-- playername => time-of-last-cooldown +local cooldown_expiry_by_name = {} + + +minetest.register_chatcommand("mesecons_clear_penalty", { + description = "clears the penalty in the current mapblock " .. + "(cooldown: " .. penalty_clear_cooldown .. ")", + func = function(name) + local player = minetest.get_player_by_name(name) + if not player then + return + end + + local is_admin = minetest.check_player_privs(player, "mesecons_debug") + if not is_admin then + local now = os.time() + local expires = cooldown_expiry_by_name[name] or 0 + local remaining_time = math.floor(expires - now) + if remaining_time > 0 then + -- cooldown still in progress + return true, "cooldown still in progress, remaining time: " .. remaining_time .. " seconds" + end + cooldown_expiry_by_name[name] = now + penalty_clear_cooldown + end + + local ctx = mesecons_debug.get_context(player:get_pos()) + ctx.penalty = 0 + + return true, "penalty reset" + end +}) |