From 0f47076047cdaddd0283061a7211b512336d8061 Mon Sep 17 00:00:00 2001 From: Draycia Date: Sun, 11 Jan 2026 01:55:04 -0800 Subject: [PATCH] show duration in muteinfo Implements #738 --- .../command/commands/MuteInfoCommand.java | 17 +++++++++++++++++ .../carbon/common/messages/CarbonMessages.java | 3 +++ .../resources/locale/messages-en_US.properties | 1 + 3 files changed, 21 insertions(+) diff --git a/common/src/main/java/net/draycia/carbon/common/command/commands/MuteInfoCommand.java b/common/src/main/java/net/draycia/carbon/common/command/commands/MuteInfoCommand.java index 7e7db45e..550ebc93 100644 --- a/common/src/main/java/net/draycia/carbon/common/command/commands/MuteInfoCommand.java +++ b/common/src/main/java/net/draycia/carbon/common/command/commands/MuteInfoCommand.java @@ -20,6 +20,8 @@ package net.draycia.carbon.common.command.commands; import com.google.inject.Inject; +import java.time.Duration; +import java.time.Instant; import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.api.users.UserManager; import net.draycia.carbon.common.command.CarbonCommand; @@ -29,7 +31,9 @@ import net.draycia.carbon.common.command.ParserFactory; import net.draycia.carbon.common.command.PlayerCommander; import net.draycia.carbon.common.messages.CarbonMessages; import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.Component; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.framework.qual.DefaultQualifier; import org.incendo.cloud.CommandManager; @@ -100,6 +104,19 @@ public final class MuteInfoCommand extends CarbonCommand { } else { if (sender.equals(target)) { this.carbonMessages.muteInfoSelfMuted(sender); + } else if (target.muteExpiration() > Instant.now().toEpochMilli()) { + final Duration duration = Duration.ofMillis(target.muteExpiration() - System.currentTimeMillis()); + final @Nullable Component formattedDuration; + + if (duration.toDaysPart() > 0) { + formattedDuration = this.carbonMessages.durationDays(duration.toDaysPart(), duration.toHoursPart(), + duration.toMinutesPart(), duration.toSecondsPart()); + } else { + formattedDuration = this.carbonMessages.durationHours(duration.toHoursPart(), duration.toMinutesPart(), + duration.toSecondsPart()); + } + + this.carbonMessages.muteInfoMutedDuration(sender, target.displayName(), formattedDuration); } else { this.carbonMessages.muteInfoMuted(sender, target.displayName(), target.muted()); } diff --git a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java index bb083d87..c37f4902 100644 --- a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java +++ b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java @@ -86,6 +86,9 @@ public interface CarbonMessages { @Message("mute.info.not_muted") void muteInfoNotMuted(final Audience audience, final Component target); + @Message("mute.info.muted.duration") + void muteInfoMutedDuration(final Audience audience, final Component target, final Component duration); + @Message("mute.info.muted") void muteInfoMuted(final Audience audience, final Component target, final boolean muted); diff --git a/common/src/main/resources/locale/messages-en_US.properties b/common/src/main/resources/locale/messages-en_US.properties index bd27c2bd..8fb4d166 100644 --- a/common/src/main/resources/locale/messages-en_US.properties +++ b/common/src/main/resources/locale/messages-en_US.properties @@ -121,6 +121,7 @@ mute.alert.target.temp=You have been muted for mute.cannot_speak=You cannot speak when muted mute.exempt=That player is exempt from being muted mute.info.muted= is muted +mute.info.muted.duration= is muted for mute.info.not_muted= is not muted mute.info.self.muted=You are muted mute.info.self.not_muted=You are not muted