package de.shiewk.smoderation.paper.command; import com.mojang.brigadier.Command; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.tree.LiteralCommandNode; import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument; import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.PunishmentManager; import de.shiewk.smoderation.paper.punishments.TimedPunishment; import de.shiewk.smoderation.paper.util.CommandUtil; import de.shiewk.smoderation.paper.util.PlayerUtil; import de.shiewk.smoderation.paper.util.TimeUtil; import io.papermc.paper.command.brigadier.CommandSourceStack; import org.bukkit.command.CommandSender; import java.util.Collection; import java.util.List; import java.util.UUID; import static io.papermc.paper.command.brigadier.Commands.argument; import static io.papermc.paper.command.brigadier.Commands.literal; import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.translatable; @SuppressWarnings("UnstableApiUsage") // Paper Brigadier API public final class ModLogsCommand implements CommandProvider { private final PunishmentManager punishmentManager; public ModLogsCommand(PunishmentManager punishmentManager) { this.punishmentManager = punishmentManager; } @Override public LiteralCommandNode getCommandNode() { return literal("modlogs") .requires(CommandUtil.requirePermission("smod.logs")) .then(argument("player", new PlayerUUIDArgument()) .executes(this::showModLogs) ) .build(); } private int showModLogs(CommandContext context) { CommandSender sender = context.getSource().getSender(); UUID uuid = context.getArgument("player", UUID.class); String name = PlayerUtil.offlinePlayerName(uuid); sender.sendMessage(translatable("smod.command.modlogs.heading", text(name), text(uuid.toString()))); 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 (punishments.isEmpty()){ sender.sendMessage(translatable("smod.command.modlogs.none")); } return Command.SINGLE_SUCCESS; } @Override public String getCommandDescription() { return "Views all current punishments of a player."; } @Override public Collection getAliases() { return List.of("logs", "seen", "smodlogs"); } }