diff --git a/src/main/java/de/shiewk/smoderation/paper/command/ModLogsCommand.java b/src/main/java/de/shiewk/smoderation/paper/command/ModLogsCommand.java index 69f8d49..ba1ba29 100644 --- a/src/main/java/de/shiewk/smoderation/paper/command/ModLogsCommand.java +++ b/src/main/java/de/shiewk/smoderation/paper/command/ModLogsCommand.java @@ -49,11 +49,15 @@ public final class ModLogsCommand implements CommandProvider { List punishments = punishmentManager.byTargetUUID(uuid); for (Punishment punishment : punishments) { if (punishment instanceof TimedPunishment timed && timed.isActive()){ - sender.sendMessage(translatable("smod.command.modlogs." + punishment.getType(), - TimeUtil.calendarTimestamp(timed.getExpiry()), - TimeUtil.formatTimeLong(timed.getExpiry() - System.currentTimeMillis()), - text(punishment.getReason()) - )); + if (timed.isPermanent()){ + sender.sendMessage(translatable("smod.command.modlogs." + punishment.getType() + ".permanent", text(punishment.getReason()))); + } else { + sender.sendMessage(translatable("smod.command.modlogs." + punishment.getType(), + TimeUtil.calendarTimestamp(timed.getExpiry()), + TimeUtil.formatTimeLong(timed.getExpiry() - System.currentTimeMillis()), + text(punishment.getReason()) + )); + } } } if (punishments.isEmpty()){ diff --git a/src/main/java/de/shiewk/smoderation/paper/command/argument/DurationArgument.java b/src/main/java/de/shiewk/smoderation/paper/command/argument/DurationArgument.java index 0e6be26..86dee07 100644 --- a/src/main/java/de/shiewk/smoderation/paper/command/argument/DurationArgument.java +++ b/src/main/java/de/shiewk/smoderation/paper/command/argument/DurationArgument.java @@ -21,9 +21,13 @@ public final class DurationArgument implements CustomArgumentType.Converted CompletableFuture listSuggestions(@NotNull CommandContext context, @NotNull SuggestionsBuilder builder) { if (builder.getRemaining().isBlank()){ List.of( + "infinite", "inf", + "permanent", "perm", "100ms", "15s", "2min", diff --git a/src/main/java/de/shiewk/smoderation/paper/inventory/SModMenu.java b/src/main/java/de/shiewk/smoderation/paper/inventory/SModMenu.java index 42956b9..bfde1fb 100644 --- a/src/main/java/de/shiewk/smoderation/paper/inventory/SModMenu.java +++ b/src/main/java/de/shiewk/smoderation/paper/inventory/SModMenu.java @@ -58,7 +58,7 @@ public class SModMenu extends PageableCustomInventory { } public enum Sort { - EXPIRY(translatable("smod.menu.sort.expiry"), Comparator.comparingLong(p -> p instanceof TimedPunishment timed ? p.getTimestamp() + timed.getDuration() : p.getTimestamp())), + EXPIRY(translatable("smod.menu.sort.expiry"), Comparator.comparingLong(p -> p instanceof TimedPunishment timed ? timed.getExpiry() : p.getTimestamp())), TIME(translatable("smod.menu.sort.time"), Comparator.comparingLong(Punishment::getTimestamp)), PLAYER_NAME(translatable("smod.menu.sort.playerName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.getTargetID()), PlayerUtil.offlinePlayerName(p2.getTargetID()))), MODERATOR_NAME(translatable("smod.menu.sort.moderatorName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.getIssuerID()), PlayerUtil.offlinePlayerName(p2.getIssuerID()))); @@ -330,12 +330,17 @@ public class SModMenu extends PageableCustomInventory { lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.timestamp", TimeUtil.calendarTimestamp(punishment.getTimestamp()))))); if (punishment instanceof TimedPunishment timed){ - lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", TimeUtil.formatTimeLong(timed.getExpiry() - punishment.getTimestamp()))))); - long remainingTime = timed.getExpiry() - System.currentTimeMillis(); - if (remainingTime > 0){ - lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.future", TimeUtil.formatTimeLong(remainingTime))))); + if (timed.isPermanent()){ + lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", translatable("smod.time.permanent"))))); + lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.never")))); } else { - lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.past", TimeUtil.formatTimeLong(-remainingTime))))); + lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", TimeUtil.formatTimeLong(timed.getExpiry() - punishment.getTimestamp()))))); + long remainingTime = timed.getExpiry() - System.currentTimeMillis(); + if (remainingTime > 0){ + lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.future", TimeUtil.formatTimeLong(remainingTime))))); + } else { + lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.past", TimeUtil.formatTimeLong(-remainingTime))))); + } } } diff --git a/src/main/java/de/shiewk/smoderation/paper/punishments/TimedPunishment.java b/src/main/java/de/shiewk/smoderation/paper/punishments/TimedPunishment.java index ef26575..83f567c 100644 --- a/src/main/java/de/shiewk/smoderation/paper/punishments/TimedPunishment.java +++ b/src/main/java/de/shiewk/smoderation/paper/punishments/TimedPunishment.java @@ -1,5 +1,6 @@ package de.shiewk.smoderation.paper.punishments; +import de.shiewk.smoderation.paper.command.argument.DurationArgument; import de.shiewk.smoderation.paper.util.PlayerUtil; import de.shiewk.smoderation.paper.util.SerializationHelper; import de.shiewk.smoderation.paper.util.TimeUtil; @@ -35,7 +36,7 @@ public abstract class TimedPunishment extends Punishment { } public boolean isActive(){ - return !wasCancelled() && System.currentTimeMillis() < timestamp + duration; + return !wasCancelled() && (isPermanent() || System.currentTimeMillis() < getExpiry()); } @Override @@ -55,23 +56,40 @@ public abstract class TimedPunishment extends Punishment { @Override public Component infoMessage(){ - return translatable( - "smod.punishment.playerMessage." + type, - text(PlayerUtil.offlinePlayerName(this.issuer)), - text(reason), - TimeUtil.formatTimeLong(this.timestamp + this.duration - System.currentTimeMillis()) - ); + if (isPermanent()){ + return translatable( + "smod.punishment.playerMessage." + type + ".permanent", + text(PlayerUtil.offlinePlayerName(this.issuer)), + text(reason) + ); + } else { + return translatable( + "smod.punishment.playerMessage." + type, + text(PlayerUtil.offlinePlayerName(this.issuer)), + text(reason), + TimeUtil.formatTimeLong(this.timestamp + this.duration - System.currentTimeMillis()) + ); + } } @Override public Component adminMessage(){ - return translatable( - "smod.punishment.broadcast." + type, - text(PlayerUtil.offlinePlayerName(target)), - text(PlayerUtil.offlinePlayerName(issuer)), - text(reason), - TimeUtil.formatTimeLong(this.duration) - ); + if (isPermanent()){ + return translatable( + "smod.punishment.broadcast." + type + ".permanent", + text(PlayerUtil.offlinePlayerName(target)), + text(PlayerUtil.offlinePlayerName(issuer)), + text(reason) + ); + } else { + return translatable( + "smod.punishment.broadcast." + type, + text(PlayerUtil.offlinePlayerName(target)), + text(PlayerUtil.offlinePlayerName(issuer)), + text(reason), + TimeUtil.formatTimeLong(this.duration) + ); + } } public Component cancelMessage(){ @@ -83,7 +101,11 @@ public abstract class TimedPunishment extends Punishment { } public long getExpiry() { - return getTimestamp() + getDuration(); + return isPermanent() ? Long.MAX_VALUE : getTimestamp() + getDuration(); + } + + public boolean isPermanent() { + return getDuration() == DurationArgument.INFINITE_DURATION; } protected void cancel(UUID canceller) { diff --git a/src/main/resources/smoderation/translations/de_de.json b/src/main/resources/smoderation/translations/de_de.json index 8f39028..79aa35e 100644 --- a/src/main/resources/smoderation/translations/de_de.json +++ b/src/main/resources/smoderation/translations/de_de.json @@ -19,8 +19,10 @@ "smod.command.kick.fail.protect": "Dieser Spieler kann nicht gekickt werden.", "smod.command.kick.fail.self": "Du kannst dich nicht selbst kicken.", "smod.command.modlogs.ban": "- ist bis (in ) gebannt. Grund: ", + "smod.command.modlogs.ban.permanent": "- ist permanent gebannt. Grund: ", "smod.command.modlogs.heading": "Spieler ()", "smod.command.modlogs.mute": "- ist bis (in ) stummgeschaltet. Grund: ", + "smod.command.modlogs.mute.permanent": "- ist permanent stummgeschaltet. Grund: ", "smod.command.modlogs.none": "- ist momentan nicht gebannt oder stummgeschaltet.", "smod.command.mute.fail.alreadyMuted": "Dieser Spieler ist schon stummgeschaltet.", "smod.command.mute.fail.forceReason": "Bitte gib einen Grund an.", @@ -56,6 +58,7 @@ "smod.menu.info.click": "\u00BB Klicke, um die Strafe aufzuheben", "smod.menu.info.duration": "Dauer: ", "smod.menu.info.expiry.future": "Läuft ab: In ", + "smod.menu.info.expiry.never": "Läuft ab: Nie", "smod.menu.info.expiry.past": "Ist abgelaufen: ago", "smod.menu.info.player": "Spieler: ", "smod.menu.info.punishedBy": "Bestraft von: ", @@ -77,16 +80,20 @@ "smod.menu.type.all": "Alle", "smod.menu.type.switch": "\u00BB Klicke, um den Typ zu ändern", "smod.punishment.broadcast.ban": " wurde von für gebannt.Grund: ", + "smod.punishment.broadcast.ban.permanent": " wurde von permanent gebannt.Grund: ", "smod.punishment.broadcast.kick": " wurde von gekickt.Grund: ", "smod.punishment.broadcast.mute": " wurde von für stummgeschaltet.Grund: ", + "smod.punishment.broadcast.mute.permanent": " wurde von permanent stummgeschaltet.Grund: ", "smod.punishment.cancel.ban": " wurde von entbannt.", "smod.punishment.cancel.mute": "s Stummschaltung wurde von aufgehoben.", "smod.punishment.name.ban": "Bann", "smod.punishment.name.kick": "Kick", "smod.punishment.name.mute": "Stummschaltung", "smod.punishment.playerMessage.ban": "Du wurdest von vom Server gebannt.Grund: Dein Bann läuft in ab.", + "smod.punishment.playerMessage.ban.permanent": "Du wurdest von vom Server gebannt.Grund: Dein Bann läuft nicht ab.", "smod.punishment.playerMessage.kick": "Du wurdest von vom Server gekickt.Grund: ", "smod.punishment.playerMessage.mute": "Du wurdest von stummgeschaltet.Grund: Du kannst in wieder schreiben.", + "smod.punishment.playerMessage.mute.permanent": "Du wurdest von stummgeschaltet.Grund: Du kannst nie wieder schreiben.", "smod.punishment.playerMessage.mute.chat": "Du kannst diesen Befehl nicht ausführen, während du stummgeschaltet bist.", "smod.socialspy.command": "[SocialSpy] : ", "smod.time.days": " Tage", @@ -106,6 +113,8 @@ "smod.time.month.8": "September", "smod.time.month.9": "Oktober", "smod.time.months": " Monate", + "smod.time.never": "Nie", + "smod.time.permanent": "Permanent", "smod.time.seconds": " Sekunden", "smod.time.timestamp": ". :: ", "smod.time.weeks": " Wochen", diff --git a/src/main/resources/smoderation/translations/en_us.json b/src/main/resources/smoderation/translations/en_us.json index 9dead7b..728feb5 100644 --- a/src/main/resources/smoderation/translations/en_us.json +++ b/src/main/resources/smoderation/translations/en_us.json @@ -19,8 +19,10 @@ "smod.command.kick.fail.protect": "This player can't be kicked.", "smod.command.kick.fail.self": "You can't kick yourself.", "smod.command.modlogs.ban": "- is banned until (in ). Reason: ", + "smod.command.modlogs.ban.permanent": "- is banned permanently. Reason: ", "smod.command.modlogs.heading": "Player ()", "smod.command.modlogs.mute": "- is muted until (in ). Reason: ", + "smod.command.modlogs.mute.permanent": "- is muted permanently. Reason: ", "smod.command.modlogs.none": "- is not currently muted or banned.", "smod.command.mute.fail.alreadyMuted": "This player is already muted.", "smod.command.mute.fail.forceReason": "Please provide a reason.", @@ -56,6 +58,7 @@ "smod.menu.info.click": "\u00BB Click to cancel punishment", "smod.menu.info.duration": "Duration: ", "smod.menu.info.expiry.future": "Expires: In ", + "smod.menu.info.expiry.never": "Expires: Never", "smod.menu.info.expiry.past": "Expired: ago", "smod.menu.info.player": "Player: ", "smod.menu.info.punishedBy": "Punished by: ", @@ -77,16 +80,20 @@ "smod.menu.type.all": "All", "smod.menu.type.switch": "» Click to switch type", "smod.punishment.broadcast.ban": " was banned by for .Reason: ", + "smod.punishment.broadcast.ban.permanent": " was banned permanently by .Reason: ", "smod.punishment.broadcast.kick": " was kicked by .Reason: ", "smod.punishment.broadcast.mute": " was muted by for .Reason: ", + "smod.punishment.broadcast.mute.permanent": " was muted permanently by .Reason: ", "smod.punishment.cancel.ban": " was unbanned by .", "smod.punishment.cancel.mute": " was unmuted by .", "smod.punishment.name.ban": "Ban", "smod.punishment.name.kick": "Kick", "smod.punishment.name.mute": "Mute", "smod.punishment.playerMessage.ban": "You have been banned from this server by .Reason: Your ban expires in .", + "smod.punishment.playerMessage.ban.permanent": "You have been banned from this server by .Reason: Your ban does not expire.", "smod.punishment.playerMessage.kick": "You have been kicked by .Reason: ", "smod.punishment.playerMessage.mute": "You have been muted by .Reason: Your mute expires in .", + "smod.punishment.playerMessage.mute.permanent": "You have been muted by .Reason: Your mute does not expire.", "smod.punishment.playerMessage.mute.chat": "You can't run this command while you are muted.", "smod.socialspy.command": "[SocialSpy] : ", "smod.time.days": " days", @@ -106,6 +113,8 @@ "smod.time.month.8": "September", "smod.time.month.9": "October", "smod.time.months": " months", + "smod.time.never": "Never", + "smod.time.permanent": "Permanent", "smod.time.seconds": " seconds", "smod.time.timestamp": " :: ", "smod.time.weeks": " weeks",