mirror of
https://github.com/Shiewk/SModeration.git
synced 2026-04-28 05:54:16 +02:00
move SModeration for Paper to subproject
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
package de.shiewk.smoderation;
|
||||
|
||||
import de.shiewk.smoderation.command.*;
|
||||
import de.shiewk.smoderation.config.SModerationConfig;
|
||||
import de.shiewk.smoderation.input.ChatInputListener;
|
||||
import de.shiewk.smoderation.listener.*;
|
||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static de.shiewk.smoderation.command.VanishCommand.isVanished;
|
||||
import static de.shiewk.smoderation.command.VanishCommand.toggleVanish;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static org.bukkit.Bukkit.getPluginManager;
|
||||
|
||||
public final class SModeration extends JavaPlugin {
|
||||
|
||||
public static final PunishmentContainer container = new PunishmentContainer();
|
||||
public static ComponentLogger LOGGER = null;
|
||||
public static SModeration PLUGIN = null;
|
||||
public static SModerationConfig CONFIG = null;
|
||||
public static File SAVE_FILE = 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;
|
||||
public static final TextColor FAIL_COLOR = NamedTextColor.RED;
|
||||
public static final TextComponent CHAT_PREFIX = text("SM \u00BB ").color(PRIMARY_COLOR);
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
LOGGER = getComponentLogger();
|
||||
PLUGIN = this;
|
||||
CONFIG = new SModerationConfig(this.getConfig(), this);
|
||||
SAVE_FILE = new File(this.getDataFolder().getAbsolutePath() + "/container.gz");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getPluginManager().registerEvents(new PunishmentListener(), this);
|
||||
getPluginManager().registerEvents(new CustomInventoryListener(), this);
|
||||
getPluginManager().registerEvents(new InvSeeListener(), this);
|
||||
getPluginManager().registerEvents(new EnderchestSeeListener(), this);
|
||||
getPluginManager().registerEvents(new VanishListener(), this);
|
||||
getPluginManager().registerEvents(new ChatInputListener(), this);
|
||||
getPluginManager().registerEvents(new SocialSpyListener(), this);
|
||||
|
||||
registerCommand("mute", new MuteCommand());
|
||||
registerCommand("ban", new BanCommand());
|
||||
registerCommand("kick", new KickCommand());
|
||||
registerCommand("smod", new SModCommand());
|
||||
registerCommand("modlogs", new ModLogsCommand());
|
||||
registerCommand("unmute", new UnmuteCommand());
|
||||
registerCommand("unban", new UnbanCommand());
|
||||
registerCommand("invsee", new InvseeCommand());
|
||||
registerCommand("enderchestsee", new EnderchestSeeCommand());
|
||||
registerCommand("vanish", new VanishCommand());
|
||||
registerCommand("socialspy", new SocialSpyCommand());
|
||||
|
||||
container.load(SAVE_FILE);
|
||||
}
|
||||
|
||||
private void registerCommand(String label, TabExecutor executor){
|
||||
final PluginCommand command = getCommand(label);
|
||||
if (command != null) {
|
||||
command.setExecutor(executor);
|
||||
command.setTabCompleter(executor);
|
||||
} else {
|
||||
LOGGER.warn("Command %s failed to register: This command does not exist".formatted(label));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
SModeration.container.save(SModeration.SAVE_FILE);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
// in case players are still vanished when the server shuts down
|
||||
if (isVanished(player)){
|
||||
toggleVanish(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
package de.shiewk.smoderation.command;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.punishments.Punishment;
|
||||
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.*;
|
||||
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 net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class BanCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
return false;
|
||||
} else {
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
String playerName = args[0];
|
||||
UUID uuid = PlayerUtil.offlinePlayerUUIDByName(playerName);
|
||||
if (senderUUID.equals(uuid)) {
|
||||
sender.sendMessage(Component.text("You can't ban yourself.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(Component.text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
final Player toPlayer = Bukkit.getPlayer(uuid);
|
||||
if (toPlayer != null && toPlayer.hasPermission("smod.preventban")){
|
||||
sender.sendMessage(text().content("This player can't be banned.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
long duration = 0;
|
||||
int p = 1;
|
||||
for (int i = 1 /* start with index 1 to avoid player name */; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
long parsedDuration = TimeUtil.parseDurationMillisSafely(arg);
|
||||
if (parsedDuration == -1){
|
||||
p = i;
|
||||
break;
|
||||
} else {
|
||||
duration += parsedDuration;
|
||||
}
|
||||
if (i == args.length - 1){ p = args.length; }
|
||||
}
|
||||
if (duration == 0){
|
||||
sender.sendMessage(Component.text("Please provide a valid duration.").color(NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
if (duration < 0){
|
||||
sender.sendMessage(Component.text("Please provide a duration that's longer than 0ms.").color(NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
StringBuilder reason = new StringBuilder();
|
||||
for (int i = p; i < args.length; i++) {
|
||||
if (!reason.isEmpty()){
|
||||
reason.append(" ");
|
||||
}
|
||||
reason.append(args[i]);
|
||||
}
|
||||
final Punishment punishment = Punishment.ban(System.currentTimeMillis(), System.currentTimeMillis() + duration, senderUUID, uuid, reason.isEmpty() ? Punishment.DEFAULT_REASON : reason.toString());
|
||||
Punishment.issue(punishment, SModeration.container);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
String toComplete = args.length > 0 ? args[0] : "";
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
names.add(onlinePlayer.getName());
|
||||
}
|
||||
ArrayList<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(toComplete, names, completions);
|
||||
return completions;
|
||||
} else {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (TimeUtil.parseDurationMillisSafely(args[i]) == -1){
|
||||
try {
|
||||
Long.parseLong(args[i]);
|
||||
} catch (NumberFormatException ignored){
|
||||
if (i != 1){
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return List.of(
|
||||
"100ms",
|
||||
"15s", // some sample completions for duration
|
||||
"30min", // you can input your own ones as well
|
||||
"6h",
|
||||
"1d",
|
||||
"2w",
|
||||
"3mo",
|
||||
"1y"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package de.shiewk.smoderation.command;
|
||||
|
||||
import de.shiewk.smoderation.util.PlayerUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
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 static de.shiewk.smoderation.SModeration.*;
|
||||
|
||||
public class EnderchestSeeCommand implements TabExecutor {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
if (sender instanceof HumanEntity human){
|
||||
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
|
||||
if (player != null) {
|
||||
human.sendMessage(CHAT_PREFIX.append(
|
||||
Component.text("Opening ender chest of ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
|
||||
.append(Component.text("."))
|
||||
));
|
||||
human.openInventory(player.getEnderChest());
|
||||
} else {
|
||||
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Only an entity that can open inventories can execute this command!").color(FAIL_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();
|
||||
}
|
||||
List<String> available = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
available.add(onlinePlayer.getName());
|
||||
}
|
||||
List<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(args.length > 0 ? args[0] : "", available, completions);
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
package de.shiewk.smoderation.command;
|
||||
|
||||
import de.shiewk.smoderation.inventory.InvSeeEquipmentInventory;
|
||||
import de.shiewk.smoderation.util.PlayerUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
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 static de.shiewk.smoderation.SModeration.*;
|
||||
|
||||
public class InvseeCommand implements TabExecutor {
|
||||
|
||||
private enum InvseeType {
|
||||
INVENTORY,
|
||||
EQUIPMENT
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1) {
|
||||
return false;
|
||||
}
|
||||
final InvseeType type;
|
||||
if (args.length > 1){
|
||||
switch (args[1].toLowerCase()){
|
||||
case "armor", "equipment" -> type = InvseeType.EQUIPMENT;
|
||||
default -> type = InvseeType.INVENTORY;
|
||||
}
|
||||
} else {
|
||||
type = InvseeType.INVENTORY;
|
||||
}
|
||||
if (sender instanceof HumanEntity human){
|
||||
final Player player = PlayerUtil.findOnlinePlayer(args[0]);
|
||||
if (player != null) {
|
||||
if (human.getUniqueId().equals(player.getUniqueId()) && type != InvseeType.EQUIPMENT){
|
||||
human.sendMessage(Component.text("You can't open your own inventory.").color(FAIL_COLOR));
|
||||
} else {
|
||||
human.sendMessage(CHAT_PREFIX.append(
|
||||
Component.text("Opening inventory of ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(player.getName()).color(SECONDARY_COLOR))
|
||||
.append(Component.text("."))
|
||||
));
|
||||
switch (type){
|
||||
case INVENTORY -> human.openInventory(player.getInventory());
|
||||
case EQUIPMENT -> new InvSeeEquipmentInventory(human, player).open();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
human.sendMessage(Component.text("This player is not online.").color(FAIL_COLOR));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Only an entity that can open inventories can execute this command!").color(FAIL_COLOR));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length > 2){
|
||||
return List.of();
|
||||
} else if (args.length > 1){
|
||||
return List.of("armor", "equipment", "inventory");
|
||||
}
|
||||
List<String> available = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
available.add(onlinePlayer.getName());
|
||||
}
|
||||
List<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(args.length > 0 ? args[0] : "", available, completions);
|
||||
return completions;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package de.shiewk.smoderation.command;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.punishments.Punishment;
|
||||
import de.shiewk.smoderation.util.PlayerUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
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 net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class KickCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1){
|
||||
return false;
|
||||
} else {
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
String playerName = args[0];
|
||||
Player player = Bukkit.getPlayer(playerName);
|
||||
if (player == null) {
|
||||
sender.sendMessage(Component.text("This player is not online.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (senderUUID.equals(uuid)) {
|
||||
sender.sendMessage(Component.text("You can't kick yourself.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (player.hasPermission("smod.preventkick")){
|
||||
sender.sendMessage(text().content("This player can't be kicked.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
StringBuilder reason = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (!reason.isEmpty()){
|
||||
reason.append(" ");
|
||||
}
|
||||
reason.append(args[i]);
|
||||
}
|
||||
final Punishment punishment = Punishment.kick(System.currentTimeMillis(), senderUUID, uuid, reason.isEmpty() ? Punishment.DEFAULT_REASON : reason.toString());
|
||||
Punishment.issue(punishment, SModeration.container);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
String toComplete = args.length > 0 ? args[0] : "";
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
names.add(onlinePlayer.getName());
|
||||
}
|
||||
ArrayList<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(toComplete, names, completions);
|
||||
return completions;
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
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 net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
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 TabExecutor {
|
||||
@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)).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
name = PlayerUtil.offlinePlayerName(uuid);
|
||||
sender.sendMessage(CHAT_PREFIX.append(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;
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package de.shiewk.smoderation.command;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.punishments.Punishment;
|
||||
import de.shiewk.smoderation.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.util.TimeUtil;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.*;
|
||||
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 net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class MuteCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
return false;
|
||||
} else {
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
String playerName = args[0];
|
||||
UUID uuid = PlayerUtil.offlinePlayerUUIDByName(playerName);
|
||||
if (senderUUID.equals(uuid)) {
|
||||
sender.sendMessage(text("You can't mute yourself.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
if (uuid == null) {
|
||||
sender.sendMessage(text("This player is either offline or was never on this server.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
final Player toPlayer = Bukkit.getPlayer(uuid);
|
||||
if (toPlayer != null && toPlayer.hasPermission("smod.preventmute")){
|
||||
sender.sendMessage(text().content("This player can't be muted.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
long duration = 0;
|
||||
int p = 1;
|
||||
for (int i = 1 /* start with index 1 to avoid player name */; i < args.length; i++) {
|
||||
String arg = args[i];
|
||||
long parsedDuration = TimeUtil.parseDurationMillisSafely(arg);
|
||||
if (parsedDuration == -1){
|
||||
p = i;
|
||||
break;
|
||||
} else {
|
||||
duration += parsedDuration;
|
||||
}
|
||||
if (i == args.length - 1){ p = args.length; }
|
||||
}
|
||||
if (duration == 0){
|
||||
sender.sendMessage(text("Please provide a valid duration.").color(NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
if (duration < 0){
|
||||
sender.sendMessage(text("Please provide a duration that's longer than 0ms.").color(NamedTextColor.RED));
|
||||
return false;
|
||||
}
|
||||
StringBuilder reason = new StringBuilder();
|
||||
for (int i = p; i < args.length; i++) {
|
||||
if (!reason.isEmpty()){
|
||||
reason.append(" ");
|
||||
}
|
||||
reason.append(args[i]);
|
||||
}
|
||||
final Punishment punishment = Punishment.mute(System.currentTimeMillis(), System.currentTimeMillis() + duration, senderUUID, uuid, reason.isEmpty() ? Punishment.DEFAULT_REASON : reason.toString());
|
||||
Punishment.issue(punishment, SModeration.container);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
String toComplete = args.length > 0 ? args[0] : "";
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
names.add(onlinePlayer.getName());
|
||||
}
|
||||
ArrayList<String> completions = new ArrayList<>();
|
||||
StringUtil.copyPartialMatches(toComplete, names, completions);
|
||||
return completions;
|
||||
} else {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
if (TimeUtil.parseDurationMillisSafely(args[i]) == -1){
|
||||
try {
|
||||
Long.parseLong(args[i]);
|
||||
} catch (NumberFormatException ignored){
|
||||
if (i != 1){
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return List.of(
|
||||
"100ms",
|
||||
"15s", // some sample completions for duration
|
||||
"30min", // you can input your own ones as well
|
||||
"6h",
|
||||
"1d",
|
||||
"2w",
|
||||
"3mo",
|
||||
"1y"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package de.shiewk.smoderation.command;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.inventory.SModMenu;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SModCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
if (commandSender instanceof Player player){
|
||||
new SModMenu(player, SModeration.container).open();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package de.shiewk.smoderation.command;
|
||||
|
||||
import de.shiewk.smoderation.listener.SocialSpyListener;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.SModeration.CHAT_PREFIX;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class SocialSpyCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
final boolean enabled = SocialSpyListener.toggle(sender);
|
||||
sender.sendMessage(CHAT_PREFIX.append(text("SocialSpy ").append(
|
||||
enabled ?
|
||||
text("enabled").color(NamedTextColor.GREEN) :
|
||||
text("disabled").color(NamedTextColor.RED)
|
||||
).append(text("."))));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
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 net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UnbanCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1){
|
||||
return false;
|
||||
} else {
|
||||
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
|
||||
String nameArg = args[0];
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(nameArg);
|
||||
} catch (IllegalArgumentException ignored){
|
||||
uuid = PlayerUtil.offlinePlayerUUIDByName(nameArg);
|
||||
}
|
||||
if (uuid == null){
|
||||
sender.sendMessage(Component.text("This player was not found. Try running /%s with an UUID instead.".formatted(label)).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
UUID finalUuid = uuid;
|
||||
final Punishment punishment = SModeration.container.find(p -> p.to.equals(finalUuid) && p.isActive() && p.type == PunishmentType.BAN);
|
||||
if (punishment != null) {
|
||||
punishment.undo(senderUUID);
|
||||
punishment.broadcastUndo(SModeration.container);
|
||||
} else {
|
||||
sender.sendMessage(Component.text("This player is not banned.").color(NamedTextColor.RED));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
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 net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class UnmuteCommand implements TabExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1){
|
||||
return false;
|
||||
} else {
|
||||
|
||||
UUID senderUUID;
|
||||
if (sender instanceof ConsoleCommandSender){
|
||||
senderUUID = PlayerUtil.UUID_CONSOLE;
|
||||
} else if (sender instanceof Player pl){
|
||||
senderUUID = pl.getUniqueId();
|
||||
} else if (sender instanceof BlockCommandSender){
|
||||
sender.sendMessage(Component.text("Blocks can't execute this command.").color(NamedTextColor.RED));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Your command sender type is unknown (%s).".formatted(sender.getClass().getName())).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
|
||||
String nameArg = args[0];
|
||||
UUID uuid;
|
||||
try {
|
||||
uuid = UUID.fromString(nameArg);
|
||||
} catch (IllegalArgumentException ignored){
|
||||
uuid = PlayerUtil.offlinePlayerUUIDByName(nameArg);
|
||||
}
|
||||
if (uuid == null){
|
||||
sender.sendMessage(Component.text("This player was not found. Try running /%s with an UUID instead.".formatted(label)).color(NamedTextColor.RED));
|
||||
return true;
|
||||
}
|
||||
UUID finalUuid = uuid;
|
||||
final Punishment punishment = SModeration.container.find(p -> p.to.equals(finalUuid) && p.isActive() && p.type == PunishmentType.MUTE);
|
||||
if (punishment != null) {
|
||||
punishment.undo(senderUUID);
|
||||
punishment.broadcastUndo(SModeration.container);
|
||||
} else {
|
||||
sender.sendMessage(Component.text("This player is not muted.").color(NamedTextColor.RED));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package de.shiewk.smoderation.command;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.util.PlayerUtil;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.SModeration.*;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class VanishCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length == 0 || args[0].equalsIgnoreCase("toggle")){
|
||||
Player player = null;
|
||||
if (args.length > 1){
|
||||
player = PlayerUtil.findOnlinePlayer(args[1]);
|
||||
} else if (sender instanceof Player){
|
||||
player = (Player) sender;
|
||||
}
|
||||
if (player != null){
|
||||
toggleVanish(player);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (args[0].equalsIgnoreCase("list")) {
|
||||
if (sender.hasPermission("smod.vanish.see")){
|
||||
listVanishedPlayersTo(sender);
|
||||
} else {
|
||||
sender.sendMessage(text().color(NamedTextColor.RED).content("You do not have permission to list all vanished players."));
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2){
|
||||
return List.of("list", "toggle");
|
||||
}
|
||||
if (args.length < 3 && args[0].equalsIgnoreCase("toggle")){
|
||||
return PlayerUtil.listPlayerNames(args[1]);
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
|
||||
private static final ObjectArrayList<Player> vanishedPlayers = new ObjectArrayList<>();
|
||||
|
||||
public static void toggleVanish(Player player){
|
||||
final boolean newStatus = !isVanished(player);
|
||||
if (newStatus){
|
||||
vanishedPlayers.add(player);
|
||||
for (CommandSender sender : SModeration.container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName()
|
||||
.colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(
|
||||
text()
|
||||
.content(" vanished.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are now vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(false);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||
onlinePlayer.showEntity(PLUGIN, player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vanishedPlayers.remove(player);
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(
|
||||
player.displayName()
|
||||
.colorIfAbsent(SECONDARY_COLOR)
|
||||
).append(
|
||||
text()
|
||||
.content(" re-appeared.")
|
||||
.color(PRIMARY_COLOR)
|
||||
));
|
||||
}
|
||||
player.sendMessage(CHAT_PREFIX.append(text("You are no longer vanished.").color(PRIMARY_COLOR)));
|
||||
player.setVisibleByDefault(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isVanished(Player player){
|
||||
return vanishedPlayers.contains(player);
|
||||
}
|
||||
|
||||
public static ObjectArrayList<Player> getVanishedPlayers() {
|
||||
return vanishedPlayers.clone();
|
||||
}
|
||||
|
||||
public static void listVanishedPlayersTo(CommandSender receiver){
|
||||
if (vanishedPlayers.isEmpty()){
|
||||
receiver.sendMessage(CHAT_PREFIX.append(
|
||||
text().content("No players are currently vanished.").color(PRIMARY_COLOR)
|
||||
));
|
||||
} else {
|
||||
Component vanishList = CHAT_PREFIX.append(
|
||||
text().content("The following players are currently vanished: ").color(PRIMARY_COLOR)
|
||||
);
|
||||
for (ObjectListIterator<Player> iterator = vanishedPlayers.iterator(); iterator.hasNext(); ) {
|
||||
Player vanishedPlayer = iterator.next();
|
||||
vanishList = vanishList.append(
|
||||
vanishedPlayer.displayName().colorIfAbsent(SECONDARY_COLOR)
|
||||
);
|
||||
if (iterator.hasNext()){
|
||||
vanishList = vanishList.append(
|
||||
text().content(", ").color(PRIMARY_COLOR)
|
||||
);
|
||||
}
|
||||
}
|
||||
receiver.sendMessage(vanishList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package de.shiewk.smoderation.config;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SModerationConfig {
|
||||
|
||||
private final FileConfiguration config;
|
||||
private final SModeration plugin;
|
||||
|
||||
public SModerationConfig(FileConfiguration config, SModeration plugin) {
|
||||
this.config = config;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public List<String> getSocialSpyCommands(List<String> default_){
|
||||
final String path = "socialspy-commands";
|
||||
if (!config.contains(path)){
|
||||
config.set(path, default_);
|
||||
plugin.saveConfig();
|
||||
}
|
||||
return config.getStringList(path);
|
||||
}
|
||||
|
||||
public FileConfiguration getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
package de.shiewk.smoderation.event;
|
||||
|
||||
import de.shiewk.smoderation.punishments.Punishment;
|
||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PunishmentIssueEvent extends Event implements Cancellable {
|
||||
private static final HandlerList handlerList = new HandlerList();
|
||||
|
||||
private final Punishment punishment;
|
||||
private final PunishmentContainer container;
|
||||
private boolean cancelled;
|
||||
|
||||
public PunishmentIssueEvent(Punishment punishment, PunishmentContainer container) {
|
||||
this.punishment = punishment;
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public Punishment getPunishment() {
|
||||
return punishment;
|
||||
}
|
||||
|
||||
public PunishmentContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HandlerList getHandlers() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlerList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package de.shiewk.smoderation.input;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static de.shiewk.smoderation.SModeration.CHAT_PREFIX;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
|
||||
public class ChatInput {
|
||||
private final Player player;
|
||||
private final Component prompt;
|
||||
private final Consumer<Component> action;
|
||||
private int remainingTicks;
|
||||
|
||||
private ChatInput(@NotNull Player player, @NotNull Component prompt, @NotNull Consumer<Component> action, int remainingSeconds){
|
||||
Objects.requireNonNull(action);
|
||||
Objects.requireNonNull(prompt);
|
||||
Objects.requireNonNull(player);
|
||||
this.player = player;
|
||||
this.prompt = prompt;
|
||||
this.action = action;
|
||||
this.remainingTicks = remainingSeconds * 20 + 1;
|
||||
}
|
||||
|
||||
static void tickAll() {
|
||||
runningInputs.values().forEach(ChatInput::tick);
|
||||
}
|
||||
|
||||
void tick(){
|
||||
remainingTicks--;
|
||||
if (remainingTicks <= 0){
|
||||
runningInputs.remove(player);
|
||||
return;
|
||||
}
|
||||
if (remainingTicks % 20 == 0){
|
||||
player.showTitle(Title.title(
|
||||
text().content(getRemainingTicks() / 20 + " seconds").color(GRAY).build(),
|
||||
getPrompt(),
|
||||
Title.Times.times(Duration.ZERO, Duration.ofSeconds(2), Duration.ZERO)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
final static ConcurrentHashMap<Player, ChatInput> runningInputs = new ConcurrentHashMap<>();
|
||||
|
||||
public static void prompt(Player player, Consumer<Component> consumer, Component prompt, int timeSeconds){
|
||||
runningInputs.put(player, new ChatInput(player, prompt, consumer, timeSeconds));
|
||||
player.sendMessage(CHAT_PREFIX.append(prompt));
|
||||
}
|
||||
|
||||
public Component getPrompt() {
|
||||
return prompt;
|
||||
}
|
||||
|
||||
public Consumer<Component> getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public int getRemainingTicks() {
|
||||
return remainingTicks;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package de.shiewk.smoderation.input;
|
||||
|
||||
import com.destroystokyo.paper.event.server.ServerTickStartEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import static de.shiewk.smoderation.input.ChatInput.runningInputs;
|
||||
|
||||
public class ChatInputListener implements Listener {
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onAsyncChat(AsyncChatEvent event){
|
||||
final ChatInput input = runningInputs.remove(event.getPlayer());
|
||||
if (input != null){
|
||||
event.setCancelled(true);
|
||||
input.getAction().accept(event.message());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
|
||||
runningInputs.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR) public void onServerTickStart(ServerTickStartEvent event){
|
||||
ChatInput.tickAll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package de.shiewk.smoderation.inventory;
|
||||
|
||||
public interface AutoUpdatingCustomInventory extends CustomInventory { }
|
||||
@@ -1,68 +0,0 @@
|
||||
package de.shiewk.smoderation.inventory;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConfirmationInventory implements CustomInventory {
|
||||
private final Inventory inventory;
|
||||
private final Player player;
|
||||
private final String prompt;
|
||||
private final ItemStack yesStack;
|
||||
private final ItemStack noStack;
|
||||
private final Runnable onAccept;
|
||||
private final Runnable onReject;
|
||||
private final boolean reversed;
|
||||
|
||||
public ConfirmationInventory(Player player, String prompt, Runnable onAccept, Runnable onReject, boolean reversed) {
|
||||
this.player = player;
|
||||
this.prompt = prompt;
|
||||
this.onAccept = onAccept;
|
||||
this.onReject = onReject;
|
||||
this.reversed = reversed;
|
||||
inventory = Bukkit.createInventory(this, InventoryType.HOPPER, Component.text(this.prompt));
|
||||
yesStack = new ItemStack(Material.LIME_STAINED_GLASS_PANE);
|
||||
noStack = new ItemStack(Material.RED_STAINED_GLASS_PANE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
yesStack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("Yes").color(NamedTextColor.GREEN))));
|
||||
noStack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("No").color(NamedTextColor.RED))));
|
||||
ItemStack confirmation = new ItemStack(Material.PAPER);
|
||||
confirmation.editMeta(meta -> meta.displayName(applyFormatting(Component.text(prompt).color(NamedTextColor.GOLD))));
|
||||
|
||||
inventory.setItem(reversed ? 4 : 0, noStack);
|
||||
inventory.setItem(2, confirmation);
|
||||
inventory.setItem(reversed ? 0 : 4, yesStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
refresh();
|
||||
player.openInventory(getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
||||
if (yesStack.equals(stack)){
|
||||
inventory.close();
|
||||
onAccept.run();
|
||||
} else if (noStack.equals(stack)) {
|
||||
inventory.close();
|
||||
onReject.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package de.shiewk.smoderation.inventory;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface CustomInventory extends InventoryHolder {
|
||||
|
||||
void refresh();
|
||||
void open();
|
||||
void click(ItemStack stack, InventoryClickEvent event);
|
||||
|
||||
default ItemStack createEmptyStack(){
|
||||
ItemStack stack = new ItemStack(Material.BLACK_STAINED_GLASS_PANE);
|
||||
stack.editMeta(meta -> meta.displayName(Component.empty()));
|
||||
return stack;
|
||||
}
|
||||
|
||||
default Component applyFormatting(Component component){
|
||||
return component.decoration(TextDecoration.ITALIC, false);
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package de.shiewk.smoderation.inventory;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class InvSeeEquipmentInventory implements AutoUpdatingCustomInventory {
|
||||
private final HumanEntity viewer;
|
||||
private final HumanEntity subject;
|
||||
private final Inventory inventory = Bukkit.createInventory(this, InventoryType.HOPPER, text("Player equipment"));
|
||||
private boolean changing = false;
|
||||
|
||||
public InvSeeEquipmentInventory(HumanEntity viewer, HumanEntity subject) {
|
||||
this.viewer = viewer;
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
if (!changing){
|
||||
final EntityEquipment equipment = subject.getEquipment();
|
||||
inventory.setItem(0, equipment.getHelmet());
|
||||
inventory.setItem(1, equipment.getChestplate());
|
||||
inventory.setItem(2, equipment.getLeggings());
|
||||
inventory.setItem(3, equipment.getBoots());
|
||||
inventory.setItem(4, equipment.getItemInOffHand());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
refresh();
|
||||
viewer.openInventory(getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
||||
if (viewer.hasPermission("smod.invsee.modify") && !subject.hasPermission("smod.invsee.preventmodify")){
|
||||
event.setCancelled(false);
|
||||
changing = true;
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModeration.PLUGIN, () -> {
|
||||
changing = false;
|
||||
final EntityEquipment equipment = subject.getEquipment();
|
||||
equipment.setHelmet(inventory.getItem(0));
|
||||
equipment.setChestplate(inventory.getItem(1));
|
||||
equipment.setLeggings(inventory.getItem(2));
|
||||
equipment.setBoots(inventory.getItem(3));
|
||||
equipment.setItemInOffHand(inventory.getItem(4));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
package de.shiewk.smoderation.inventory;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public abstract class PageableCustomInventory implements CustomInventory {
|
||||
public abstract int lastPage();
|
||||
public abstract void switchPage();
|
||||
private ItemStack previousStack = null;
|
||||
private ItemStack nextStack = null;
|
||||
private int page = 0;
|
||||
|
||||
public int getPage(){
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
||||
if (stack != null){
|
||||
if (stack.equals(previousStack)){
|
||||
previousPage();
|
||||
} else if (stack.equals(nextStack)) {
|
||||
nextPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void nextPage(){
|
||||
if (page < lastPage()){
|
||||
page++;
|
||||
switchPage();
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void previousPage(){
|
||||
if (page > 0){
|
||||
page--;
|
||||
switchPage();
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack createPreviousPageStack(){
|
||||
boolean allowed = page > 0;
|
||||
TextColor color = allowed ? NamedTextColor.GREEN : NamedTextColor.RED;
|
||||
int skip = allowed ? page : page+1;
|
||||
ItemStack stack = new ItemStack(allowed ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE);
|
||||
stack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("Previous page (%s/%s)".formatted(skip, lastPage()+1)).color(color))));
|
||||
previousStack = stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
public ItemStack createNextPageStack(){
|
||||
boolean allowed = page < lastPage();
|
||||
TextColor color = allowed ? NamedTextColor.GREEN : NamedTextColor.RED;
|
||||
int skip = allowed ? page+2 : page+1;
|
||||
ItemStack stack = new ItemStack(allowed ? Material.GREEN_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE);
|
||||
stack.editMeta(meta -> meta.displayName(applyFormatting(Component.text("Next page (%s/%s)".formatted(skip, lastPage()+1)).color(color))));
|
||||
nextStack = stack;
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
@@ -1,393 +0,0 @@
|
||||
package de.shiewk.smoderation.inventory;
|
||||
|
||||
import de.shiewk.smoderation.input.ChatInput;
|
||||
import de.shiewk.smoderation.punishments.Punishment;
|
||||
import de.shiewk.smoderation.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
||||
import de.shiewk.smoderation.util.PlayerUtil;
|
||||
import de.shiewk.smoderation.util.TimeUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static de.shiewk.smoderation.SModeration.*;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class SModMenu extends PageableCustomInventory {
|
||||
|
||||
public enum Filter {
|
||||
ACTIVE("Active punishments", Punishment::isActive),
|
||||
OLD("Old punishments", p -> !p.isActive()),
|
||||
ALL("All punishments", p -> true);
|
||||
|
||||
public static final Material ICON = Material.HOPPER;
|
||||
|
||||
public final String name;
|
||||
public final Predicate<Punishment> filter;
|
||||
Filter(String name, Predicate<Punishment> filter) {
|
||||
this.name = name;
|
||||
this.filter = filter;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Sort {
|
||||
EXPIRY("Expiry", Comparator.comparingLong(p -> p.until)),
|
||||
TIME("Date", Comparator.comparingLong(p -> p.time)),
|
||||
PLAYER_NAME("Player name", (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.to), PlayerUtil.offlinePlayerName(p2.to))),
|
||||
MODERATOR_NAME("Moderator name", (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.by), PlayerUtil.offlinePlayerName(p2.by)));
|
||||
|
||||
public static final Material ICON = Material.COMPARATOR;
|
||||
|
||||
public final String name;
|
||||
public final Comparator<Punishment> comparator;
|
||||
|
||||
Sort(String name, Comparator<Punishment> comparator) {
|
||||
this.name = name;
|
||||
this.comparator = comparator;
|
||||
}
|
||||
}
|
||||
private static final NamespacedKey PUNISHMENT_STORE_KEY = new NamespacedKey("smod", "punishmentid");
|
||||
|
||||
private final Inventory inventory;
|
||||
private final Player player;
|
||||
private final PunishmentContainer container;
|
||||
private List<Punishment> punishments;
|
||||
private ItemStack sortStack = null;
|
||||
private ItemStack filterStack = null;
|
||||
private ItemStack searchStack = null;
|
||||
private ItemStack typeStack = null;
|
||||
private int sort = 0;
|
||||
private int filter = 0;
|
||||
private int type = -1;
|
||||
private String searchQuery = null;
|
||||
|
||||
public SModMenu(Player player, PunishmentContainer container) {
|
||||
this.player = player;
|
||||
this.container = container;
|
||||
this.inventory = Bukkit.createInventory(this, 54, text("SMod Menu"));
|
||||
reload();
|
||||
}
|
||||
|
||||
public Sort getSort(){
|
||||
return Sort.values()[sort];
|
||||
}
|
||||
|
||||
public Filter getFilter(){
|
||||
return Filter.values()[filter];
|
||||
}
|
||||
|
||||
public PunishmentType getType(){
|
||||
return type == -1 ? null : PunishmentType.values()[type];
|
||||
}
|
||||
|
||||
private void reload(){
|
||||
this.punishments = container.copy().stream()
|
||||
.filter(getFilter().filter)
|
||||
.filter(p -> getType() == null || p.type == getType())
|
||||
.filter(p -> p.matchesSearchQuery(searchQuery))
|
||||
.sorted(getSort().comparator).toList();
|
||||
}
|
||||
|
||||
public void promptSearchQuery(){
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(PLUGIN, player::closeInventory);
|
||||
ChatInput.prompt(player, component -> {
|
||||
if (component instanceof TextComponent text){
|
||||
this.searchQuery = text.content();
|
||||
// chat event is async
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(PLUGIN, this::open);
|
||||
}
|
||||
}, text("Enter your search query in chat").color(SECONDARY_COLOR), 30);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int lastPage() {
|
||||
return Math.max((punishments.size() - 1) / 45, 0);
|
||||
}
|
||||
|
||||
public void cycleFilter(boolean backwards){
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
||||
if (backwards){
|
||||
if (filter <= 0){
|
||||
filter = Filter.values().length-1;
|
||||
} else {
|
||||
filter--;
|
||||
}
|
||||
} else {
|
||||
if (filter >= Filter.values().length-1){
|
||||
filter = 0;
|
||||
} else {
|
||||
filter++;
|
||||
}
|
||||
}
|
||||
reload();
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void cycleSort(boolean backwards){
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
||||
if (backwards){
|
||||
if (sort <= 0){
|
||||
sort = Sort.values().length-1;
|
||||
} else {
|
||||
sort--;
|
||||
}
|
||||
} else {
|
||||
if (sort >= Sort.values().length-1){
|
||||
sort = 0;
|
||||
} else {
|
||||
sort++;
|
||||
}
|
||||
}
|
||||
reload();
|
||||
refresh();
|
||||
}
|
||||
|
||||
public void cycleType(boolean backwards){
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
|
||||
if (backwards){
|
||||
if (type <= -1){
|
||||
type = PunishmentType.values().length-1;
|
||||
} else {
|
||||
type--;
|
||||
}
|
||||
} else {
|
||||
if (type >= PunishmentType.values().length-1){
|
||||
type = -1;
|
||||
} else {
|
||||
type++;
|
||||
}
|
||||
}
|
||||
reload();
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void switchPage() {
|
||||
player.playSound(player, Sound.BLOCK_STONE_HIT, 0.75f, 1f);
|
||||
}
|
||||
|
||||
private ItemStack createFilterItem(){
|
||||
final Filter filter = getFilter();
|
||||
final ItemStack stack = new ItemStack(Filter.ICON);
|
||||
stack.editMeta(meta -> {
|
||||
meta.displayName(applyFormatting(text("Filter: " + filter.name).color(PRIMARY_COLOR)));
|
||||
ArrayList<Component> lore = new ArrayList<>();
|
||||
lore.add(Component.empty());
|
||||
for (Filter value : Filter.values()) {
|
||||
final boolean selected = filter == value;
|
||||
Component filterText = applyFormatting(text((selected ? "\u00BB " : "") + value.name).color(selected ? SECONDARY_COLOR : INACTIVE_COLOR));
|
||||
lore.add(filterText);
|
||||
}
|
||||
lore.add(Component.empty());
|
||||
lore.add(applyFormatting(text("\u00BB Click to switch filter").color(NamedTextColor.GOLD)));
|
||||
meta.lore(lore);
|
||||
});
|
||||
filterStack = stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
private ItemStack createTypeItem(){
|
||||
final PunishmentType type = getType();
|
||||
final ItemStack stack = new ItemStack(Material.CHEST);
|
||||
stack.editMeta(meta -> {
|
||||
meta.displayName(applyFormatting(text("Type: " + (type == null ? "All" : type.name)).color(PRIMARY_COLOR)));
|
||||
ArrayList<Component> lore = new ArrayList<>();
|
||||
lore.add(Component.empty());
|
||||
final Consumer<PunishmentType> addToLore = value -> {
|
||||
final boolean selected = type == value;
|
||||
Component typeText = applyFormatting(text((selected ? "\u00BB " : "") + (value == null ? "All" : value.name)).color(selected ? SECONDARY_COLOR : INACTIVE_COLOR));
|
||||
lore.add(typeText);
|
||||
};
|
||||
addToLore.accept(null);
|
||||
for (PunishmentType value : PunishmentType.values()) {
|
||||
addToLore.accept(value);
|
||||
}
|
||||
lore.add(Component.empty());
|
||||
lore.add(applyFormatting(text("\u00BB Click to switch type").color(NamedTextColor.GOLD)));
|
||||
meta.lore(lore);
|
||||
});
|
||||
return typeStack = stack;
|
||||
}
|
||||
|
||||
private ItemStack createSortItem(){
|
||||
final Sort sort = getSort();
|
||||
final ItemStack stack = new ItemStack(Sort.ICON);
|
||||
stack.editMeta(meta -> {
|
||||
meta.displayName(applyFormatting(text("Sort by: " + sort.name).color(PRIMARY_COLOR)));
|
||||
ArrayList<Component> lore = new ArrayList<>();
|
||||
lore.add(Component.empty());
|
||||
for (Sort value : Sort.values()) {
|
||||
final boolean selected = sort == value;
|
||||
Component sortText = applyFormatting(text((selected ? "\u00BB " : "") + value.name).color(selected ? SECONDARY_COLOR : INACTIVE_COLOR));
|
||||
lore.add(sortText);
|
||||
}
|
||||
lore.add(Component.empty());
|
||||
lore.add(applyFormatting(text("\u00BB Click to switch sorting option").color(NamedTextColor.GOLD)));
|
||||
meta.lore(lore);
|
||||
});
|
||||
sortStack = stack;
|
||||
return stack;
|
||||
}
|
||||
|
||||
private ItemStack createSearchItem(){
|
||||
final ItemStack stack = new ItemStack(Material.FLOWER_BANNER_PATTERN);
|
||||
stack.editMeta(meta -> {
|
||||
meta.addItemFlags(ItemFlag.HIDE_ITEM_SPECIFICS);
|
||||
meta.displayName(applyFormatting(text("Search").color(PRIMARY_COLOR)));
|
||||
final ArrayList<Component> lore = new ArrayList<>(List.of(
|
||||
Component.empty(),
|
||||
applyFormatting(text("Current search query: %s".formatted(searchQuery == null ? "None" : "\"" + searchQuery + "\"")).color(SECONDARY_COLOR)),
|
||||
Component.empty(),
|
||||
applyFormatting(text("\u00BB Click to enter new search query").color(NamedTextColor.GOLD))
|
||||
));
|
||||
if (searchQuery != null){
|
||||
lore.add(applyFormatting(text("\u00BB Right click to remove search query").color(NamedTextColor.GOLD)));
|
||||
}
|
||||
meta.lore(lore);
|
||||
});
|
||||
return searchStack = stack;
|
||||
}
|
||||
|
||||
private ItemStack createPunishmentItem(Punishment punishment){
|
||||
ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
|
||||
stack.editMeta(meta -> {
|
||||
if (meta instanceof SkullMeta skullMeta){
|
||||
try {
|
||||
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.to));
|
||||
} catch (NullPointerException e) {
|
||||
LOGGER.warn("Player {} has a punishment but was never on this server!", punishment.to);
|
||||
};
|
||||
}
|
||||
meta.displayName(applyFormatting(text(punishment.type.name).color(NamedTextColor.RED).decorate(TextDecoration.BOLD)));
|
||||
ArrayList<Component> lore = new ArrayList<>();
|
||||
lore.add(applyFormatting(text("Player: ").color(SECONDARY_COLOR).append(text(PlayerUtil.offlinePlayerName(punishment.to)).color(PRIMARY_COLOR))));
|
||||
lore.add(applyFormatting(text("Punished by: ").color(SECONDARY_COLOR).append(text(PlayerUtil.offlinePlayerName(punishment.by)).color(PRIMARY_COLOR))));
|
||||
lore.add(applyFormatting(text("Timestamp: ").color(SECONDARY_COLOR).append(text(TimeUtil.calendarTimestamp(punishment.time)).color(PRIMARY_COLOR))));
|
||||
if (punishment.type != PunishmentType.KICK){
|
||||
lore.add(applyFormatting(text("Duration: ").color(SECONDARY_COLOR).append(text(TimeUtil.formatTimeLong(punishment.until - punishment.time)).color(PRIMARY_COLOR))));
|
||||
long remainingTime = punishment.until - System.currentTimeMillis();
|
||||
final String expires;
|
||||
if (remainingTime > 0){
|
||||
expires = "in " + TimeUtil.formatTimeLong(remainingTime);
|
||||
} else {
|
||||
remainingTime *= -1;
|
||||
expires = TimeUtil.formatTimeLong(remainingTime) + " ago";
|
||||
}
|
||||
lore.add(applyFormatting(text("Expires: ").color(SECONDARY_COLOR).append(text(expires).color(PRIMARY_COLOR))));
|
||||
}
|
||||
lore.add(applyFormatting(text("Reason: ").color(SECONDARY_COLOR).append(text(punishment.reason).color(PRIMARY_COLOR))));
|
||||
if (punishment.wasUndone()){
|
||||
lore.add(applyFormatting(text("Undone by: ").color(NamedTextColor.RED).append(text(PlayerUtil.offlinePlayerName(punishment.undoneBy())).color(NamedTextColor.GOLD))));
|
||||
} else if (punishment.isActive()) {
|
||||
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))){
|
||||
lore.add(Component.empty());
|
||||
lore.add(applyFormatting(text("\u00BB Click to undo punishment").color(NamedTextColor.GOLD)));
|
||||
}
|
||||
}
|
||||
meta.lore(lore);
|
||||
});
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
for (int i = 45; i < 54; i++) {
|
||||
inventory.setItem(i, createEmptyStack());
|
||||
}
|
||||
inventory.setItem(45, createPreviousPageStack());
|
||||
inventory.setItem(53, createNextPageStack());
|
||||
inventory.setItem(47, createSearchItem());
|
||||
inventory.setItem(48, createTypeItem());
|
||||
inventory.setItem(50, createFilterItem());
|
||||
inventory.setItem(51, createSortItem());
|
||||
|
||||
for (int i = 0; i < 45; i++) {
|
||||
int ci = i + (getPage() * 45);
|
||||
if (punishments.size() > ci){
|
||||
final Punishment punishment = punishments.get(ci);
|
||||
final ItemStack item = createPunishmentItem(punishment);
|
||||
if (punishment.isActive()){
|
||||
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))) {
|
||||
item.editMeta(meta -> meta.getPersistentDataContainer().set(PUNISHMENT_STORE_KEY, PersistentDataType.LONG, punishment.time));
|
||||
}
|
||||
}
|
||||
inventory.setItem(i, item);
|
||||
} else {
|
||||
inventory.setItem(i, new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click(ItemStack stack, InventoryClickEvent event) {
|
||||
super.click(stack, event);
|
||||
if (stack != null) {
|
||||
if (stack.equals(filterStack)){
|
||||
cycleFilter(event.isRightClick());
|
||||
} else if (stack.equals(sortStack)){
|
||||
cycleSort(event.isRightClick());
|
||||
} else if (stack.equals(searchStack)){
|
||||
if (event.isRightClick() && searchQuery != null){
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 0.8f);
|
||||
searchQuery = null;
|
||||
reload();
|
||||
refresh();
|
||||
} else {
|
||||
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 2f);
|
||||
promptSearchQuery();
|
||||
}
|
||||
} else if (stack.equals(typeStack)) {
|
||||
cycleType(event.isRightClick());
|
||||
}
|
||||
final ItemMeta itemMeta = stack.getItemMeta();
|
||||
if (itemMeta != null) {
|
||||
final PersistentDataContainer persistentDataContainer = itemMeta.getPersistentDataContainer();
|
||||
final Long timestamp = persistentDataContainer.get(PUNISHMENT_STORE_KEY, PersistentDataType.LONG);
|
||||
if (timestamp != null) {
|
||||
final Punishment punishment = container.findByTimestamp(timestamp);
|
||||
if (punishment != null) {
|
||||
new ConfirmationInventory(player, "Do you want to undo this punishment?", () -> {
|
||||
punishment.undo(player.getUniqueId());
|
||||
punishment.broadcastUndo(container);
|
||||
player.playSound(player, Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 2f);
|
||||
this.open();
|
||||
}, this::open, false).open();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
reload();
|
||||
refresh();
|
||||
player.openInventory(this.inventory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package de.shiewk.smoderation.listener;
|
||||
|
||||
import com.destroystokyo.paper.event.server.ServerTickEndEvent;
|
||||
import de.shiewk.smoderation.inventory.AutoUpdatingCustomInventory;
|
||||
import de.shiewk.smoderation.inventory.CustomInventory;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
|
||||
public class CustomInventoryListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onInventoryClick(InventoryClickEvent event){
|
||||
if (event.getInventory().getHolder() instanceof CustomInventory customInventory){
|
||||
event.setCancelled(true);
|
||||
customInventory.click(event.getCurrentItem(), event);
|
||||
}
|
||||
}
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onInventoryDrag(InventoryDragEvent event){
|
||||
if (event.getInventory().getHolder() instanceof CustomInventory){
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onServerTickEnd(ServerTickEndEvent event){
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.getOpenInventory().getTopInventory().getHolder() instanceof AutoUpdatingCustomInventory ci) {
|
||||
ci.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package de.shiewk.smoderation.listener;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
public class EnderchestSeeListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event){
|
||||
final Inventory clicked = event.getView().getTopInventory();
|
||||
if (!(clicked instanceof PlayerInventory)){
|
||||
final InventoryHolder holder = clicked.getHolder();
|
||||
if (holder instanceof HumanEntity humanHolder && humanHolder.getEnderChest().equals(clicked) && !humanHolder.equals(event.getWhoClicked())){
|
||||
if (!event.getWhoClicked().hasPermission("smod.enderchestsee.modify")){
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package de.shiewk.smoderation.listener;
|
||||
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class InvSeeListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event){
|
||||
final Inventory clicked = event.getView().getTopInventory();
|
||||
if (clicked instanceof PlayerInventory inventory){
|
||||
final HumanEntity holder = inventory.getHolder();
|
||||
if (Objects.equals(holder, event.getWhoClicked())){
|
||||
return;
|
||||
}
|
||||
if (!event.getWhoClicked().hasPermission("smod.invsee.modify")){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (holder != null) {
|
||||
if (holder.hasPermission("smod.invsee.preventmodify")){
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package de.shiewk.smoderation.listener;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.event.PunishmentIssueEvent;
|
||||
import de.shiewk.smoderation.punishments.Punishment;
|
||||
import de.shiewk.smoderation.punishments.PunishmentType;
|
||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.world.WorldSaveEvent;
|
||||
|
||||
import static de.shiewk.smoderation.SModeration.CHAT_PREFIX;
|
||||
|
||||
public class PunishmentListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPlayerLogin(PlayerLoginEvent event){
|
||||
Punishment punishment = SModeration.container.find(p ->
|
||||
p.type == PunishmentType.BAN
|
||||
&& p.to.equals(event.getPlayer().getUniqueId())
|
||||
&& p.isActive());
|
||||
if (punishment != null){
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CHAT_PREFIX.append(punishment.playerMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncChatEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
final Punishment punishment = SModeration.container.find(p ->
|
||||
p.type == PunishmentType.MUTE
|
||||
&& p.to.equals(player.getUniqueId())
|
||||
&& p.isActive());
|
||||
if (punishment != null) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(CHAT_PREFIX.append(punishment.playerMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPunishmentIssue(PunishmentIssueEvent event){
|
||||
final Punishment punishment = event.getPunishment();
|
||||
final PunishmentContainer container = event.getContainer();
|
||||
final Punishment duplicate = container.find(p -> p.to.equals(punishment.to) && p.type == punishment.type && p.isActive());
|
||||
if (duplicate != null){
|
||||
container.remove(duplicate);
|
||||
container.add(new Punishment(duplicate.type, duplicate.time, System.currentTimeMillis(), duplicate.by, duplicate.to, duplicate.reason));
|
||||
}
|
||||
switch (punishment.type){
|
||||
case KICK, BAN -> {
|
||||
final Player player = Bukkit.getPlayer(punishment.to);
|
||||
if (player != null) {
|
||||
player.kick(CHAT_PREFIX.append(punishment.playerMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldSave(WorldSaveEvent event){
|
||||
if (event.getWorld().equals(Bukkit.getServer().getWorlds().get(0))){
|
||||
SModeration.container.save(SModeration.SAVE_FILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package de.shiewk.smoderation.listener;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.shiewk.smoderation.SModeration.PRIMARY_COLOR;
|
||||
import static de.shiewk.smoderation.SModeration.SECONDARY_COLOR;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class SocialSpyListener implements Listener {
|
||||
|
||||
private static final List<String> defaultCommands = List.of(
|
||||
"w",
|
||||
"tell",
|
||||
"msg",
|
||||
"teammsg",
|
||||
"tm",
|
||||
"minecraft:w",
|
||||
"minecraft:tell",
|
||||
"minecraft:msg",
|
||||
"minecraft:teammsg",
|
||||
"minecraft:tm"
|
||||
);
|
||||
|
||||
private static final NamespacedKey SAVE_KEY = new NamespacedKey("smoderation", "socialspy");
|
||||
private static final ObjectArrayList<CommandSender> targets = new ObjectArrayList<>();
|
||||
|
||||
public static boolean toggle(CommandSender sender) {
|
||||
boolean enabledNow = isEnabled(sender);
|
||||
if (enabledNow){
|
||||
targets.remove(sender);
|
||||
if (sender instanceof Player player){
|
||||
player.getPersistentDataContainer().set(SAVE_KEY, PersistentDataType.BOOLEAN, false);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
targets.add(sender);
|
||||
if (sender instanceof Player player){
|
||||
player.getPersistentDataContainer().set(SAVE_KEY, PersistentDataType.BOOLEAN, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onPlayerJoin(PlayerJoinEvent event){
|
||||
final PersistentDataContainer pdc = event.getPlayer().getPersistentDataContainer();
|
||||
if (Boolean.TRUE.equals(pdc.get(SAVE_KEY, PersistentDataType.BOOLEAN))){
|
||||
targets.add(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
|
||||
targets.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
public static boolean isEnabled(CommandSender sender){
|
||||
return targets.contains(sender);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||
public void onPlayerSendCommand(PlayerCommandPreprocessEvent event){
|
||||
List<String> ssCommands = SModeration.CONFIG.getSocialSpyCommands(defaultCommands);
|
||||
final String message = event.getMessage();
|
||||
if (ssCommands.stream().anyMatch(str ->
|
||||
message.startsWith("/"+str+" ")
|
||||
|| message.startsWith(str+" ")
|
||||
)){
|
||||
SocialSpyListener.command(event.getPlayer(), message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void command(Player player, String command){
|
||||
for (CommandSender target : targets) {
|
||||
target.sendMessage(text("[", PRIMARY_COLOR)
|
||||
.append(text("SocialSpy", SECONDARY_COLOR))
|
||||
.append(text("] "))
|
||||
.append(player.displayName().colorIfAbsent(PRIMARY_COLOR))
|
||||
.append(text(": ", PRIMARY_COLOR))
|
||||
.append(text(command, SECONDARY_COLOR))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package de.shiewk.smoderation.listener;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.command.VanishCommand;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import static de.shiewk.smoderation.SModeration.SECONDARY_COLOR;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
|
||||
public class VanishListener implements Listener {
|
||||
|
||||
@EventHandler public void onPlayerQuit(PlayerQuitEvent event){
|
||||
final Player player = event.getPlayer();
|
||||
if (VanishCommand.isVanished(player)){
|
||||
VanishCommand.toggleVanish(player);
|
||||
}
|
||||
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||
// to clean up visibility status
|
||||
player.hideEntity(SModeration.PLUGIN, vanishedPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event){
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SModeration.PLUGIN, () -> {
|
||||
final Player player = event.getPlayer().getPlayer();
|
||||
assert player != null;
|
||||
if (player.hasPermission("smod.vanish.see")){
|
||||
for (Player vanishedPlayer : VanishCommand.getVanishedPlayers()) {
|
||||
// to show visible vanished players
|
||||
player.showEntity(SModeration.PLUGIN, vanishedPlayer);
|
||||
}
|
||||
VanishCommand.listVanishedPlayersTo(player);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onPlayerDeath(PlayerDeathEvent event){
|
||||
final Component message = event.deathMessage();
|
||||
if (VanishCommand.isVanished(event.getPlayer()) && message != null){
|
||||
event.deathMessage(null);
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.vanish.see")){
|
||||
onlinePlayer.sendMessage(text("[VANISH] ").color(SECONDARY_COLOR).append(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,261 +0,0 @@
|
||||
package de.shiewk.smoderation.punishments;
|
||||
|
||||
import de.shiewk.smoderation.event.PunishmentIssueEvent;
|
||||
import de.shiewk.smoderation.storage.PunishmentContainer;
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.shiewk.smoderation.SModeration.*;
|
||||
|
||||
public class Punishment {
|
||||
public static final String DEFAULT_REASON = "No reason provided.";
|
||||
public final PunishmentType type;
|
||||
public final long time;
|
||||
public final long until;
|
||||
public final UUID by;
|
||||
public final UUID to;
|
||||
public final String reason;
|
||||
private UUID undoneBy;
|
||||
|
||||
public Punishment(PunishmentType type, long time, long until, UUID by, UUID to, String reason) {
|
||||
this(type, time, until, by, to, reason, null);
|
||||
}
|
||||
|
||||
private Punishment(PunishmentType type, long time, long until, UUID by, UUID to, String reason, UUID undoneBy) {
|
||||
this.type = type;
|
||||
this.time = time;
|
||||
this.until = until;
|
||||
this.by = by;
|
||||
this.to = to;
|
||||
this.reason = reason;
|
||||
this.undoneBy = undoneBy;
|
||||
}
|
||||
|
||||
private static byte[] readStreamInternal(InputStream stream, int len) throws IOException {
|
||||
final byte[] bytes = stream.readNBytes(len);
|
||||
if (bytes.length != len){
|
||||
throw new EOFException("Stream has ended before enough bytes were read");
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static Punishment load(InputStream in) throws IOException {
|
||||
PunishmentType type = PunishmentType.values()[ByteUtil.bytesToInt(readStreamInternal(in, 4))];
|
||||
long time = ByteUtil.bytesToLong(readStreamInternal(in, 8));
|
||||
long until = ByteUtil.bytesToLong(readStreamInternal(in, 8));
|
||||
UUID by = ByteUtil.bytesToUuid(readStreamInternal(in, 16));
|
||||
UUID to = ByteUtil.bytesToUuid(readStreamInternal(in, 16));
|
||||
int reasonLen = ByteUtil.bytesToInt(readStreamInternal(in, 4));
|
||||
String reason = new String(readStreamInternal(in, reasonLen));
|
||||
UUID undoneBy = null;
|
||||
boolean undone = in.read() == 1;
|
||||
if (undone){
|
||||
undoneBy = ByteUtil.bytesToUuid(readStreamInternal(in, 16));
|
||||
}
|
||||
return new Punishment(type, time, until, by, to, reason, undoneBy);
|
||||
}
|
||||
|
||||
public boolean wasUndone(){
|
||||
return undoneBy != null;
|
||||
}
|
||||
|
||||
public UUID undoneBy() {
|
||||
return undoneBy;
|
||||
}
|
||||
|
||||
public void undo(UUID undoneBy){
|
||||
if (this.undoneBy != null){
|
||||
throw new IllegalArgumentException("This punishment was already undone.");
|
||||
}
|
||||
this.undoneBy = undoneBy;
|
||||
}
|
||||
|
||||
public boolean isActive(){
|
||||
return until > System.currentTimeMillis() && !wasUndone();
|
||||
}
|
||||
|
||||
public static Punishment mute(long time, long until, UUID by, UUID to, String reason){
|
||||
return new Punishment(PunishmentType.MUTE, time, until, by, to, reason);
|
||||
}
|
||||
|
||||
public static Punishment ban(long time, long until, UUID by, UUID to, String reason){
|
||||
return new Punishment(PunishmentType.BAN, time, until, by, to, reason);
|
||||
}
|
||||
|
||||
public static Punishment kick(long time, UUID by, UUID to, String reason){
|
||||
return new Punishment(PunishmentType.KICK, time, time, by, to, reason);
|
||||
}
|
||||
|
||||
private static final int BUFFER_LENGTH = 56;
|
||||
|
||||
public void writeBytes(OutputStream stream) throws IOException {
|
||||
stream.write(ByteUtil.intToBytes(type.ordinal()));
|
||||
stream.write(ByteUtil.longToBytes(time));
|
||||
stream.write(ByteUtil.longToBytes(until));
|
||||
stream.write(ByteUtil.uuidToBytes(by));
|
||||
stream.write(ByteUtil.uuidToBytes(to));
|
||||
final byte[] reasonBytes = reason.getBytes();
|
||||
stream.write(ByteUtil.intToBytes(reasonBytes.length));
|
||||
stream.write(reasonBytes);
|
||||
stream.write(wasUndone() ? 1 : 0);
|
||||
if (wasUndone()){
|
||||
stream.write(ByteUtil.uuidToBytes(undoneBy));
|
||||
}
|
||||
}
|
||||
|
||||
private Component undoMessage(){
|
||||
String msg = "";
|
||||
switch (type){
|
||||
case MUTE -> msg = "unmuted";
|
||||
case KICK -> msg = "unkicked??";
|
||||
case BAN -> msg = "unbanned";
|
||||
}
|
||||
return Component.text(PlayerUtil.offlinePlayerName(to)).color(SECONDARY_COLOR)
|
||||
.append(Component.text(" was ").color(PRIMARY_COLOR))
|
||||
.append(Component.text(msg))
|
||||
.append(Component.text(" by ").color(PRIMARY_COLOR))
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(undoneBy)))
|
||||
.append(Component.text(".").color(PRIMARY_COLOR));
|
||||
}
|
||||
|
||||
public void broadcastUndo(PunishmentContainer container){
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(undoMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Punishment{" +
|
||||
"type=" + type +
|
||||
", time=" + time +
|
||||
", until=" + until +
|
||||
", by=" + by +
|
||||
", to=" + to +
|
||||
", reason=" + reason +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static void issue(Punishment punishment, PunishmentContainer container){
|
||||
final PunishmentIssueEvent event = new PunishmentIssueEvent(punishment, container);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()){
|
||||
container.add(punishment);
|
||||
punishment.firstIssue(container);
|
||||
}
|
||||
}
|
||||
|
||||
private Component broadcastMessage(){
|
||||
final String toName = PlayerUtil.offlinePlayerName(to);
|
||||
switch (type) {
|
||||
case MUTE -> {
|
||||
return Component.text(toName).color(SECONDARY_COLOR).append(
|
||||
Component.text(" has been muted by ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(" for "))
|
||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - this.time)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(".\nReason: "))
|
||||
.append(Component.text(reason).color(SECONDARY_COLOR)));
|
||||
}
|
||||
case KICK -> {
|
||||
return Component.text(toName).color(SECONDARY_COLOR).append(
|
||||
Component.text(" has been kicked by ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(".\nReason: "))
|
||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
||||
.color(PRIMARY_COLOR));
|
||||
}
|
||||
case BAN -> {
|
||||
return Component.text(toName).color(SECONDARY_COLOR).append(
|
||||
Component.text(" has been banned by ").color(PRIMARY_COLOR)
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(" for "))
|
||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - this.time)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(".\nReason: "))
|
||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
||||
.color(PRIMARY_COLOR));
|
||||
}
|
||||
default -> throw new IllegalStateException("Unknown punishment type " + type);
|
||||
}
|
||||
}
|
||||
|
||||
private void broadcastIssue(PunishmentContainer container){
|
||||
for (CommandSender sender : container.collectBroadcastTargets()) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(broadcastMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private void firstIssue(PunishmentContainer container){
|
||||
switch (type) {
|
||||
case MUTE, BAN -> {
|
||||
final CommandSender sender = PlayerUtil.senderByUUID(to);
|
||||
if (sender != null) {
|
||||
sender.sendMessage(CHAT_PREFIX.append(playerMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
broadcastIssue(container);
|
||||
}
|
||||
|
||||
public Component playerMessage(){
|
||||
switch (type) {
|
||||
case MUTE -> {
|
||||
return Component.text("You have been muted by ")
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(".\nReason: "))
|
||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
||||
.append(Component.text("\nYour mute expires in "))
|
||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - System.currentTimeMillis())).color(SECONDARY_COLOR))
|
||||
.append(Component.text("."))
|
||||
.color(PRIMARY_COLOR);
|
||||
}
|
||||
case KICK -> {
|
||||
return Component.text("You have been kicked by ")
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(".\nReason: "))
|
||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
||||
.color(PRIMARY_COLOR);
|
||||
}
|
||||
case BAN -> {
|
||||
return Component.text("You have been banned from this server by ")
|
||||
.append(Component.text(PlayerUtil.offlinePlayerName(this.by)).color(SECONDARY_COLOR))
|
||||
.append(Component.text(".\nReason: "))
|
||||
.append(Component.text(reason).color(SECONDARY_COLOR))
|
||||
.append(Component.text("\nYour ban expires in "))
|
||||
.append(Component.text(TimeUtil.formatTimeLong(this.until - System.currentTimeMillis())).color(SECONDARY_COLOR))
|
||||
.append(Component.text("."))
|
||||
.color(PRIMARY_COLOR);
|
||||
}
|
||||
default -> throw new IllegalStateException("Unknown punishment type " + type);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean matchesSearchQuery(String searchQuery) {
|
||||
if (searchQuery == null) return true;
|
||||
searchQuery = searchQuery.toLowerCase();
|
||||
return reason.toLowerCase().contains(searchQuery)
|
||||
|| by.toString().equalsIgnoreCase(searchQuery)
|
||||
|| to.toString().equalsIgnoreCase(searchQuery)
|
||||
|| getPlayerName().toLowerCase().contains(searchQuery)
|
||||
|| getModeratorName().toLowerCase().contains(searchQuery);
|
||||
|
||||
}
|
||||
|
||||
private String getPlayerName() {
|
||||
return PlayerUtil.offlinePlayerName(to);
|
||||
}
|
||||
|
||||
private String getModeratorName() {
|
||||
return PlayerUtil.offlinePlayerName(by);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package de.shiewk.smoderation.punishments;
|
||||
|
||||
public enum PunishmentType {
|
||||
MUTE("Mute"),
|
||||
KICK("Kick"),
|
||||
BAN("Ban");
|
||||
|
||||
public final String name;
|
||||
|
||||
PunishmentType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package de.shiewk.smoderation.storage;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.punishments.Punishment;
|
||||
import net.kyori.adventure.text.logger.slf4j.ComponentLogger;
|
||||
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.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class PunishmentContainer {
|
||||
|
||||
private final CopyOnWriteArrayList<Punishment> punishments = new CopyOnWriteArrayList<>();
|
||||
|
||||
public PunishmentContainer(){}
|
||||
|
||||
public void add(Punishment punishment){
|
||||
punishments.add(punishment);
|
||||
}
|
||||
|
||||
public @Nullable Punishment remove(int index){
|
||||
return punishments.remove(index);
|
||||
}
|
||||
|
||||
public void remove(Punishment punishment){
|
||||
punishments.remove(punishment);
|
||||
}
|
||||
|
||||
public @Nullable Punishment find(Predicate<Punishment> predicate){
|
||||
for (Punishment punishment : new CopyOnWriteArrayList<>(punishments)) {
|
||||
if (predicate.test(punishment)){
|
||||
return punishment;
|
||||
}
|
||||
}
|
||||
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(){
|
||||
ArrayList<CommandSender> senders = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.hasPermission("smod.notifications")){
|
||||
senders.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
senders.add(Bukkit.getConsoleSender());
|
||||
return Collections.unmodifiableList(senders);
|
||||
}
|
||||
|
||||
public @Nullable Punishment findByTimestamp(long timestamp){
|
||||
return find(punishment -> punishment.time == timestamp);
|
||||
}
|
||||
|
||||
public ArrayList<Punishment> copy() {
|
||||
return new ArrayList<>(punishments);
|
||||
}
|
||||
|
||||
public void load(File file){
|
||||
final ComponentLogger logger = SModeration.LOGGER;
|
||||
try {
|
||||
logger.info("Loading from {}", file.getPath());
|
||||
if (!file.isFile()){
|
||||
logger.warn("The file does not exist.");
|
||||
} else {
|
||||
try (FileInputStream fin = new FileInputStream(file)){
|
||||
GZIPInputStream gzin = new GZIPInputStream(fin);
|
||||
while (gzin.available() > 0){
|
||||
add(Punishment.load(gzin));
|
||||
}
|
||||
}
|
||||
logger.info("Successfully loaded {} items.", punishments.size());
|
||||
}
|
||||
} catch (EOFException e) {
|
||||
logger.error("The file was not correctly saved, {} items could be recovered!", this.punishments.size());
|
||||
} catch (IOException e){
|
||||
logger.error("An error occurred while loading: {}", e.toString());
|
||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
||||
logger.error(stackTraceElement.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void save(File file) {
|
||||
final ComponentLogger logger = SModeration.LOGGER;
|
||||
try {
|
||||
logger.info("Saving to {}", file.getPath());
|
||||
if (!file.isFile()){
|
||||
file.mkdirs();
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
}
|
||||
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
||||
GZIPOutputStream gzout = new GZIPOutputStream(outputStream);
|
||||
for (Punishment punishment : copy()) {
|
||||
punishment.writeBytes(gzout);
|
||||
}
|
||||
gzout.close();
|
||||
}
|
||||
logger.info("Successfully saved.");
|
||||
} catch (IOException e){
|
||||
logger.error("An error occurred while saving: {}", e.toString());
|
||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
||||
logger.error(stackTraceElement.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package de.shiewk.smoderation.util;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
/**
|
||||
* Utility class for byte-based saving of integers, longs and UUIDs
|
||||
*/
|
||||
public abstract class ByteUtil {
|
||||
private ByteUtil(){}
|
||||
|
||||
public static byte[] longToBytes(long v){
|
||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||
buffer.putLong(v);
|
||||
return buffer.array();
|
||||
}
|
||||
|
||||
public static long bytesToLong(byte[] i){
|
||||
if (i.length != 8){
|
||||
throw new IllegalArgumentException("length must be 8");
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.allocate(8);
|
||||
buffer.put(0, i);
|
||||
return buffer.getLong(0);
|
||||
}
|
||||
|
||||
public static byte[] uuidToBytes(UUID uuid){
|
||||
byte[] l = longToBytes(uuid.getLeastSignificantBits());
|
||||
byte[] m = longToBytes(uuid.getMostSignificantBits());
|
||||
return new byte[]{
|
||||
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7],
|
||||
l[0], l[1], l[2], l[3], l[4], l[5], l[6], l[7]
|
||||
};
|
||||
}
|
||||
|
||||
public static UUID bytesToUuid(byte[] i){
|
||||
if (i.length != 16){
|
||||
throw new IllegalArgumentException("length must be 16, was " + i.length);
|
||||
}
|
||||
long l = bytesToLong(new byte[]{ i[8], i[9], i[10], i[11], i[12], i[13], i[14], i[15] });
|
||||
long m = bytesToLong(new byte[]{ i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7] });
|
||||
return new UUID(m, l);
|
||||
}
|
||||
|
||||
public static int bytesToInt(byte[] bytes) {
|
||||
if (bytes.length != 4){
|
||||
throw new IllegalArgumentException("length must be 4");
|
||||
}
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.put(0, bytes);
|
||||
return buffer.getInt(0);
|
||||
}
|
||||
|
||||
public static byte[] intToBytes(int value) {
|
||||
ByteBuffer buffer = ByteBuffer.allocate(4);
|
||||
buffer.putInt(value);
|
||||
return buffer.array();
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package de.shiewk.smoderation.util;
|
||||
|
||||
import de.shiewk.smoderation.SModeration;
|
||||
import de.shiewk.smoderation.punishments.Punishment;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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 java.util.function.Predicate;
|
||||
|
||||
public abstract class PlayerUtil {
|
||||
private PlayerUtil(){}
|
||||
|
||||
public static final UUID UUID_CONSOLE = new UUID(0, 0);
|
||||
|
||||
public static @NotNull String offlinePlayerName(UUID uuid){
|
||||
if (uuid.equals(UUID_CONSOLE)){
|
||||
return "CONSOLE";
|
||||
}
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(uuid);
|
||||
return player.getName() == null ? "Unknown Player " + uuid : player.getName();
|
||||
}
|
||||
|
||||
public static @Nullable UUID offlinePlayerUUIDByName(String name){
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(name); // getOfflinePlayerIfCached(String) is safer (I have experience with getOfflinePlayer(String) returning wrong UUIDs)
|
||||
if (offlinePlayer != null) {
|
||||
return offlinePlayer.getUniqueId();
|
||||
} else {
|
||||
// try to find uuid by searching through punishments
|
||||
final Punishment punishment = SModeration.container.find(p -> offlinePlayerName(p.to).equalsIgnoreCase(name));
|
||||
if (punishment != null) {
|
||||
return punishment.to;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static @Nullable CommandSender senderByUUID(@NotNull UUID uid){
|
||||
if (uid.equals(UUID_CONSOLE)){
|
||||
return Bukkit.getConsoleSender();
|
||||
} else {
|
||||
return Bukkit.getPlayer(uid);
|
||||
}
|
||||
}
|
||||
|
||||
public static @Nullable Player findOnlinePlayer(String name){
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (onlinePlayer.getName().equalsIgnoreCase(name)){
|
||||
return onlinePlayer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<String> listPlayerNames(){
|
||||
return listPlayerNames(pl -> true);
|
||||
}
|
||||
|
||||
public static List<String> listPlayerNames(final Predicate<Player> predicate) {
|
||||
final ArrayList<String> names = new ArrayList<>();
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (predicate.test(onlinePlayer)){
|
||||
names.add(onlinePlayer.getName());
|
||||
}
|
||||
}
|
||||
return List.copyOf(names);
|
||||
}
|
||||
|
||||
public static List<String> listPlayerNames(String search) {
|
||||
return StringUtil.copyPartialMatches(search, listPlayerNames(), new ArrayList<>());
|
||||
}
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
package de.shiewk.smoderation.util;
|
||||
|
||||
import org.jetbrains.annotations.Range;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public abstract class TimeUtil {
|
||||
private TimeUtil(){}
|
||||
|
||||
public static String formatTimeLong(long millis){
|
||||
long seconds = millis / 1000;
|
||||
millis -= seconds * 1000;
|
||||
|
||||
long minutes = seconds / 60;
|
||||
seconds -= minutes * 60;
|
||||
|
||||
long hours = minutes / 60;
|
||||
minutes -= hours * 60;
|
||||
|
||||
long days = hours / 24;
|
||||
hours -= days * 24;
|
||||
|
||||
long years = days / 365;
|
||||
days -= years * 365;
|
||||
|
||||
long months = days / 30;
|
||||
days -= months * 30;
|
||||
|
||||
long weeks = days / 7;
|
||||
days -= weeks * 7;
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (years > 0){
|
||||
if (!builder.isEmpty()){
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append("%s years".formatted(years));
|
||||
}
|
||||
|
||||
if (months > 0){
|
||||
if (!builder.isEmpty()){
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append("%s months".formatted(months));
|
||||
}
|
||||
|
||||
if (weeks > 0){
|
||||
if (!builder.isEmpty()){
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append("%s weeks".formatted(weeks));
|
||||
}
|
||||
|
||||
if (days > 0){
|
||||
if (!builder.isEmpty()){
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append("%s days".formatted(days));
|
||||
}
|
||||
|
||||
if (hours > 0){
|
||||
if (!builder.isEmpty()){
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append("%s hours".formatted(hours));
|
||||
}
|
||||
|
||||
if (minutes > 0){
|
||||
if (!builder.isEmpty()){
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append("%s minutes".formatted(minutes));
|
||||
}
|
||||
|
||||
if (seconds > 0){
|
||||
if (!builder.isEmpty()){
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append("%s seconds".formatted(seconds));
|
||||
}
|
||||
|
||||
if (builder.isEmpty()){
|
||||
builder.append("%s ms".formatted(millis));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static long parseDurationMillisSafely(String in){
|
||||
try {
|
||||
return parseDurationMillis(in);
|
||||
} catch (Throwable e){
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static long parseDurationMillis(String in){
|
||||
if (in.endsWith("ms")){
|
||||
return Long.parseLong(in.substring(0, in.length()-2));
|
||||
} else if (in.endsWith("s")){
|
||||
return Long.parseLong(in.substring(0, in.length()-1)) * 1000L;
|
||||
} else if (in.endsWith("min")){
|
||||
return Long.parseLong(in.substring(0, in.length()-3)) * 60000L;
|
||||
} else if (in.endsWith("h")){
|
||||
return Long.parseLong(in.substring(0, in.length()-1)) * 3600000L;
|
||||
} else if (in.endsWith("d")){
|
||||
return Long.parseLong(in.substring(0, in.length()-1)) * 86400000L;
|
||||
} else if (in.endsWith("w")){
|
||||
return Long.parseLong(in.substring(0, in.length()-1)) * 604800000L;
|
||||
} else if (in.endsWith("mo")){
|
||||
return Long.parseLong(in.substring(0, in.length()-2)) * 2592000000L;
|
||||
} else if (in.endsWith("y")){
|
||||
return Long.parseLong(in.substring(0, in.length()-1)) * 31536000000L;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static String calendarTimestamp(long time){
|
||||
Date date = new Date(time);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
TimeZone zone = calendar.getTimeZone();
|
||||
int second = calendar.get(Calendar.SECOND);
|
||||
int minute = calendar.get(Calendar.MINUTE);
|
||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
|
||||
String day = numberWithSuffix(calendar.get(Calendar.DAY_OF_MONTH));
|
||||
String month = monthName(calendar.get(Calendar.MONTH));
|
||||
return "%s %s %s, %s:%s:%s %s".formatted(
|
||||
month,
|
||||
day,
|
||||
year,
|
||||
hour < 10 ? "0" + hour : hour,
|
||||
minute < 10 ? "0" + minute : minute,
|
||||
second < 10 ? "0" + second : second,
|
||||
zone.getDisplayName(false, TimeZone.SHORT)
|
||||
);
|
||||
}
|
||||
|
||||
private static String numberWithSuffix(int i){
|
||||
return i + numberSuffix(i);
|
||||
}
|
||||
|
||||
private static String numberSuffix(int i){
|
||||
if ((i % 10) == 1 && i != 11){
|
||||
return "st";
|
||||
} else if ((i % 10) == 2 && i != 12){
|
||||
return "nd";
|
||||
} else if ((i % 10) == 3 && i != 13){
|
||||
return "rd";
|
||||
}
|
||||
return "th";
|
||||
}
|
||||
|
||||
public static String monthName(@Range(from = 0, to = 11) int m){
|
||||
switch (m){
|
||||
case 0 -> {
|
||||
return "January";
|
||||
}
|
||||
case 1 -> {
|
||||
return "February";
|
||||
}
|
||||
case 2 -> {
|
||||
return "March";
|
||||
}
|
||||
case 3 -> {
|
||||
return "April";
|
||||
}
|
||||
case 4 -> {
|
||||
return "May";
|
||||
}
|
||||
case 5 -> {
|
||||
return "June";
|
||||
}
|
||||
case 6 -> {
|
||||
return "July";
|
||||
}
|
||||
case 7 -> {
|
||||
return "August";
|
||||
}
|
||||
case 8 -> {
|
||||
return "September";
|
||||
}
|
||||
case 9 -> {
|
||||
return "October";
|
||||
}
|
||||
case 10 -> {
|
||||
return "November";
|
||||
}
|
||||
case 11 -> {
|
||||
return "December";
|
||||
}
|
||||
}
|
||||
return "Unknown Month";
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
name: SModeration
|
||||
version: '${version}'
|
||||
main: de.shiewk.smoderation.SModeration
|
||||
api-version: '1.20'
|
||||
load: STARTUP
|
||||
authors:
|
||||
- Shiewk
|
||||
description: "SModeration is an easy-to-use minecraft plugin for moderating your server."
|
||||
commands:
|
||||
modlogs:
|
||||
usage: "§cUsage: /modlogs <player|uuid>"
|
||||
aliases:
|
||||
- logs
|
||||
- seen
|
||||
- smodlogs
|
||||
permission: smod.logs
|
||||
mute:
|
||||
usage: "§cUsage: /mute <player> <duration> <reason>"
|
||||
aliases:
|
||||
- smodmute
|
||||
permission: smod.mute
|
||||
description: Mutes a player, either temporarily or permanently.
|
||||
ban:
|
||||
usage: "§cUsage: /ban <player> <duration> <reason>"
|
||||
aliases:
|
||||
- smodban
|
||||
- tempban
|
||||
permission: smod.ban
|
||||
description: Bans a player, either temporarily or permanently.
|
||||
kick:
|
||||
usage: "§cUsage: /kick <player> <reason>"
|
||||
aliases:
|
||||
- smodkick
|
||||
permission: smod.kick
|
||||
description: Kicks a player
|
||||
smod:
|
||||
usage: "§cUsage: /smod"
|
||||
aliases:
|
||||
- smodmenu
|
||||
- smoderation
|
||||
permission: smod.menu
|
||||
description: Shows the SModeration menu.
|
||||
unmute:
|
||||
usage: "§cUsage: /unmute <player|uuid>"
|
||||
aliases:
|
||||
- sunmute
|
||||
permission: smod.unmute
|
||||
description: Unmutes a muted player.
|
||||
unban:
|
||||
usage: "§cUsage: /unban <player|uuid>"
|
||||
aliases:
|
||||
- sunban
|
||||
- pardon
|
||||
- spardon
|
||||
permission: smod.unban
|
||||
description: Unbans a banned player.
|
||||
invsee:
|
||||
usage: "§cUsage: /invsee <player>"
|
||||
aliases:
|
||||
- sinvsee
|
||||
- smodinvsee
|
||||
- invs
|
||||
permission: smod.invsee
|
||||
description: Views the inventory of another player.
|
||||
enderchestsee:
|
||||
usage: "§cUsage: /enderchestsee <player>"
|
||||
aliases:
|
||||
- secsee
|
||||
- senderchestsee
|
||||
- ecsee
|
||||
- ecs
|
||||
permission: smod.enderchestsee
|
||||
description: Views the ender chest of another player.
|
||||
vanish:
|
||||
usage: "§cUsage: /vanish list or /vanish toggle <player>"
|
||||
aliases:
|
||||
- smvanish
|
||||
- smodvanish
|
||||
- v
|
||||
- smv
|
||||
permission: smod.vanish
|
||||
description: Toggles vanish mode which prevents other players from seeing you're online
|
||||
socialspy:
|
||||
usage: "§cUsage: /socialspy"
|
||||
description: Enables socialspy mode (you can see private messages of other players)
|
||||
permission: smod.socialspy
|
||||
aliases:
|
||||
- smodsocialspy
|
||||
- smsocialspy
|
||||
- smss
|
||||
- ss
|
||||
permissions:
|
||||
smod.mute:
|
||||
default: op
|
||||
description: Allows the player to mute other players.
|
||||
smod.ban:
|
||||
default: op
|
||||
description: Allows the player to ban and kick other players.
|
||||
children:
|
||||
- smod.kick
|
||||
smod.kick:
|
||||
default: op
|
||||
description: Allows the player to kick other players.
|
||||
smod.menu:
|
||||
default: op
|
||||
description: Allows the player to use the SModeration menu.
|
||||
smod.notifications:
|
||||
default: op
|
||||
description: Allows the player to be notified when a punishment is issued.
|
||||
smod.unmute:
|
||||
default: op
|
||||
description: Allows the player to unmute other players.
|
||||
smod.unban:
|
||||
default: op
|
||||
description: Allows the player to unban other players.
|
||||
smod.logs:
|
||||
default: op
|
||||
description: Allows the player to view mod logs.
|
||||
smod.invsee:
|
||||
default: op
|
||||
description: Allows the player to view other players inventories.
|
||||
smod.invsee.modify:
|
||||
default: op
|
||||
description: Allows the player to view and modify other players inventories.
|
||||
children:
|
||||
- smod.invsee
|
||||
smod.invsee.preventmodify:
|
||||
default: op
|
||||
description: When giving this permission to a player, prevents their inventory from being modified.
|
||||
smod.enderchestsee:
|
||||
default: op
|
||||
description: Allows the player to view other players ender chests.
|
||||
smod.enderchestsee.modify:
|
||||
default: op
|
||||
description: Allows the player to view and modify other players ender chests.
|
||||
children:
|
||||
- smod.enderchestsee
|
||||
smod.preventmute:
|
||||
default: op
|
||||
description: Prevents the player from being muted (if online)
|
||||
smod.preventkick:
|
||||
default: op
|
||||
description: Prevents the player from being muted (if online)
|
||||
smod.preventban:
|
||||
default: op
|
||||
description: Prevents the player from being muted (if online)
|
||||
smod.vanish:
|
||||
default: op
|
||||
description: Allows the player to use /vanish
|
||||
smod.vanish.see:
|
||||
default: op
|
||||
description: Allows the player to see vanished players
|
||||
smod.socialspy:
|
||||
default: op
|
||||
description: Allows the player to enable SocialSpy
|
||||
Reference in New Issue
Block a user