diff --git a/src/main/java/de/shiewk/smoderation/SModeration.java b/src/main/java/de/shiewk/smoderation/SModeration.java index 3811db2..8ac5a1b 100644 --- a/src/main/java/de/shiewk/smoderation/SModeration.java +++ b/src/main/java/de/shiewk/smoderation/SModeration.java @@ -1,12 +1,11 @@ package de.shiewk.smoderation; -import de.shiewk.smoderation.command.BanCommand; -import de.shiewk.smoderation.command.KickCommand; -import de.shiewk.smoderation.command.MuteCommand; -import de.shiewk.smoderation.command.SModCommand; +import de.shiewk.smoderation.command.*; import de.shiewk.smoderation.event.CustomInventoryEvents; import de.shiewk.smoderation.listener.PunishmentListener; import de.shiewk.smoderation.storage.PunishmentContainer; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.format.TextColor; import org.bukkit.command.PluginCommand; import org.bukkit.plugin.java.JavaPlugin; @@ -17,6 +16,10 @@ public final class SModeration extends JavaPlugin { public static final PunishmentContainer container = new PunishmentContainer(); public static SModeration PLUGIN = null; + public static final TextColor PRIMARY_COLOR = TextColor.color(212, 0, 255); + public static final TextColor SECONDARY_COLOR = TextColor.color(52, 143, 255); + public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY; + @Override public void onLoad() { PLUGIN = this; @@ -46,10 +49,10 @@ public final class SModeration extends JavaPlugin { assert smod != null; smod.setExecutor(new SModCommand()); smod.setTabCompleter(new SModCommand()); - } - - @Override - public void onDisable() { + final PluginCommand logs = getCommand("modlogs"); + assert logs != null; + logs.setExecutor(new ModLogsCommand()); + logs.setTabCompleter(new ModLogsCommand()); } } diff --git a/src/main/java/de/shiewk/smoderation/command/ModLogsCommand.java b/src/main/java/de/shiewk/smoderation/command/ModLogsCommand.java new file mode 100644 index 0000000..7511d36 --- /dev/null +++ b/src/main/java/de/shiewk/smoderation/command/ModLogsCommand.java @@ -0,0 +1,79 @@ +package de.shiewk.smoderation.command; + +import de.shiewk.smoderation.SModeration; +import de.shiewk.smoderation.punishments.Punishment; +import de.shiewk.smoderation.punishments.PunishmentType; +import de.shiewk.smoderation.util.PlayerUtil; +import de.shiewk.smoderation.util.TimeUtil; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; +import org.bukkit.util.StringUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import static de.shiewk.smoderation.SModeration.*; + +public class ModLogsCommand implements CommandExecutor, TabCompleter { + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (args.length < 1){ + return false; + } else { + String playername = args[0]; + String name; + UUID uuid; + try { + uuid = UUID.fromString(playername); + } catch (IllegalArgumentException ignored){ + uuid = PlayerUtil.offlinePlayerUUIDByName(playername); + } + if (uuid == null){ + sender.sendMessage(Component.text("This player was not found. Try running /%s with an UUID instead.".formatted(label))); + return true; + } + name = PlayerUtil.offlinePlayerName(uuid); + sender.sendMessage(Component.text("Player ").color(PRIMARY_COLOR) + .append(Component.text(name).color(SECONDARY_COLOR)) + .append(Component.text(" (%s)".formatted(uuid)).color(INACTIVE_COLOR))); + UUID finalUuid = uuid; + final List punishments = SModeration.container.findAll(p -> p.to.equals(finalUuid) && p.isActive()); + for (Punishment punishment : punishments) { + sender.sendMessage(Component.text("- is currently ").color(PRIMARY_COLOR) + .append(Component.text(punishment.type == PunishmentType.BAN ? "banned" : "muted").color(SECONDARY_COLOR)) + .append(Component.text(" until ").color(PRIMARY_COLOR)) + .append(Component.text(TimeUtil.calendarTimestamp(punishment.until)).color(SECONDARY_COLOR)) + .append(Component.text(" (in %s)".formatted(TimeUtil.formatTimeLong(punishment.until - System.currentTimeMillis()))).color(INACTIVE_COLOR)) + .append(Component.text(". Reason: ").color(PRIMARY_COLOR)) + .append(Component.text(punishment.reason).color(SECONDARY_COLOR))); + } + if (punishments.isEmpty()){ + sender.sendMessage(Component.text("- has no punishments.").color(PRIMARY_COLOR)); + } + return true; + } + } + + @Override + public @Nullable List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + if (args.length > 1){ + return List.of(); + } + String search = args.length > 0 ? args[0] : ""; + List playernames = new ArrayList<>(); + for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { + playernames.add(onlinePlayer.getName()); + } + List completions = new ArrayList<>(); + StringUtil.copyPartialMatches(search, playernames, completions); + return completions; + } +} diff --git a/src/main/java/de/shiewk/smoderation/inventory/SModMenu.java b/src/main/java/de/shiewk/smoderation/inventory/SModMenu.java index fea86e8..54e457d 100644 --- a/src/main/java/de/shiewk/smoderation/inventory/SModMenu.java +++ b/src/main/java/de/shiewk/smoderation/inventory/SModMenu.java @@ -27,6 +27,8 @@ import java.util.Comparator; import java.util.List; import java.util.function.Predicate; +import static de.shiewk.smoderation.SModeration.*; + public class SModMenu extends PageableCustomInventory { public enum Filter { @@ -60,10 +62,6 @@ public class SModMenu extends PageableCustomInventory { this.comparator = comparator; } } - - public static final NamedTextColor PRIMARY_COLOR = NamedTextColor.AQUA; - public static final NamedTextColor SECONDARY_COLOR = NamedTextColor.GREEN; - public static final NamedTextColor INACTIVE_COLOR = NamedTextColor.GRAY; private static final NamespacedKey PUNISHMENT_STORE_KEY = new NamespacedKey("smod", "punishmentid"); private final Inventory inventory; diff --git a/src/main/java/de/shiewk/smoderation/punishments/Punishment.java b/src/main/java/de/shiewk/smoderation/punishments/Punishment.java index e71fdca..789f397 100644 --- a/src/main/java/de/shiewk/smoderation/punishments/Punishment.java +++ b/src/main/java/de/shiewk/smoderation/punishments/Punishment.java @@ -6,7 +6,6 @@ import de.shiewk.smoderation.util.ByteUtil; import de.shiewk.smoderation.util.PlayerUtil; import de.shiewk.smoderation.util.TimeUtil; import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -14,10 +13,10 @@ import org.jetbrains.annotations.NotNull; import java.nio.ByteBuffer; import java.util.UUID; -public class Punishment { +import static de.shiewk.smoderation.SModeration.PRIMARY_COLOR; +import static de.shiewk.smoderation.SModeration.SECONDARY_COLOR; - public static final NamedTextColor PRIMARY_COLOR = NamedTextColor.RED; - public static final NamedTextColor SECONDARY_COLOR = NamedTextColor.GOLD; +public class Punishment { public static final String DEFAULT_REASON = "No reason provided."; public final PunishmentType type; public final long time; diff --git a/src/main/java/de/shiewk/smoderation/storage/PunishmentContainer.java b/src/main/java/de/shiewk/smoderation/storage/PunishmentContainer.java index 9147810..8f5a406 100644 --- a/src/main/java/de/shiewk/smoderation/storage/PunishmentContainer.java +++ b/src/main/java/de/shiewk/smoderation/storage/PunishmentContainer.java @@ -4,6 +4,7 @@ import de.shiewk.smoderation.punishments.Punishment; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -39,6 +40,16 @@ public class PunishmentContainer { return null; } + public @NotNull List findAll(Predicate predicate){ + List found = new ArrayList<>(); + for (Punishment punishment : new CopyOnWriteArrayList<>(punishments)) { + if (predicate.test(punishment)){ + found.add(punishment); + } + } + return found; + } + public List collectBroadcastTargets(){ ArrayList senders = new ArrayList<>(); for (Player onlinePlayer : Bukkit.getOnlinePlayers()) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index d6ae3e5..06c78c6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,6 +7,13 @@ authors: - Shiewk description: "SModeration is an easy-to-use minecraft plugin for moderating your server." commands: + modlogs: + usage: "§cUsage: /modlogs " + aliases: + - logs + - seen + - smodlogs + permission: smod.logs mute: usage: "§cUsage: /mute " aliases: @@ -56,4 +63,7 @@ permissions: description: Allows the player to unmute other players. smod.cancelBan: default: op - description: Allows the player to unban other players. \ No newline at end of file + description: Allows the player to unban other players. + smod.logs: + default: op + description: Allows the player to view mod logs. \ No newline at end of file