mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
Mod Logs command, change chat and menu colors
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
package de.shiewk.smoderation;
|
package de.shiewk.smoderation;
|
||||||
|
|
||||||
import de.shiewk.smoderation.command.BanCommand;
|
import de.shiewk.smoderation.command.*;
|
||||||
import de.shiewk.smoderation.command.KickCommand;
|
|
||||||
import de.shiewk.smoderation.command.MuteCommand;
|
|
||||||
import de.shiewk.smoderation.command.SModCommand;
|
|
||||||
import de.shiewk.smoderation.event.CustomInventoryEvents;
|
import de.shiewk.smoderation.event.CustomInventoryEvents;
|
||||||
import de.shiewk.smoderation.listener.PunishmentListener;
|
import de.shiewk.smoderation.listener.PunishmentListener;
|
||||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
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.command.PluginCommand;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
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 final PunishmentContainer container = new PunishmentContainer();
|
||||||
public static SModeration PLUGIN = null;
|
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
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
PLUGIN = this;
|
PLUGIN = this;
|
||||||
@@ -46,10 +49,10 @@ public final class SModeration extends JavaPlugin {
|
|||||||
assert smod != null;
|
assert smod != null;
|
||||||
smod.setExecutor(new SModCommand());
|
smod.setExecutor(new SModCommand());
|
||||||
smod.setTabCompleter(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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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<Punishment> 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<String> 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<String> playernames = new ArrayList<>();
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
playernames.add(onlinePlayer.getName());
|
||||||
|
}
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
StringUtil.copyPartialMatches(search, playernames, completions);
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,8 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import static de.shiewk.smoderation.SModeration.*;
|
||||||
|
|
||||||
public class SModMenu extends PageableCustomInventory {
|
public class SModMenu extends PageableCustomInventory {
|
||||||
|
|
||||||
public enum Filter {
|
public enum Filter {
|
||||||
@@ -60,10 +62,6 @@ public class SModMenu extends PageableCustomInventory {
|
|||||||
this.comparator = comparator;
|
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 static final NamespacedKey PUNISHMENT_STORE_KEY = new NamespacedKey("smod", "punishmentid");
|
||||||
|
|
||||||
private final Inventory inventory;
|
private final Inventory inventory;
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import de.shiewk.smoderation.util.ByteUtil;
|
|||||||
import de.shiewk.smoderation.util.PlayerUtil;
|
import de.shiewk.smoderation.util.PlayerUtil;
|
||||||
import de.shiewk.smoderation.util.TimeUtil;
|
import de.shiewk.smoderation.util.TimeUtil;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -14,10 +13,10 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.UUID;
|
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 class Punishment {
|
||||||
public static final NamedTextColor SECONDARY_COLOR = NamedTextColor.GOLD;
|
|
||||||
public static final String DEFAULT_REASON = "No reason provided.";
|
public static final String DEFAULT_REASON = "No reason provided.";
|
||||||
public final PunishmentType type;
|
public final PunishmentType type;
|
||||||
public final long time;
|
public final long time;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import de.shiewk.smoderation.punishments.Punishment;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -39,6 +40,16 @@ public class PunishmentContainer {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull List<Punishment> findAll(Predicate<Punishment> predicate){
|
||||||
|
List<Punishment> found = new ArrayList<>();
|
||||||
|
for (Punishment punishment : new CopyOnWriteArrayList<>(punishments)) {
|
||||||
|
if (predicate.test(punishment)){
|
||||||
|
found.add(punishment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
public List<CommandSender> collectBroadcastTargets(){
|
public List<CommandSender> collectBroadcastTargets(){
|
||||||
ArrayList<CommandSender> senders = new ArrayList<>();
|
ArrayList<CommandSender> senders = new ArrayList<>();
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ authors:
|
|||||||
- Shiewk
|
- Shiewk
|
||||||
description: "SModeration is an easy-to-use minecraft plugin for moderating your server."
|
description: "SModeration is an easy-to-use minecraft plugin for moderating your server."
|
||||||
commands:
|
commands:
|
||||||
|
modlogs:
|
||||||
|
usage: "§cUsage: /modlogs <player|uuid>"
|
||||||
|
aliases:
|
||||||
|
- logs
|
||||||
|
- seen
|
||||||
|
- smodlogs
|
||||||
|
permission: smod.logs
|
||||||
mute:
|
mute:
|
||||||
usage: "§cUsage: /mute <player> <duration> <reason>"
|
usage: "§cUsage: /mute <player> <duration> <reason>"
|
||||||
aliases:
|
aliases:
|
||||||
@@ -56,4 +63,7 @@ permissions:
|
|||||||
description: Allows the player to unmute other players.
|
description: Allows the player to unmute other players.
|
||||||
smod.cancelBan:
|
smod.cancelBan:
|
||||||
default: op
|
default: op
|
||||||
description: Allows the player to unban other players.
|
description: Allows the player to unban other players.
|
||||||
|
smod.logs:
|
||||||
|
default: op
|
||||||
|
description: Allows the player to view mod logs.
|
||||||
Reference in New Issue
Block a user