mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-29 06:34:17 +02:00
Add permanent punishments
This commit is contained in:
@@ -49,11 +49,15 @@ public final class ModLogsCommand implements CommandProvider {
|
||||
List<Punishment> 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()){
|
||||
|
||||
@@ -21,9 +21,13 @@ public final class DurationArgument implements CustomArgumentType.Converted<Long
|
||||
|
||||
public static final Pattern DURATION_PATTERN = Pattern.compile("([0-9]{1,9})(ms|s|min|h|d|w|mo|y)");
|
||||
public static final Pattern VALIDATION_PATTERN = Pattern.compile("(([0-9]{1,9})(ms|s|min|h|d|w|mo|y))+");
|
||||
public static final long INFINITE_DURATION = -1L;
|
||||
|
||||
@Override
|
||||
public @NotNull Long convert(@NotNull String nativeType) throws CommandSyntaxException {
|
||||
if (nativeType.startsWith("perm") || nativeType.startsWith("inf")) {
|
||||
return INFINITE_DURATION;
|
||||
}
|
||||
if (!VALIDATION_PATTERN.matcher(nativeType).matches()){
|
||||
CommandUtil.errorTranslatable("smod.argument.duration.fail.pattern");
|
||||
}
|
||||
@@ -58,6 +62,8 @@ public final class DurationArgument implements CustomArgumentType.Converted<Long
|
||||
public @NotNull <S> CompletableFuture<Suggestions> listSuggestions(@NotNull CommandContext<S> context, @NotNull SuggestionsBuilder builder) {
|
||||
if (builder.getRemaining().isBlank()){
|
||||
List.of(
|
||||
"infinite", "inf",
|
||||
"permanent", "perm",
|
||||
"100ms",
|
||||
"15s",
|
||||
"2min",
|
||||
|
||||
@@ -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)))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user