1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-28 05:54:16 +02:00

Rework save format and punishment manager

- Punishments are now saved as JSON in files named after their targets
- Each punishment type now has its own Java class
- Each file contains a list of JSON objects that is updated every time something changes (e.g. player muted, banned or unbanned)
- Punishments have a unique ID now; if something changes, the new version is added to the list and overwrites the old version
- 'Undo' has been renamed to 'cancel'
- You can no longer mute or ban players if they are already muted or banned
This commit is contained in:
Shy
2026-04-08 16:12:01 +02:00
parent fecd21bf19
commit 823093be35
26 changed files with 795 additions and 509 deletions
@@ -5,7 +5,10 @@ import de.shiewk.smoderation.paper.command.*;
import de.shiewk.smoderation.paper.input.ChatInput; import de.shiewk.smoderation.paper.input.ChatInput;
import de.shiewk.smoderation.paper.input.ChatInputListener; import de.shiewk.smoderation.paper.input.ChatInputListener;
import de.shiewk.smoderation.paper.listener.*; import de.shiewk.smoderation.paper.listener.*;
import de.shiewk.smoderation.paper.storage.PunishmentContainer; import de.shiewk.smoderation.paper.punishments.Ban;
import de.shiewk.smoderation.paper.punishments.Kick;
import de.shiewk.smoderation.paper.punishments.Mute;
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.translation.TranslatorManager; import de.shiewk.smoderation.paper.translation.TranslatorManager;
import de.shiewk.smoderation.paper.util.SchedulerUtil; import de.shiewk.smoderation.paper.util.SchedulerUtil;
import io.papermc.paper.command.brigadier.Commands; import io.papermc.paper.command.brigadier.Commands;
@@ -24,7 +27,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
@@ -44,10 +46,8 @@ public final class SModerationPaper extends JavaPlugin {
public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY; public static final TextColor INACTIVE_COLOR = NamedTextColor.GRAY;
public static final Gson gson = new Gson(); public static final Gson gson = new Gson();
public static final PunishmentContainer container = new PunishmentContainer();
public static ComponentLogger LOGGER = null; public static ComponentLogger LOGGER = null;
public static SModerationPaper PLUGIN = null; public static SModerationPaper PLUGIN = null;
public static File SAVE_FILE = null;
private static SkinTextureProvider textureProvider = null; private static SkinTextureProvider textureProvider = null;
private final TranslatorManager translatorManager = new TranslatorManager( private final TranslatorManager translatorManager = new TranslatorManager(
@@ -60,6 +60,8 @@ public final class SModerationPaper extends JavaPlugin {
} }
); );
private PunishmentManager punishmentManager;
public static FileConfiguration config() { public static FileConfiguration config() {
return PLUGIN.getConfig(); return PLUGIN.getConfig();
} }
@@ -67,11 +69,16 @@ public final class SModerationPaper extends JavaPlugin {
@Override @Override
public void onLoad() { public void onLoad() {
LOGGER = getComponentLogger(); LOGGER = getComponentLogger();
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no");
PLUGIN = this; PLUGIN = this;
SAVE_FILE = new File(this.getDataFolder().getAbsolutePath() + "/container.gz");
LOGGER.info("Loading translations"); LOGGER.info("Loading translations");
translatorManager.load(); translatorManager.load();
updateConfig(); updateConfig();
this.punishmentManager = new PunishmentManager(getDataPath().resolve("punishments.v2"));
this.punishmentManager.registerType("mute", new Mute.Factory());
this.punishmentManager.registerType("ban", new Ban.Factory());
this.punishmentManager.registerType("kick", new Kick.Factory());
} }
public boolean isFeatureEnabled(String feature){ public boolean isFeatureEnabled(String feature){
@@ -80,9 +87,7 @@ public final class SModerationPaper extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
LOGGER.info("Folia: {}", SchedulerUtil.isFolia ? "yes" : "no"); if (isFeatureEnabled("punishments")) listen(new PunishmentListener(punishmentManager));
if (isFeatureEnabled("punishments")) listen(new PunishmentListener());
if (isFeatureEnabled("invsee")) listen(new InvSeeListener()); if (isFeatureEnabled("invsee")) listen(new InvSeeListener());
if (isFeatureEnabled("enderchestsee")) listen(new EnderchestSeeListener()); if (isFeatureEnabled("enderchestsee")) listen(new EnderchestSeeListener());
if (isFeatureEnabled("socialspy")) listen(new SocialSpyListener()); if (isFeatureEnabled("socialspy")) listen(new SocialSpyListener());
@@ -95,15 +100,15 @@ public final class SModerationPaper extends JavaPlugin {
Commands commands = event.registrar(); Commands commands = event.registrar();
if (isFeatureEnabled("punishments")){ if (isFeatureEnabled("punishments")){
registerCommand(commands, new KickCommand()); registerCommand(commands, new KickCommand(punishmentManager));
registerCommand(commands, new ModLogsCommand()); registerCommand(commands, new ModLogsCommand(punishmentManager));
registerCommand(commands, new UnmuteCommand()); registerCommand(commands, new UnmuteCommand(punishmentManager));
registerCommand(commands, new UnbanCommand()); registerCommand(commands, new UnbanCommand(punishmentManager));
registerCommand(commands, new MuteCommand()); registerCommand(commands, new MuteCommand(punishmentManager));
registerCommand(commands, new BanCommand()); registerCommand(commands, new BanCommand(punishmentManager));
if (isFeatureEnabled("smodmenu")){ if (isFeatureEnabled("smodmenu")){
registerCommand(commands, new SModCommand()); registerCommand(commands, new SModCommand(punishmentManager));
} }
} }
@@ -122,8 +127,6 @@ public final class SModerationPaper extends JavaPlugin {
} }
SchedulerUtil.scheduleGlobalRepeating(PLUGIN, ChatInput::tickAll, 1, 1); SchedulerUtil.scheduleGlobalRepeating(PLUGIN, ChatInput::tickAll, 1, 1);
container.load(SAVE_FILE);
} }
private void listen(Listener listener) { private void listen(Listener listener) {
@@ -140,7 +143,6 @@ public final class SModerationPaper extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
SModerationPaper.container.save(SModerationPaper.SAVE_FILE);
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
// in case players are still vanished when the server shuts down // in case players are still vanished when the server shuts down
if (isVanished(player)){ if (isVanished(player)){
@@ -8,7 +8,9 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
import de.shiewk.smoderation.paper.SModerationPaper; import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.command.argument.DurationArgument; import de.shiewk.smoderation.paper.command.argument.DurationArgument;
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument; import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
import de.shiewk.smoderation.paper.punishments.Ban;
import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.util.CommandUtil; import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -24,6 +26,12 @@ import static io.papermc.paper.command.brigadier.Commands.literal;
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API @SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
public final class BanCommand implements CommandProvider { public final class BanCommand implements CommandProvider {
private final PunishmentManager punishmentManager;
public BanCommand(PunishmentManager punishmentManager) {
this.punishmentManager = punishmentManager;
}
@Override @Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() { public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("ban") return literal("ban")
@@ -46,7 +54,7 @@ public final class BanCommand implements CommandProvider {
UUID sender = CommandUtil.getSenderUUID(context.getSource()); UUID sender = CommandUtil.getSenderUUID(context.getSource());
UUID target = context.getArgument("player", UUID.class); UUID target = context.getArgument("player", UUID.class);
long duration = context.getArgument("duration", Long.class); long duration = context.getArgument("duration", Long.class);
executeBan(sender, target, duration, Punishment.DEFAULT_REASON); executeBan(punishmentManager, sender, target, duration, Punishment.DEFAULT_REASON);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
@@ -55,17 +63,17 @@ public final class BanCommand implements CommandProvider {
UUID target = context.getArgument("player", UUID.class); UUID target = context.getArgument("player", UUID.class);
long duration = context.getArgument("duration", Long.class); long duration = context.getArgument("duration", Long.class);
String reason = StringArgumentType.getString(context, "reason"); String reason = StringArgumentType.getString(context, "reason");
executeBan(sender, target, duration, reason); executeBan(punishmentManager, sender, target, duration, reason);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
public static void executeBan(UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException { public static void executeBan(PunishmentManager manager, UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
Player targetPlayer = Bukkit.getPlayer(target); Player targetPlayer = Bukkit.getPlayer(target);
if (duration == 0){ if (duration == 0){
if (targetPlayer == null){ if (targetPlayer == null){
CommandUtil.errorTranslatable("smod.command.ban.fail.tooShort"); CommandUtil.errorTranslatable("smod.command.ban.fail.tooShort");
} else { } else {
KickCommand.executeKick(sender, targetPlayer, reason); KickCommand.executeKick(manager, sender, targetPlayer, reason);
} }
return; return;
} }
@@ -75,14 +83,18 @@ public final class BanCommand implements CommandProvider {
if (targetPlayer != null && targetPlayer.hasPermission("smod.preventban")){ if (targetPlayer != null && targetPlayer.hasPermission("smod.preventban")){
CommandUtil.errorTranslatable("smod.command.ban.fail.protect"); CommandUtil.errorTranslatable("smod.command.ban.fail.protect");
} else { } else {
final Punishment punishment = Punishment.ban( if (!manager.byTargetUUID(target, p -> p instanceof Ban ban && ban.isActive()).isEmpty()) {
CommandUtil.errorTranslatable("smod.command.ban.fail.alreadyBanned");
}
Punishment punishment = new Ban(
Punishment.generateUUID(),
System.currentTimeMillis(), System.currentTimeMillis(),
System.currentTimeMillis() + duration,
sender, sender,
target, target,
reason reason,
duration
); );
Punishment.issue(punishment, SModerationPaper.container); manager.tryIssue(punishment);
} }
} }
} }
@@ -6,7 +6,9 @@ import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import de.shiewk.smoderation.paper.SModerationPaper; import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.punishments.Kick;
import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.util.CommandUtil; import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes; import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
@@ -22,6 +24,12 @@ import static io.papermc.paper.command.brigadier.Commands.literal;
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API @SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
public final class KickCommand implements CommandProvider { public final class KickCommand implements CommandProvider {
private final PunishmentManager punishmentManager;
public KickCommand(PunishmentManager punishmentManager) {
this.punishmentManager = punishmentManager;
}
@Override @Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() { public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("kick") return literal("kick")
@@ -39,7 +47,7 @@ public final class KickCommand implements CommandProvider {
UUID sender = CommandUtil.getSenderUUID(context.getSource()); UUID sender = CommandUtil.getSenderUUID(context.getSource());
Player target = CommandUtil.getPlayerSingle(context, "player"); Player target = CommandUtil.getPlayerSingle(context, "player");
String reason = StringArgumentType.getString(context, "reason"); String reason = StringArgumentType.getString(context, "reason");
executeKick(sender, target, reason); executeKick(punishmentManager, sender, target, reason);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
@@ -49,24 +57,25 @@ public final class KickCommand implements CommandProvider {
} }
UUID sender = CommandUtil.getSenderUUID(context.getSource()); UUID sender = CommandUtil.getSenderUUID(context.getSource());
Player target = CommandUtil.getPlayerSingle(context, "player"); Player target = CommandUtil.getPlayerSingle(context, "player");
executeKick(sender, target, Punishment.DEFAULT_REASON); executeKick(punishmentManager, sender, target, Punishment.DEFAULT_REASON);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
public static void executeKick(UUID sender, Player target, String reason) throws CommandSyntaxException { public static void executeKick(PunishmentManager manager, UUID sender, Player target, String reason) throws CommandSyntaxException {
UUID targetId = target.getUniqueId(); UUID targetId = target.getUniqueId();
if (sender.equals(targetId)) { if (sender.equals(targetId)) {
CommandUtil.errorTranslatable("smod.command.kick.fail.self"); CommandUtil.errorTranslatable("smod.command.kick.fail.self");
} else if (target.hasPermission("smod.preventkick")){ } else if (target.hasPermission("smod.preventkick")){
CommandUtil.errorTranslatable("smod.command.kick.fail.protect"); CommandUtil.errorTranslatable("smod.command.kick.fail.protect");
} }
final Punishment punishment = Punishment.kick( Punishment punishment = new Kick(
Punishment.generateUUID(),
System.currentTimeMillis(), System.currentTimeMillis(),
sender, sender,
targetId, targetId,
reason reason
); );
Punishment.issue(punishment, SModerationPaper.container); manager.tryIssue(punishment);
} }
@Override @Override
@@ -5,6 +5,8 @@ import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument; import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
import de.shiewk.smoderation.paper.util.CommandUtil; import de.shiewk.smoderation.paper.util.CommandUtil;
import de.shiewk.smoderation.paper.util.PlayerUtil; import de.shiewk.smoderation.paper.util.PlayerUtil;
import de.shiewk.smoderation.paper.util.TimeUtil; import de.shiewk.smoderation.paper.util.TimeUtil;
@@ -15,7 +17,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static de.shiewk.smoderation.paper.SModerationPaper.container;
import static io.papermc.paper.command.brigadier.Commands.argument; import static io.papermc.paper.command.brigadier.Commands.argument;
import static io.papermc.paper.command.brigadier.Commands.literal; import static io.papermc.paper.command.brigadier.Commands.literal;
import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.text;
@@ -24,6 +25,12 @@ import static net.kyori.adventure.text.Component.translatable;
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API @SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
public final class ModLogsCommand implements CommandProvider { public final class ModLogsCommand implements CommandProvider {
private final PunishmentManager punishmentManager;
public ModLogsCommand(PunishmentManager punishmentManager) {
this.punishmentManager = punishmentManager;
}
@Override @Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() { public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("modlogs") return literal("modlogs")
@@ -39,14 +46,16 @@ public final class ModLogsCommand implements CommandProvider {
UUID uuid = context.getArgument("player", UUID.class); UUID uuid = context.getArgument("player", UUID.class);
String name = PlayerUtil.offlinePlayerName(uuid); String name = PlayerUtil.offlinePlayerName(uuid);
sender.sendMessage(translatable("smod.command.modlogs.heading", text(name), text(uuid.toString()))); sender.sendMessage(translatable("smod.command.modlogs.heading", text(name), text(uuid.toString())));
final List<Punishment> punishments = container.findAll(p -> p.to.equals(uuid) && p.isActive()); List<Punishment> punishments = punishmentManager.byTargetUUID(uuid);
for (Punishment punishment : punishments) { for (Punishment punishment : punishments) {
sender.sendMessage(translatable("smod.command.modlogs." + punishment.type.name().toLowerCase(), if (punishment instanceof TimedPunishment timed && timed.isActive()){
TimeUtil.calendarTimestamp(punishment.until), sender.sendMessage(translatable("smod.command.modlogs." + punishment.getType(),
TimeUtil.formatTimeLong(punishment.until - System.currentTimeMillis()), TimeUtil.calendarTimestamp(timed.getExpiry()),
text(punishment.reason) TimeUtil.formatTimeLong(timed.getExpiry() - System.currentTimeMillis()),
text(punishment.getReason())
)); ));
} }
}
if (punishments.isEmpty()){ if (punishments.isEmpty()){
sender.sendMessage(translatable("smod.command.modlogs.none")); sender.sendMessage(translatable("smod.command.modlogs.none"));
} }
@@ -8,7 +8,9 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
import de.shiewk.smoderation.paper.SModerationPaper; import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.command.argument.DurationArgument; import de.shiewk.smoderation.paper.command.argument.DurationArgument;
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument; import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
import de.shiewk.smoderation.paper.punishments.Mute;
import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.util.CommandUtil; import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@@ -24,6 +26,12 @@ import static io.papermc.paper.command.brigadier.Commands.literal;
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API @SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
public final class MuteCommand implements CommandProvider { public final class MuteCommand implements CommandProvider {
private final PunishmentManager punishmentManager;
public MuteCommand(PunishmentManager punishmentManager) {
this.punishmentManager = punishmentManager;
}
@Override @Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() { public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("mute") return literal("mute")
@@ -46,7 +54,7 @@ public final class MuteCommand implements CommandProvider {
UUID sender = CommandUtil.getSenderUUID(context.getSource()); UUID sender = CommandUtil.getSenderUUID(context.getSource());
UUID target = context.getArgument("player", UUID.class); UUID target = context.getArgument("player", UUID.class);
long duration = context.getArgument("duration", Long.class); long duration = context.getArgument("duration", Long.class);
executeMute(sender, target, duration, Punishment.DEFAULT_REASON); executeMute(punishmentManager, sender, target, duration, Punishment.DEFAULT_REASON);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
@@ -55,11 +63,11 @@ public final class MuteCommand implements CommandProvider {
UUID target = context.getArgument("player", UUID.class); UUID target = context.getArgument("player", UUID.class);
long duration = context.getArgument("duration", Long.class); long duration = context.getArgument("duration", Long.class);
String reason = StringArgumentType.getString(context, "reason"); String reason = StringArgumentType.getString(context, "reason");
executeMute(sender, target, duration, reason); executeMute(punishmentManager, sender, target, duration, reason);
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
public static void executeMute(UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException { public static void executeMute(PunishmentManager manager, UUID sender, UUID target, long duration, String reason) throws CommandSyntaxException {
if (duration == 0){ if (duration == 0){
CommandUtil.errorTranslatable("smod.command.mute.fail.tooShort"); CommandUtil.errorTranslatable("smod.command.mute.fail.tooShort");
} }
@@ -70,14 +78,18 @@ public final class MuteCommand implements CommandProvider {
if (targetPlayer != null && targetPlayer.hasPermission("smod.preventmute")){ if (targetPlayer != null && targetPlayer.hasPermission("smod.preventmute")){
CommandUtil.errorTranslatable("smod.command.mute.fail.protect"); CommandUtil.errorTranslatable("smod.command.mute.fail.protect");
} else { } else {
final Punishment punishment = Punishment.mute( if (!manager.byTargetUUID(target, p -> p instanceof Mute mute && mute.isActive()).isEmpty()) {
CommandUtil.errorTranslatable("smod.command.mute.fail.alreadyMuted");
}
Punishment punishment = new Mute(
Punishment.generateUUID(),
System.currentTimeMillis(), System.currentTimeMillis(),
System.currentTimeMillis() + duration,
sender, sender,
target, target,
reason reason,
duration
); );
Punishment.issue(punishment, SModerationPaper.container); manager.tryIssue(punishment);
} }
} }
} }
@@ -4,8 +4,8 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.inventory.SModMenu; import de.shiewk.smoderation.paper.inventory.SModMenu;
import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.util.CommandUtil; import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -18,6 +18,12 @@ import static io.papermc.paper.command.brigadier.Commands.literal;
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API @SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
public final class SModCommand implements CommandProvider { public final class SModCommand implements CommandProvider {
private final PunishmentManager punishmentManager;
public SModCommand(PunishmentManager punishmentManager) {
this.punishmentManager = punishmentManager;
}
@Override @Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() { public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("smod") return literal("smod")
@@ -28,7 +34,7 @@ public final class SModCommand implements CommandProvider {
private int openMenu(CommandContext<CommandSourceStack> context) throws CommandSyntaxException { private int openMenu(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
Player player = CommandUtil.getExecutingPlayer(context.getSource()); Player player = CommandUtil.getExecutingPlayer(context.getSource());
new SModMenu(player, SModerationPaper.container).open(); new SModMenu(player, punishmentManager).open();
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
@@ -4,10 +4,11 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument; import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
import de.shiewk.smoderation.paper.punishments.Ban;
import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentType; import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
import de.shiewk.smoderation.paper.util.CommandUtil; import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
@@ -21,6 +22,12 @@ import static io.papermc.paper.command.brigadier.Commands.literal;
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API @SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
public final class UnbanCommand implements CommandProvider { public final class UnbanCommand implements CommandProvider {
private final PunishmentManager punishmentManager;
public UnbanCommand(PunishmentManager punishmentManager) {
this.punishmentManager = punishmentManager;
}
@Override @Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() { public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("unban") return literal("unban")
@@ -34,13 +41,14 @@ public final class UnbanCommand implements CommandProvider {
private int unbanPlayer(CommandContext<CommandSourceStack> context) throws CommandSyntaxException { private int unbanPlayer(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
UUID senderUUID = CommandUtil.getSenderUUID(context.getSource()); UUID senderUUID = CommandUtil.getSenderUUID(context.getSource());
UUID target = context.getArgument("player", UUID.class); UUID target = context.getArgument("player", UUID.class);
final Punishment punishment = SModerationPaper.container.find( final List<Punishment> punishments = punishmentManager.byTargetUUID(
p -> p.to.equals(target) && p.isActive() && p.type == PunishmentType.BAN target,
p -> p instanceof Ban ban && ban.isActive()
); );
if (punishment != null) { for (Punishment punishment : punishments) {
punishment.undo(senderUUID); punishmentManager.cancel((TimedPunishment) punishment, senderUUID);
punishment.broadcastUndo(SModerationPaper.container); }
} else { if (punishments.isEmpty()) {
CommandUtil.errorTranslatable("smod.command.unban.fail.notBanned"); CommandUtil.errorTranslatable("smod.command.unban.fail.notBanned");
} }
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
@@ -4,10 +4,11 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument; import de.shiewk.smoderation.paper.command.argument.PlayerUUIDArgument;
import de.shiewk.smoderation.paper.punishments.Mute;
import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentType; import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.punishments.TimedPunishment;
import de.shiewk.smoderation.paper.util.CommandUtil; import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
@@ -21,6 +22,12 @@ import static io.papermc.paper.command.brigadier.Commands.literal;
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API @SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
public final class UnmuteCommand implements CommandProvider { public final class UnmuteCommand implements CommandProvider {
private final PunishmentManager punishmentManager;
public UnmuteCommand(PunishmentManager punishmentManager) {
this.punishmentManager = punishmentManager;
}
@Override @Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() { public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("unmute") return literal("unmute")
@@ -34,14 +41,15 @@ public final class UnmuteCommand implements CommandProvider {
private int unmutePlayer(CommandContext<CommandSourceStack> context) throws CommandSyntaxException { private int unmutePlayer(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
UUID senderUUID = CommandUtil.getSenderUUID(context.getSource()); UUID senderUUID = CommandUtil.getSenderUUID(context.getSource());
UUID target = context.getArgument("player", UUID.class); UUID target = context.getArgument("player", UUID.class);
final Punishment punishment = SModerationPaper.container.find( final List<Punishment> punishments = punishmentManager.byTargetUUID(
p -> p.to.equals(target) && p.isActive() && p.type == PunishmentType.MUTE target,
p -> p instanceof Mute mute && mute.isActive()
); );
if (punishment != null) { for (Punishment punishment : punishments) {
punishment.undo(senderUUID); punishmentManager.cancel((TimedPunishment) punishment, senderUUID);
punishment.broadcastUndo(SModerationPaper.container); }
} else { if (punishments.isEmpty()) {
CommandUtil.errorTranslatable("smod.command.unmute.fail.notMuted"); CommandUtil.errorTranslatable("smod.command.unmute.fail.notBanned");
} }
return Command.SINGLE_SUCCESS; return Command.SINGLE_SUCCESS;
} }
@@ -4,8 +4,8 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.event.VanishToggleEvent; import de.shiewk.smoderation.paper.event.VanishToggleEvent;
import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.util.CommandUtil; import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack; import io.papermc.paper.command.brigadier.CommandSourceStack;
import io.papermc.paper.command.brigadier.argument.ArgumentTypes; import io.papermc.paper.command.brigadier.argument.ArgumentTypes;
@@ -92,7 +92,7 @@ public final class VanishCommand implements CommandProvider {
} }
if (newStatus){ if (newStatus){
vanishedPlayers.add(player); vanishedPlayers.add(player);
for (CommandSender sender : SModerationPaper.container.collectBroadcastTargets()) { for (CommandSender sender : Punishment.getBroadcastTargets()) {
sender.sendMessage(translatable("smod.command.vanish.broadcast.on", player.teamDisplayName())); sender.sendMessage(translatable("smod.command.vanish.broadcast.on", player.teamDisplayName()));
} }
player.sendMessage(translatable("smod.command.vanish.toggle.on")); player.sendMessage(translatable("smod.command.vanish.toggle.on"));
@@ -104,7 +104,7 @@ public final class VanishCommand implements CommandProvider {
} }
} else { } else {
vanishedPlayers.remove(player); vanishedPlayers.remove(player);
for (CommandSender sender : container.collectBroadcastTargets()) { for (CommandSender sender : Punishment.getBroadcastTargets()) {
sender.sendMessage(translatable("smod.command.vanish.broadcast.off", player.teamDisplayName())); sender.sendMessage(translatable("smod.command.vanish.broadcast.off", player.teamDisplayName()));
} }
player.sendMessage(translatable("smod.command.vanish.toggle.off")); player.sendMessage(translatable("smod.command.vanish.toggle.off"));
@@ -1,7 +1,7 @@
package de.shiewk.smoderation.paper.event; package de.shiewk.smoderation.paper.event;
import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.storage.PunishmentContainer; import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@@ -11,20 +11,20 @@ public class PunishmentIssueEvent extends Event implements Cancellable {
private static final HandlerList handlerList = new HandlerList(); private static final HandlerList handlerList = new HandlerList();
private final Punishment punishment; private final Punishment punishment;
private final PunishmentContainer container; private final PunishmentManager manager;
private boolean cancelled; private boolean cancelled;
public PunishmentIssueEvent(Punishment punishment, PunishmentContainer container) { public PunishmentIssueEvent(Punishment punishment, PunishmentManager manager) {
this.punishment = punishment; this.punishment = punishment;
this.container = container; this.manager = manager;
} }
public Punishment getPunishment() { public Punishment getPunishment() {
return punishment; return punishment;
} }
public PunishmentContainer getContainer() { public PunishmentManager getPunishmentManager() {
return container; return manager;
} }
@Override @Override
@@ -5,8 +5,8 @@ import com.destroystokyo.paper.profile.ProfileProperty;
import de.shiewk.smoderation.paper.SkinTextureProvider; import de.shiewk.smoderation.paper.SkinTextureProvider;
import de.shiewk.smoderation.paper.input.ChatInput; import de.shiewk.smoderation.paper.input.ChatInput;
import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentType; import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.storage.PunishmentContainer; import de.shiewk.smoderation.paper.punishments.TimedPunishment;
import de.shiewk.smoderation.paper.util.PlayerUtil; import de.shiewk.smoderation.paper.util.PlayerUtil;
import de.shiewk.smoderation.paper.util.SchedulerUtil; import de.shiewk.smoderation.paper.util.SchedulerUtil;
import de.shiewk.smoderation.paper.util.TimeUtil; import de.shiewk.smoderation.paper.util.TimeUtil;
@@ -27,8 +27,10 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Predicate; import java.util.function.Predicate;
@@ -41,8 +43,8 @@ import static net.kyori.adventure.text.Component.*;
public class SModMenu extends PageableCustomInventory { public class SModMenu extends PageableCustomInventory {
public enum Filter { public enum Filter {
ACTIVE(translatable("smod.menu.filter.active"), Punishment::isActive), ACTIVE(translatable("smod.menu.filter.active"), p -> p instanceof TimedPunishment timed && timed.isActive()),
OLD(translatable("smod.menu.filter.expired"), p -> !p.isActive()), OLD(translatable("smod.menu.filter.expired"), p -> !(p instanceof TimedPunishment timed && timed.isActive())),
ALL(translatable("smod.menu.filter.all"), p -> true); ALL(translatable("smod.menu.filter.all"), p -> true);
public static final Material ICON = Material.HOPPER; public static final Material ICON = Material.HOPPER;
@@ -56,10 +58,10 @@ public class SModMenu extends PageableCustomInventory {
} }
public enum Sort { public enum Sort {
EXPIRY(translatable("smod.menu.sort.expiry"), Comparator.comparingLong(p -> p.until)), EXPIRY(translatable("smod.menu.sort.expiry"), Comparator.comparingLong(p -> p instanceof TimedPunishment timed ? p.getTimestamp() + timed.getDuration() : p.getTimestamp())),
TIME(translatable("smod.menu.sort.time"), Comparator.comparingLong(p -> p.time)), TIME(translatable("smod.menu.sort.time"), Comparator.comparingLong(Punishment::getTimestamp)),
PLAYER_NAME(translatable("smod.menu.sort.playerName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.to), PlayerUtil.offlinePlayerName(p2.to))), PLAYER_NAME(translatable("smod.menu.sort.playerName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.getTargetID()), PlayerUtil.offlinePlayerName(p2.getTargetID()))),
MODERATOR_NAME(translatable("smod.menu.sort.moderatorName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.by), PlayerUtil.offlinePlayerName(p2.by))); MODERATOR_NAME(translatable("smod.menu.sort.moderatorName"), (p1, p2) -> String.CASE_INSENSITIVE_ORDER.compare(PlayerUtil.offlinePlayerName(p1.getIssuerID()), PlayerUtil.offlinePlayerName(p2.getIssuerID())));
public static final Material ICON = Material.COMPARATOR; public static final Material ICON = Material.COMPARATOR;
@@ -74,7 +76,7 @@ public class SModMenu extends PageableCustomInventory {
private final Inventory inventory; private final Inventory inventory;
private final Player player; private final Player player;
private final PunishmentContainer container; private final PunishmentManager punishmentManager;
private final Int2ObjectArrayMap<Punishment> slotMap = new Int2ObjectArrayMap<>(45); private final Int2ObjectArrayMap<Punishment> slotMap = new Int2ObjectArrayMap<>(45);
private List<Punishment> punishments; private List<Punishment> punishments;
private int sort = 0; private int sort = 0;
@@ -83,10 +85,10 @@ public class SModMenu extends PageableCustomInventory {
private int rfId = 0; private int rfId = 0;
private String searchQuery = null; private String searchQuery = null;
public SModMenu(Player player, PunishmentContainer container) { public SModMenu(Player player, PunishmentManager punishmentManager) {
super(45, 53); super(45, 53);
this.player = player; this.player = player;
this.container = container; this.punishmentManager = punishmentManager;
this.inventory = Bukkit.createInventory(this, 54, translatable("smod.menu")); this.inventory = Bukkit.createInventory(this, 54, translatable("smod.menu"));
reload(); reload();
} }
@@ -99,16 +101,21 @@ public class SModMenu extends PageableCustomInventory {
return Filter.values()[filter]; return Filter.values()[filter];
} }
public PunishmentType getType(){ public String getType(){
return type == -1 ? null : PunishmentType.values()[type]; return type == -1 ? null : punishmentManager.getRegisteredTypes().get(type);
} }
private void reload() { private void reload() {
this.punishments = container.copy().stream() try {
this.punishments = this.punishmentManager.getAll()
.stream()
.filter(getFilter().filter) .filter(getFilter().filter)
.filter(p -> getType() == null || p.type == getType()) .filter(p -> getType() == null || Objects.equals(p.getType(), getType()))
.filter(p -> p.matchesSearchQuery(searchQuery)) .filter(p -> p.matchesSearchQuery(searchQuery))
.sorted(getSort().comparator).toList(); .sorted(getSort().comparator).toList();
} catch (IOException e) {
this.punishments = List.of();
}
} }
public void promptSearchQuery(){ public void promptSearchQuery(){
@@ -169,12 +176,12 @@ public class SModMenu extends PageableCustomInventory {
player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f); player.playSound(player, Sound.UI_BUTTON_CLICK, 1f, backwards ? 0.8f : 2f);
if (backwards){ if (backwards){
if (type <= -1){ if (type <= -1){
type = PunishmentType.values().length-1; type = punishmentManager.getRegisteredTypes().size()-1;
} else { } else {
type--; type--;
} }
} else { } else {
if (type >= PunishmentType.values().length-1){ if (type >= punishmentManager.getRegisteredTypes().size()-1){
type = -1; type = -1;
} else { } else {
type++; type++;
@@ -209,19 +216,19 @@ public class SModMenu extends PageableCustomInventory {
} }
private ItemStack createTypeItem(){ private ItemStack createTypeItem(){
final PunishmentType type = getType(); final String type = getType();
final ItemStack stack = new ItemStack(Material.CHEST); final ItemStack stack = new ItemStack(Material.CHEST);
stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.type", (type == null ? translatable("smod.menu.type.all") : type.name))).color(PRIMARY_COLOR)); stack.setData(DataComponentTypes.ITEM_NAME, renderComponent(player, translatable("smod.menu.type", (type == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + type)))).color(PRIMARY_COLOR));
ItemLore.Builder loreBuilder = ItemLore.lore(); ItemLore.Builder loreBuilder = ItemLore.lore();
loreBuilder.addLine(empty()); loreBuilder.addLine(empty());
final Consumer<PunishmentType> addToLore = value -> { final Consumer<String> addToLore = value -> {
final boolean selected = type == value; final boolean selected = Objects.equals(type, value);
Component typeText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value == null ? translatable("smod.menu.type.all") : value.name))); Component typeText = renderComponent(player, applyFormatting(text((selected ? "\u00BB " : ""), selected ? SECONDARY_COLOR : INACTIVE_COLOR).append(value == null ? translatable("smod.menu.type.all") : translatable("smod.punishment.name." + value))));
loreBuilder.addLine(typeText); loreBuilder.addLine(typeText);
}; };
addToLore.accept(null); addToLore.accept(null);
for (PunishmentType value : PunishmentType.values()) { for (String value : punishmentManager.getRegisteredTypes()) {
addToLore.accept(value); addToLore.accept(value);
} }
@@ -282,12 +289,12 @@ public class SModMenu extends PageableCustomInventory {
private CompletableFuture<ItemStack> createPunishmentItem(Punishment punishment){ private CompletableFuture<ItemStack> createPunishmentItem(Punishment punishment){
SkinTextureProvider provider = getTextureProvider(); SkinTextureProvider provider = getTextureProvider();
if (provider != null) { if (provider != null) {
return provider.textureProperty(punishment.to) return provider.textureProperty(punishment.getTargetID())
.thenApply(texture -> { .thenApply(texture -> {
ItemStack stack = new ItemStack(Material.PLAYER_HEAD); ItemStack stack = new ItemStack(Material.PLAYER_HEAD);
stack.editMeta(meta -> { stack.editMeta(meta -> {
if (meta instanceof SkullMeta skullMeta){ if (meta instanceof SkullMeta skullMeta){
PlayerProfile profile = Bukkit.createProfile(punishment.to); PlayerProfile profile = Bukkit.createProfile(punishment.getTargetID());
profile.setProperty(new ProfileProperty( profile.setProperty(new ProfileProperty(
"textures", "textures",
texture texture
@@ -303,9 +310,9 @@ public class SModMenu extends PageableCustomInventory {
stack.editMeta(meta -> { stack.editMeta(meta -> {
if (meta instanceof SkullMeta skullMeta){ if (meta instanceof SkullMeta skullMeta){
try { try {
skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.to)); skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(punishment.getTargetID()));
} catch (NullPointerException e) { } catch (NullPointerException e) {
LOGGER.warn("Player {} has a punishment but was never on this server!", punishment.to); LOGGER.warn("Player {} has a punishment but was never on this server!", punishment.getTargetID());
} }
} }
}); });
@@ -315,16 +322,16 @@ public class SModMenu extends PageableCustomInventory {
} }
private void addPunishmentInfo(Punishment punishment, ItemStack stack) { private void addPunishmentInfo(Punishment punishment, ItemStack stack) {
stack.setData(DataComponentTypes.CUSTOM_NAME, renderComponent(player, applyFormatting(punishment.type.name.color(NamedTextColor.RED).decorate(TextDecoration.BOLD)))); stack.setData(DataComponentTypes.CUSTOM_NAME, renderComponent(player, applyFormatting(translatable("smod.punishment.name." + punishment.getType(), NamedTextColor.RED).decorate(TextDecoration.BOLD))));
ItemLore.Builder lore = ItemLore.lore(); ItemLore.Builder lore = ItemLore.lore();
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.player", text(PlayerUtil.offlinePlayerName(punishment.to)))))); lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.player", text(PlayerUtil.offlinePlayerName(punishment.getTargetID()))))));
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.punishedBy", text(PlayerUtil.offlinePlayerName(punishment.by)))))); lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.punishedBy", text(PlayerUtil.offlinePlayerName(punishment.getIssuerID()))))));
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.timestamp", TimeUtil.calendarTimestamp(punishment.time))))); lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.timestamp", TimeUtil.calendarTimestamp(punishment.getTimestamp())))));
if (punishment.type != PunishmentType.KICK){ if (punishment instanceof TimedPunishment timed){
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", TimeUtil.formatTimeLong(punishment.until - punishment.time))))); lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.duration", TimeUtil.formatTimeLong(timed.getExpiry() - punishment.getTimestamp())))));
long remainingTime = punishment.until - System.currentTimeMillis(); long remainingTime = timed.getExpiry() - System.currentTimeMillis();
if (remainingTime > 0){ if (remainingTime > 0){
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.future", TimeUtil.formatTimeLong(remainingTime))))); lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.expiry.future", TimeUtil.formatTimeLong(remainingTime)))));
} else { } else {
@@ -332,16 +339,18 @@ public class SModMenu extends PageableCustomInventory {
} }
} }
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.reason", text(punishment.reason))))); lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.reason", text(punishment.getReason())))));
if (punishment.wasUndone()){ if (punishment instanceof TimedPunishment timed){
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.undone", text(PlayerUtil.offlinePlayerName(punishment.undoneBy())))))); if (timed.wasCancelled()){
} else if (punishment.isActive()) { lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.cancelled", text(PlayerUtil.offlinePlayerName(timed.getCancelledBy()))))));
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))){ } else if (timed.isActive()) {
if (player.hasPermission("smod.un" + punishment.getType())){
lore.addLine(empty()); lore.addLine(empty());
lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.click", NamedTextColor.GOLD)))); lore.addLine(renderComponent(player, applyFormatting(translatable("smod.menu.info.click", NamedTextColor.GOLD))));
} }
} }
}
stack.setData(DataComponentTypes.LORE, lore); stack.setData(DataComponentTypes.LORE, lore);
} }
@@ -404,12 +413,10 @@ public class SModMenu extends PageableCustomInventory {
cycleSort(event.isRightClick()); cycleSort(event.isRightClick());
} else { } else {
Punishment punishment = slotMap.get(slot); Punishment punishment = slotMap.get(slot);
if (punishment != null){ if (punishment instanceof TimedPunishment timed && timed.isActive()){
if (punishment.isActive()){ if (player.hasPermission("smod.un" + punishment.getType())) {
if ((punishment.type == PunishmentType.BAN && player.hasPermission("smod.unban")) || (punishment.type == PunishmentType.MUTE && player.hasPermission("smod.unmute"))) { new ConfirmationInventory(player, translatable("smod.menu.cancelConfirmation"), () -> {
new ConfirmationInventory(player, translatable("smod.menu.undoConfirmation"), () -> { punishmentManager.cancel(timed, player.getUniqueId());
punishment.undo(player.getUniqueId());
punishment.broadcastUndo(container);
player.playSound(player, Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 2f); player.playSound(player, Sound.BLOCK_NOTE_BLOCK_PLING, 1f, 2f);
this.open(); this.open();
}, this::open).open(); }, this::open).open();
@@ -417,7 +424,6 @@ public class SModMenu extends PageableCustomInventory {
} }
} }
} }
}
@Override @Override
public void open() { public void open() {
@@ -1,11 +1,10 @@
package de.shiewk.smoderation.paper.listener; package de.shiewk.smoderation.paper.listener;
import de.shiewk.smoderation.paper.SModerationPaper; import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.event.PunishmentIssueEvent; import de.shiewk.smoderation.paper.punishments.Ban;
import de.shiewk.smoderation.paper.inventory.CustomInventory; import de.shiewk.smoderation.paper.punishments.Mute;
import de.shiewk.smoderation.paper.punishments.Punishment; import de.shiewk.smoderation.paper.punishments.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentType; import de.shiewk.smoderation.paper.punishments.PunishmentManager;
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
import io.papermc.paper.event.player.AsyncChatEvent; import io.papermc.paper.event.player.AsyncChatEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@@ -14,7 +13,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.world.WorldSaveEvent;
import java.util.List; import java.util.List;
@@ -23,42 +21,35 @@ import static net.kyori.adventure.text.Component.translatable;
public class PunishmentListener implements Listener { public class PunishmentListener implements Listener {
private final PunishmentManager punishmentManager;
public PunishmentListener(PunishmentManager punishmentManager) {
this.punishmentManager = punishmentManager;
}
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onPlayerLogin(AsyncPlayerPreLoginEvent event){ public void onPlayerLogin(AsyncPlayerPreLoginEvent event){
// Have to use AsyncPlayerPreLoginEvent since PlayerLoginEvent is deprecated in newer versions List<Punishment> list = punishmentManager.byTargetUUID(event.getUniqueId(), p -> p instanceof Ban ban && ban.isActive());
// I would use the new PlayerConnectionValidateLoginEvent but there is literally no API available if (!list.isEmpty()) {
// there to get player's UUIDs event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, list.getFirst().infoMessage());
Punishment punishment = SModerationPaper.container.find(p ->
p.type == PunishmentType.BAN
&& p.to.equals(event.getUniqueId())
&& p.isActive());
if (punishment != null){
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, punishment.playerMessage().colorIfAbsent(PRIMARY_COLOR));
} }
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerChat(AsyncChatEvent event){ public void onPlayerChat(AsyncChatEvent event){
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final Punishment punishment = SModerationPaper.container.find(p -> List<Punishment> list = punishmentManager.byTargetUUID(player.getUniqueId(), p -> p instanceof Mute mute && mute.isActive());
p.type == PunishmentType.MUTE if (!list.isEmpty()) {
&& p.to.equals(player.getUniqueId())
&& p.isActive());
if (punishment != null) {
event.setCancelled(true); event.setCancelled(true);
player.sendMessage(punishment.playerMessage().colorIfAbsent(PRIMARY_COLOR)); player.sendMessage(list.getFirst().infoMessage().colorIfAbsent(PRIMARY_COLOR));
} }
} }
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){ public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event){
Player player = event.getPlayer(); Player player = event.getPlayer();
final Punishment mute = SModerationPaper.container.find(p -> List<Punishment> list = punishmentManager.byTargetUUID(player.getUniqueId(), p -> p instanceof Mute mute && mute.isActive());
p.type == PunishmentType.MUTE if (!list.isEmpty()) { // Player is muted
&& p.to.equals(player.getUniqueId())
&& p.isActive());
if (mute != null) { // Player is muted
List<String> forbiddenCommands = SModerationPaper.config().getStringList("muted-forbidden-commands"); List<String> forbiddenCommands = SModerationPaper.config().getStringList("muted-forbidden-commands");
final String message = event.getMessage(); final String message = event.getMessage();
if (forbiddenCommands.stream().anyMatch(str -> if (forbiddenCommands.stream().anyMatch(str ->
@@ -73,29 +64,4 @@ public class PunishmentListener implements Listener {
} }
@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(CustomInventory.renderComponent(player, punishment.playerMessage().colorIfAbsent(PRIMARY_COLOR)));
}
}
}
}
@EventHandler
public void onWorldSave(WorldSaveEvent event){
if (event.getWorld().equals(Bukkit.getServer().getWorlds().getFirst())){
SModerationPaper.container.save(SModerationPaper.SAVE_FILE);
}
}
} }
@@ -0,0 +1,46 @@
package de.shiewk.smoderation.paper.punishments;
import de.shiewk.smoderation.paper.inventory.CustomInventory;
import de.shiewk.smoderation.paper.util.SerializationHelper;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jspecify.annotations.NonNull;
import java.util.UUID;
public class Ban extends TimedPunishment {
public Ban(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration, UUID cancelledBy) {
super(id, "ban", timestamp, issuer, target, reason, duration, cancelledBy);
}
public Ban(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration) {
this(id, timestamp, issuer, target, reason, duration, null);
}
public static class Factory implements PunishmentFactory<Ban> {
@Override
public @NonNull Ban deserialize(SerializationHelper helper) {
return new Ban(
helper.getUUID("id"),
helper.getLong("timestamp"),
helper.getUUID("issuer"),
helper.getUUID("target"),
helper.getString("reason"),
helper.getLong("duration"),
helper.getUUID("cancelledBy", null)
);
}
}
@Override
public void processIssue() {
super.processIssue();
final Player player = Bukkit.getPlayer(getTargetID());
if (player != null) {
player.kick(CustomInventory.renderComponent(player, infoMessage()));
}
}
}
@@ -0,0 +1,40 @@
package de.shiewk.smoderation.paper.punishments;
import de.shiewk.smoderation.paper.inventory.CustomInventory;
import de.shiewk.smoderation.paper.util.SerializationHelper;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.jspecify.annotations.NonNull;
import java.util.UUID;
public class Kick extends Punishment {
public Kick(UUID id, long timestamp, UUID issuer, UUID target, String reason) {
super(id, "kick", timestamp, issuer, target, reason);
}
public static class Factory implements PunishmentFactory<Kick> {
@Override
public @NonNull Kick deserialize(SerializationHelper helper) {
return new Kick(
helper.getUUID("id"),
helper.getLong("timestamp"),
helper.getUUID("issuer"),
helper.getUUID("target"),
helper.getString("reason")
);
}
}
@Override
public void processIssue() {
super.processIssue();
final Player player = Bukkit.getPlayer(getTargetID());
if (player != null) {
player.kick(CustomInventory.renderComponent(player, infoMessage()));
}
}
}
@@ -0,0 +1,34 @@
package de.shiewk.smoderation.paper.punishments;
import de.shiewk.smoderation.paper.util.SerializationHelper;
import org.jspecify.annotations.NonNull;
import java.util.UUID;
public class Mute extends TimedPunishment {
public Mute(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration, UUID cancelledBy) {
super(id, "mute", timestamp, issuer, target, reason, duration, cancelledBy);
}
public Mute(UUID id, long timestamp, UUID issuer, UUID target, String reason, long duration) {
this(id, timestamp, issuer, target, reason, duration, null);
}
public static class Factory implements PunishmentFactory<Mute> {
@Override
public @NonNull Mute deserialize(SerializationHelper helper) {
return new Mute(
helper.getUUID("id"),
helper.getLong("timestamp"),
helper.getUUID("issuer"),
helper.getUUID("target"),
helper.getString("reason"),
helper.getLong("duration"),
helper.getUUID("cancelledBy", null)
);
}
}
}
@@ -1,205 +1,123 @@
package de.shiewk.smoderation.paper.punishments; package de.shiewk.smoderation.paper.punishments;
import de.shiewk.smoderation.paper.event.PunishmentIssueEvent;
import de.shiewk.smoderation.paper.storage.PunishmentContainer;
import de.shiewk.smoderation.paper.util.ByteUtil;
import de.shiewk.smoderation.paper.util.PlayerUtil; import de.shiewk.smoderation.paper.util.PlayerUtil;
import de.shiewk.smoderation.paper.util.TimeUtil; import de.shiewk.smoderation.paper.util.SerializationHelper;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.io.EOFException; import java.util.List;
import java.io.IOException; import java.util.Random;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID; import java.util.UUID;
import static de.shiewk.smoderation.paper.SModerationPaper.*;
import static net.kyori.adventure.text.Component.text; import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable; import static net.kyori.adventure.text.Component.translatable;
public class Punishment { public abstract class Punishment {
public static final String DEFAULT_REASON = "No reason provided."; 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) { protected final UUID id;
this(type, time, until, by, to, reason, null); protected final String type;
} protected final long timestamp;
protected final UUID issuer;
protected final UUID target;
protected final String reason;
private Punishment(PunishmentType type, long time, long until, UUID by, UUID to, String reason, UUID undoneBy) { protected Punishment(UUID id, String type, long timestamp, UUID issuer, UUID target, String reason) {
this.id = id;
this.type = type; this.type = type;
this.time = time; this.timestamp = timestamp;
this.until = until; this.issuer = issuer;
this.by = by; this.target = target;
this.to = to;
this.reason = reason; this.reason = reason;
this.undoneBy = undoneBy;
} }
private static byte[] readStreamInternal(InputStream stream, int len) throws IOException { public UUID getID() {
final byte[] bytes = stream.readNBytes(len); return id;
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 { public String getType() {
PunishmentType type = PunishmentType.values()[ByteUtil.bytesToInt(readStreamInternal(in, 4))]; return type;
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(){ public long getTimestamp() {
return undoneBy != null; return timestamp;
} }
public UUID undoneBy() { public UUID getIssuerID() {
return undoneBy; return issuer;
} }
public void undo(UUID undoneBy){ public UUID getTargetID() {
if (this.undoneBy != null){ return target;
throw new IllegalArgumentException("This punishment was already undone.");
}
this.undoneBy = undoneBy;
} }
public boolean isActive(){ public String getReason() {
return until > System.currentTimeMillis() && !wasUndone(); return reason;
} }
public static Punishment mute(long time, long until, UUID by, UUID to, String reason){ public void addSerializableProperties(SerializationHelper helper){
return new Punishment(PunishmentType.MUTE, time, until, by, to, reason); helper.putUUID("id", id);
helper.putString("type", type);
helper.putLong("timestamp", timestamp);
helper.putUUID("issuer", issuer);
helper.putUUID("target", target);
helper.putString("reason", reason);
} }
public static Punishment ban(long time, long until, UUID by, UUID to, String reason){ public boolean matchesSearchQuery(String query){
return new Punishment(PunishmentType.BAN, time, until, by, to, reason); if (query == null) return true;
query = query.toLowerCase();
return reason.toLowerCase().contains(query)
|| issuer.toString().equalsIgnoreCase(query)
|| target.toString().equalsIgnoreCase(query)
|| PlayerUtil.offlinePlayerName(issuer).toLowerCase().contains(query)
|| PlayerUtil.offlinePlayerName(target).toLowerCase().contains(query);
} }
public static Punishment kick(long time, UUID by, UUID to, String reason){ public Component infoMessage(){
return new Punishment(PunishmentType.KICK, time, time, by, to, reason);
}
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 key = "smod.punishment.undo." + type.name().toLowerCase();
return translatable(key, text(PlayerUtil.offlinePlayerName(to)), text(PlayerUtil.offlinePlayerName(undoneBy)));
}
public void broadcastUndo(PunishmentContainer container){
for (CommandSender sender : container.collectBroadcastTargets()) {
sender.sendMessage(undoMessage().colorIfAbsent(PRIMARY_COLOR));
}
}
@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(){
String key = "smod.punishment.broadcast." + type.name().toLowerCase();
return translatable( return translatable(
key, "smod.punishment.playerMessage." + type,
text(PlayerUtil.offlinePlayerName(to)), text(PlayerUtil.offlinePlayerName(this.issuer)),
text(PlayerUtil.offlinePlayerName(by)),
TimeUtil.formatTimeLong(this.until - this.time),
text(reason) text(reason)
); );
} }
private void broadcastIssue(PunishmentContainer container){ public Component adminMessage(){
for (CommandSender sender : container.collectBroadcastTargets()) {
sender.sendMessage(broadcastMessage().colorIfAbsent(PRIMARY_COLOR));
}
}
private void firstIssue(PunishmentContainer container){
switch (type) {
case MUTE, BAN -> {
final CommandSender sender = PlayerUtil.senderByUUID(to);
if (sender != null) {
sender.sendMessage(playerMessage().colorIfAbsent(PRIMARY_COLOR));
}
}
}
broadcastIssue(container);
}
public Component playerMessage(){
String key = "smod.punishment.playerMessage." + type.name().toLowerCase();
return translatable( return translatable(
key, "smod.punishment.broadcast." + type,
text(PlayerUtil.offlinePlayerName(this.by)), text(PlayerUtil.offlinePlayerName(target)),
text(reason), text(PlayerUtil.offlinePlayerName(issuer)),
TimeUtil.formatTimeLong(this.until - System.currentTimeMillis()) text(reason)
); );
} }
public boolean matchesSearchQuery(String searchQuery) { public void processIssue() {
if (searchQuery == null) return true; CommandSender sender = PlayerUtil.senderByUUID(target);
searchQuery = searchQuery.toLowerCase(); if (sender != null) {
return reason.toLowerCase().contains(searchQuery) sender.sendMessage(infoMessage());
|| by.toString().equalsIgnoreCase(searchQuery) }
|| to.toString().equalsIgnoreCase(searchQuery) for (CommandSender target : getBroadcastTargets()) {
|| getPlayerName().toLowerCase().contains(searchQuery) target.sendMessage(adminMessage());
|| getModeratorName().toLowerCase().contains(searchQuery); }
} }
private String getPlayerName() { public static List<CommandSender> getBroadcastTargets() {
return PlayerUtil.offlinePlayerName(to); ObjectArrayList<CommandSender> senders = new ObjectArrayList<>();
senders.add(Bukkit.getConsoleSender());
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (onlinePlayer.hasPermission("smod.notifications")){
senders.add(onlinePlayer);
}
}
return List.copyOf(senders);
} }
private String getModeratorName() { public static UUID generateUUID() {
return PlayerUtil.offlinePlayerName(by); Random random = new Random();
return new UUID(System.currentTimeMillis(), random.nextLong());
} }
} }
@@ -0,0 +1,10 @@
package de.shiewk.smoderation.paper.punishments;
import de.shiewk.smoderation.paper.util.SerializationHelper;
import org.jetbrains.annotations.NotNull;
public interface PunishmentFactory<T extends Punishment> {
@NotNull T deserialize(SerializationHelper helper);
}
@@ -0,0 +1,168 @@
package de.shiewk.smoderation.paper.punishments;
import com.google.gson.JsonObject;
import com.google.gson.Strictness;
import com.google.gson.stream.JsonReader;
import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.event.PunishmentIssueEvent;
import de.shiewk.smoderation.paper.util.PlayerUtil;
import de.shiewk.smoderation.paper.util.SerializationHelper;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.List;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static de.shiewk.smoderation.paper.SModerationPaper.LOGGER;
public final class PunishmentManager {
private static final Logger log = LoggerFactory.getLogger(PunishmentManager.class);
private final Object2ObjectArrayMap<String, PunishmentFactory<?>> typeRegistry = new Object2ObjectArrayMap<>(1);
private final Object ioLock = new Object();
private final Path dataDir;
public PunishmentManager(Path dataDir) {
this.dataDir = dataDir;
}
private Path getTargetFile(UUID targetUUID){
return dataDir.resolve(targetUUID.toString().replace("-", ""));
}
public boolean tryIssue(Punishment punishment) {
try {
PunishmentIssueEvent event = new PunishmentIssueEvent(punishment, this);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()){
this.appendToSave(punishment);
punishment.processIssue();
return true;
}
return false;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public List<Punishment> byTargetUUID(UUID target) {
synchronized (ioLock) {
Path file = getTargetFile(target);
if (!Files.exists(file)) {
return List.of();
}
try (
BufferedReader reader = Files.newBufferedReader(file);
JsonReader json = new JsonReader(reader)
) {
json.setStrictness(Strictness.LENIENT);
Object2ObjectArrayMap<UUID, Punishment> punishments = new Object2ObjectArrayMap<>(0);
while (json.hasNext()){
JsonObject obj = SModerationPaper.gson.fromJson(json, JsonObject.class);
try {
SerializationHelper helper = new SerializationHelper(obj);
String type = helper.getString("type");
PunishmentFactory<?> factory = typeRegistry.get(type);
if (factory != null){
Punishment punishment = factory.deserialize(helper);
if (!punishment.getTargetID().equals(target)){
LOGGER.warn("Punishment saved in file for {} has incorrect target UUID {}", target, punishment.getTargetID());
} else {
punishments.put(punishment.getID(), punishment);
}
} else {
LOGGER.warn("Unknown punishment type '{}'! Can not load.", type);
LOGGER.warn("Please check your configuration, or see file {} to remove corrupted data.", file);
LOGGER.warn(obj.toString());
}
} catch (Exception e) {
LOGGER.warn("Could not deserialize punishment!", e);
LOGGER.warn("Please check file {} for corrupted data, or remove the corresponding line.", file);
LOGGER.warn(obj.toString());
}
}
return List.copyOf(punishments.values());
} catch (IOException e){
throw new RuntimeException("Error while reading punishment file " + file, e);
}
}
}
public List<Punishment> byTargetUUID(UUID target, Predicate<Punishment> filter) {
return byTargetUUID(target).stream().filter(filter).toList();
}
public <T extends Punishment> void registerType(String type, PunishmentFactory<T> factory){
if (typeRegistry.containsKey(type)) {
throw new IllegalStateException("Punishment type already registered: " + type);
}
typeRegistry.put(type, factory);
}
public List<String> getRegisteredTypes(){
return List.copyOf(typeRegistry.keySet());
}
private void appendToSave(Punishment punishment) throws IOException {
synchronized (ioLock) {
Path file = getTargetFile(punishment.getTargetID());
if (!Files.exists(file)) {
Files.createDirectories(dataDir);
Files.createFile(file);
}
try (BufferedWriter writer = Files.newBufferedWriter(file, StandardOpenOption.APPEND)) {
JsonObject json = new JsonObject();
punishment.addSerializableProperties(new SerializationHelper(json));
SModerationPaper.gson.toJson(json, writer);
writer.append('\n');
}
}
}
public @NotNull List<Punishment> getAll() throws IOException {
ObjectArrayList<Punishment> punishments = new ObjectArrayList<>();
synchronized (ioLock) {
try (Stream<Path> stream = Files.list(dataDir)) {
stream.forEach(file -> {
try {
String name = file.getFileName().toString();
UUID targetUUID = PlayerUtil.uuidFromString(name);
punishments.addAll(byTargetUUID(targetUUID));
} catch (Exception e) {
log.warn("Could not read punishment file {}", file, e);
}
});
}
}
return List.copyOf(punishments);
}
public List<Punishment> getAll(Predicate<Punishment> filter) throws IOException {
return getAll().stream().filter(filter).toList();
}
public void cancel(TimedPunishment punishment, UUID canceller) {
if (!punishment.isActive()){
throw new IllegalStateException("This punishment is not active");
}
punishment.cancel(canceller);
try {
appendToSave(punishment);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@@ -1,17 +0,0 @@
package de.shiewk.smoderation.paper.punishments;
import net.kyori.adventure.text.Component;
import static net.kyori.adventure.text.Component.translatable;
public enum PunishmentType {
MUTE(translatable("smod.punishment.name.mute")),
KICK(translatable("smod.punishment.name.kick")),
BAN(translatable("smod.punishment.name.ban"));
public final Component name;
PunishmentType(Component name) {
this.name = name;
}
}
@@ -0,0 +1,98 @@
package de.shiewk.smoderation.paper.punishments;
import de.shiewk.smoderation.paper.util.PlayerUtil;
import de.shiewk.smoderation.paper.util.SerializationHelper;
import de.shiewk.smoderation.paper.util.TimeUtil;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import java.util.UUID;
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.Component.translatable;
public abstract class TimedPunishment extends Punishment {
protected final long duration;
protected UUID cancelledBy;
protected TimedPunishment(UUID id, String type, long timestamp, UUID issuer, UUID target, String reason, long duration, UUID cancelledBy) {
super(id, type, timestamp, issuer, target, reason);
this.duration = duration;
this.cancelledBy = cancelledBy;
}
public long getDuration() {
return duration;
}
public UUID getCancelledBy() {
return cancelledBy;
}
public boolean wasCancelled(){
return cancelledBy != null;
}
public boolean isActive(){
return !wasCancelled() && System.currentTimeMillis() < timestamp + duration;
}
@Override
public void addSerializableProperties(SerializationHelper helper) {
super.addSerializableProperties(helper);
helper.putLong("duration", duration);
helper.putUUID("cancelledBy", cancelledBy);
}
@Override
public boolean matchesSearchQuery(String query) {
if (super.matchesSearchQuery(query)) return true;
query = query.toLowerCase();
return cancelledBy.toString().equalsIgnoreCase(query)
|| PlayerUtil.offlinePlayerName(cancelledBy).toLowerCase().contains(query);
}
@Override
public Component infoMessage(){
return translatable(
"smod.punishment.playerMessage." + type,
text(PlayerUtil.offlinePlayerName(this.issuer)),
text(reason),
TimeUtil.formatTimeLong(this.timestamp + this.duration - System.currentTimeMillis())
);
}
@Override
public Component adminMessage(){
return translatable(
"smod.punishment.broadcast." + type,
text(PlayerUtil.offlinePlayerName(target)),
text(PlayerUtil.offlinePlayerName(issuer)),
text(reason),
TimeUtil.formatTimeLong(this.duration)
);
}
public Component cancelMessage(){
return translatable(
"smod.punishment.cancel." + type,
text(PlayerUtil.offlinePlayerName(target)),
text(PlayerUtil.offlinePlayerName(cancelledBy))
);
}
public long getExpiry() {
return getTimestamp() + getDuration();
}
protected void cancel(UUID canceller) {
if (this.cancelledBy != null){
throw new IllegalArgumentException("This punishment was already cancelled.");
}
this.cancelledBy = canceller;
for (CommandSender sender : getBroadcastTargets()) {
sender.sendMessage(cancelMessage());
}
}
}
@@ -1,124 +0,0 @@
package de.shiewk.smoderation.paper.storage;
import de.shiewk.smoderation.paper.SModerationPaper;
import de.shiewk.smoderation.paper.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 : 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 : 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 synchronized void load(File file){
final ComponentLogger logger = SModerationPaper.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 synchronized void save(File file) {
final ComponentLogger logger = SModerationPaper.LOGGER;
try {
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();
}
} catch (IOException e){
logger.error("An error occurred while saving: {}", e.toString());
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
logger.error(stackTraceElement.toString());
}
}
}
}
@@ -28,4 +28,12 @@ public final class PlayerUtil {
return Bukkit.getPlayer(uid); return Bukkit.getPlayer(uid);
} }
} }
public static UUID uuidFromString(String string) {
if (string.length() == 36) {
return UUID.fromString(string);
} else {
return UUID.fromString(string.replaceFirst("(.{8})(.{4})(.{4})(.{4})(.{12})", "$1-$2-$3-$4-$5"));
}
}
} }
@@ -3,20 +3,16 @@ package de.shiewk.smoderation.paper.util;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.UUID; import java.util.UUID;
public final class SModLegacy {
private SModLegacy() {}
/** private static byte[] longToBytes(long v){
* Utility class for byte-based saving of integers, longs and UUIDs
*/
public final class ByteUtil {
private ByteUtil(){}
public static byte[] longToBytes(long v){
ByteBuffer buffer = ByteBuffer.allocate(8); ByteBuffer buffer = ByteBuffer.allocate(8);
buffer.putLong(v); buffer.putLong(v);
return buffer.array(); return buffer.array();
} }
public static long bytesToLong(byte[] i){ private static long bytesToLong(byte[] i){
if (i.length != 8){ if (i.length != 8){
throw new IllegalArgumentException("length must be 8"); throw new IllegalArgumentException("length must be 8");
} }
@@ -25,7 +21,7 @@ public final class ByteUtil {
return buffer.getLong(0); return buffer.getLong(0);
} }
public static byte[] uuidToBytes(UUID uuid){ private static byte[] uuidToBytes(UUID uuid){
byte[] l = longToBytes(uuid.getLeastSignificantBits()); byte[] l = longToBytes(uuid.getLeastSignificantBits());
byte[] m = longToBytes(uuid.getMostSignificantBits()); byte[] m = longToBytes(uuid.getMostSignificantBits());
return new byte[]{ return new byte[]{
@@ -34,7 +30,7 @@ public final class ByteUtil {
}; };
} }
public static UUID bytesToUuid(byte[] i){ private static UUID bytesToUuid(byte[] i){
if (i.length != 16){ if (i.length != 16){
throw new IllegalArgumentException("length must be 16, was " + i.length); throw new IllegalArgumentException("length must be 16, was " + i.length);
} }
@@ -43,7 +39,7 @@ public final class ByteUtil {
return new UUID(m, l); return new UUID(m, l);
} }
public static int bytesToInt(byte[] bytes) { private static int bytesToInt(byte[] bytes) {
if (bytes.length != 4){ if (bytes.length != 4){
throw new IllegalArgumentException("length must be 4"); throw new IllegalArgumentException("length must be 4");
} }
@@ -52,9 +48,10 @@ public final class ByteUtil {
return buffer.getInt(0); return buffer.getInt(0);
} }
public static byte[] intToBytes(int value) { private static byte[] intToBytes(int value) {
ByteBuffer buffer = ByteBuffer.allocate(4); ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.putInt(value); buffer.putInt(value);
return buffer.array(); return buffer.array();
} }
} }
@@ -0,0 +1,66 @@
package de.shiewk.smoderation.paper.util;
import com.google.gson.JsonObject;
import java.util.UUID;
public final class SerializationHelper {
private final JsonObject json;
public SerializationHelper(JsonObject json) {
this.json = json;
}
public String getString(String key) {
try {
return json.get(key).getAsString();
} catch (NullPointerException e) {
throw new IllegalStateException("Key " + key + " does not exist on this object");
} catch (UnsupportedOperationException | IllegalStateException e) {
throw new IllegalStateException("Tried to get string " + key + ", but is " + json.get(key).getClass().getSimpleName());
}
}
public void putString(String key, String value) {
json.addProperty(key, value);
}
public long getLong(String key) {
try {
return json.get(key).getAsLong();
} catch (NullPointerException e) {
throw new IllegalStateException("Key " + key + " does not exist on this object");
} catch (UnsupportedOperationException | IllegalStateException e) {
throw new IllegalStateException("Tried to get long " + key + ", but is " + json.get(key).getClass().getSimpleName());
} catch (NumberFormatException e) {
throw new IllegalStateException("Tried to get long " + key + ", but is malformed: " + json.get(key).getAsString());
}
}
public void putLong(String key, long value) {
json.addProperty(key, value);
}
public UUID getUUID(String key) {
try {
return PlayerUtil.uuidFromString(getString(key));
} catch (IllegalArgumentException e) {
throw new IllegalStateException("UUID " + key + " malformed: " + getString(key));
}
}
public UUID getUUID(String key, UUID defaultValue) {
try {
return getUUID(key);
} catch (Exception ignored) {
return defaultValue;
}
}
public void putUUID(String key, UUID value) {
if (value == null) return;
json.addProperty(key, value.toString().replace("-", ""));
}
}
@@ -1,9 +1,10 @@
{ {
"smod.argument.duration.fail.invalid": "Ungültige Zeit '<arg:0>'", "smod.argument.duration.fail.invalid": "Ungültige Zeit '<arg:0>'",
"smod.argument.duration.fail.pattern": "Bitte gib eine gültige Zeit an, z.B. '1d6h30min'", "smod.argument.duration.fail.pattern": "Bitte gib eine gültige Zeit an, z.B. '1d6h30min'",
"smod.argument.offlinePlayer.fail.notCached": "Dieser Spieler ist nicht gespeichert.", "smod.argument.offlinePlayer.fail.notCached": "Die Daten des Spielers sind nicht gespeichert.",
"smod.argument.uuid.fail.notCached": "Dieser Spieler ist nicht gespeichert. Versuche, stattdessen seine UUID anzugeben.", "smod.argument.uuid.fail.notCached": "Die Daten des Spielers sind nicht gespeichert. Versuche, stattdessen seine UUID anzugeben.",
"smod.chatInput.remainingTime": "<gray><arg:0> Sekunden", "smod.chatInput.remainingTime": "<gray><arg:0> Sekunden",
"smod.command.ban.fail.alreadyBanned": "Dieser Spieler ist schon gebannt.",
"smod.command.ban.fail.forceReason": "Bitte gib einen Grund an.", "smod.command.ban.fail.forceReason": "Bitte gib einen Grund an.",
"smod.command.ban.fail.protect": "Dieser Spieler kann nicht gebannt werden.", "smod.command.ban.fail.protect": "Dieser Spieler kann nicht gebannt werden.",
"smod.command.ban.fail.self": "Du kannst dich nicht selbst bannen.", "smod.command.ban.fail.self": "Du kannst dich nicht selbst bannen.",
@@ -21,6 +22,7 @@
"smod.command.modlogs.heading": "<primary>Spieler <secondary><arg:0> <gray>(<arg:1>)", "smod.command.modlogs.heading": "<primary>Spieler <secondary><arg:0> <gray>(<arg:1>)",
"smod.command.modlogs.mute": "<primary>- ist bis <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray> stummgeschaltet. Grund: <secondary><arg:2>", "smod.command.modlogs.mute": "<primary>- ist bis <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray> stummgeschaltet. Grund: <secondary><arg:2>",
"smod.command.modlogs.none": "<primary>- ist momentan nicht gebannt oder stummgeschaltet.", "smod.command.modlogs.none": "<primary>- ist momentan nicht gebannt oder stummgeschaltet.",
"smod.command.mute.fail.alreadyMuted": "Dieser Spieler ist schon stummgeschaltet.",
"smod.command.mute.fail.forceReason": "Bitte gib einen Grund an.", "smod.command.mute.fail.forceReason": "Bitte gib einen Grund an.",
"smod.command.mute.fail.protect": "Dieser Spieler kann nicht stummgeschaltet werden.", "smod.command.mute.fail.protect": "Dieser Spieler kann nicht stummgeschaltet werden.",
"smod.command.mute.fail.self": "Du kannst dich nicht selbst stummschalten.", "smod.command.mute.fail.self": "Du kannst dich nicht selbst stummschalten.",
@@ -41,12 +43,16 @@
"smod.command.vanish.toggle.on": "<primary>Du bist jetzt unsichtbar.", "smod.command.vanish.toggle.on": "<primary>Du bist jetzt unsichtbar.",
"smod.confirm.no": "<red>Nein", "smod.confirm.no": "<red>Nein",
"smod.confirm.yes": "<green>Ja", "smod.confirm.yes": "<green>Ja",
"smod.inventory.next": "Nächste Seite (<arg:0>/<arg:1>)",
"smod.inventory.previous": "Vorherige Seite (<arg:0>/<arg:1>)",
"smod.menu": "SMod Menü", "smod.menu": "SMod Menü",
"smod.menu.cancelConfirmation": "Bist du sicher, dass du die Strafe aufheben willst?",
"smod.menu.filter": "Filter: <arg:0>", "smod.menu.filter": "Filter: <arg:0>",
"smod.menu.filter.active": "Aktive Strafen", "smod.menu.filter.active": "Aktive Strafen",
"smod.menu.filter.all": "Alle Strafen", "smod.menu.filter.all": "Alle Strafen",
"smod.menu.filter.expired": "Abgelaufene Strafen", "smod.menu.filter.expired": "Abgelaufene Strafen",
"smod.menu.filter.switch": "\u00BB Klicke, um den Filter zu ändern", "smod.menu.filter.switch": "\u00BB Klicke, um den Filter zu ändern",
"smod.menu.info.cancelled": "<red>Aufgehoben von: <gold><arg:0>",
"smod.menu.info.click": "\u00BB Klicke, um die Strafe aufzuheben", "smod.menu.info.click": "\u00BB Klicke, um die Strafe aufzuheben",
"smod.menu.info.duration": "<secondary>Dauer: <primary><arg:0>", "smod.menu.info.duration": "<secondary>Dauer: <primary><arg:0>",
"smod.menu.info.expiry.future": "<secondary>Läuft ab: <primary>In <arg:0>", "smod.menu.info.expiry.future": "<secondary>Läuft ab: <primary>In <arg:0>",
@@ -55,7 +61,6 @@
"smod.menu.info.punishedBy": "<secondary>Bestraft von: <primary><arg:0>", "smod.menu.info.punishedBy": "<secondary>Bestraft von: <primary><arg:0>",
"smod.menu.info.reason": "<secondary>Grund: <primary><arg:0>", "smod.menu.info.reason": "<secondary>Grund: <primary><arg:0>",
"smod.menu.info.timestamp": "<secondary>Zeitpunkt: <primary><arg:0>", "smod.menu.info.timestamp": "<secondary>Zeitpunkt: <primary><arg:0>",
"smod.menu.info.undone": "<red>Aufgehoben von: <gold><arg:0>",
"smod.menu.search": "Suchen", "smod.menu.search": "Suchen",
"smod.menu.search.current": "Aktueller Suchbegriff: <arg:0>", "smod.menu.search.current": "Aktueller Suchbegriff: <arg:0>",
"smod.menu.search.new": "\u00BB Klicke, um einen neuen Suchbegriff einzugeben", "smod.menu.search.new": "\u00BB Klicke, um einen neuen Suchbegriff einzugeben",
@@ -71,10 +76,11 @@
"smod.menu.type": "Typ: <arg:0>", "smod.menu.type": "Typ: <arg:0>",
"smod.menu.type.all": "Alle", "smod.menu.type.all": "Alle",
"smod.menu.type.switch": "\u00BB Klicke, um den Typ zu ändern", "smod.menu.type.switch": "\u00BB Klicke, um den Typ zu ändern",
"smod.menu.undoConfirmation": "Bist du sicher, dass du die Strafe aufheben willst?", "smod.punishment.broadcast.ban": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> für <secondary><arg:3></secondary> gebannt.<newline>Grund: <secondary><arg:2>",
"smod.punishment.broadcast.ban": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> für <secondary><arg:2></secondary> gebannt.<newline>Grund: <secondary><arg:3>", "smod.punishment.broadcast.kick": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> gekickt.<newline>Grund: <secondary><arg:2>",
"smod.punishment.broadcast.kick": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> gekickt.<newline>Grund: <secondary><arg:3>", "smod.punishment.broadcast.mute": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> für <secondary><arg:3></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:2>",
"smod.punishment.broadcast.mute": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> für <secondary><arg:2></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:3>", "smod.punishment.cancel.ban": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> entbannt.",
"smod.punishment.cancel.mute": "<primary><secondary><arg:0></secondary>s Stummschaltung wurde von <secondary><arg:1></secondary> aufgehoben.",
"smod.punishment.name.ban": "Bann", "smod.punishment.name.ban": "Bann",
"smod.punishment.name.kick": "Kick", "smod.punishment.name.kick": "Kick",
"smod.punishment.name.mute": "Stummschaltung", "smod.punishment.name.mute": "Stummschaltung",
@@ -82,8 +88,6 @@
"smod.punishment.playerMessage.kick": "<primary>Du wurdest von <secondary><arg:0></secondary> vom Server gekickt.<newline>Grund: <secondary><arg:1>", "smod.punishment.playerMessage.kick": "<primary>Du wurdest von <secondary><arg:0></secondary> vom Server gekickt.<newline>Grund: <secondary><arg:1>",
"smod.punishment.playerMessage.mute": "<primary>Du wurdest von <secondary><arg:0></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:1></secondary><newline>Du kannst in <secondary><arg:2></secondary> wieder schreiben.", "smod.punishment.playerMessage.mute": "<primary>Du wurdest von <secondary><arg:0></secondary> stummgeschaltet.<newline>Grund: <secondary><arg:1></secondary><newline>Du kannst in <secondary><arg:2></secondary> wieder schreiben.",
"smod.punishment.playerMessage.mute.chat": "<primary>Du kannst diesen Befehl nicht ausführen, während du stummgeschaltet bist.", "smod.punishment.playerMessage.mute.chat": "<primary>Du kannst diesen Befehl nicht ausführen, während du stummgeschaltet bist.",
"smod.punishment.undo.ban": "<primary><secondary><arg:0></secondary> wurde von <secondary><arg:1></secondary> entbannt.",
"smod.punishment.undo.mute": "<primary><secondary><arg:0></secondary>s Stummschaltung wurde von <secondary><arg:1></secondary> aufgehoben.",
"smod.socialspy.command": "<primary>[<secondary>SocialSpy</secondary>] <arg:0>: <secondary><arg:1>", "smod.socialspy.command": "<primary>[<secondary>SocialSpy</secondary>] <arg:0>: <secondary><arg:1>",
"smod.time.days": "<arg:0> Tage", "smod.time.days": "<arg:0> Tage",
"smod.time.hours": "<arg:0> Stunden", "smod.time.hours": "<arg:0> Stunden",
@@ -105,7 +109,5 @@
"smod.time.seconds": "<arg:0> Sekunden", "smod.time.seconds": "<arg:0> Sekunden",
"smod.time.timestamp": "<arg:2>. <arg:1> <arg:0> <arg:3>:<arg:4>:<arg:5> <arg:6>", "smod.time.timestamp": "<arg:2>. <arg:1> <arg:0> <arg:3>:<arg:4>:<arg:5> <arg:6>",
"smod.time.weeks": "<arg:0> Wochen", "smod.time.weeks": "<arg:0> Wochen",
"smod.time.years": "<arg:0> Jahre", "smod.time.years": "<arg:0> Jahre"
"smod.inventory.next": "Nächste Seite (<arg:0>/<arg:1>)",
"smod.inventory.previous": "Vorherige Seite (<arg:0>/<arg:1>)"
} }
@@ -1,9 +1,10 @@
{ {
"smod.argument.duration.fail.invalid": "Invalid duration '<arg:0>'", "smod.argument.duration.fail.invalid": "Invalid duration '<arg:0>'",
"smod.argument.duration.fail.pattern": "Please provide a valid duration, e.g. '1d6h30min'", "smod.argument.duration.fail.pattern": "Please provide a valid duration, e.g. '1d6h30min'",
"smod.argument.offlinePlayer.fail.notCached": "That player is not cached.", "smod.argument.offlinePlayer.fail.notCached": "That player's data is not saved.",
"smod.argument.uuid.fail.notCached": "That player is not cached. Try providing an UUID instead.", "smod.argument.uuid.fail.notCached": "That player's data is not saved. Try providing an UUID instead.",
"smod.chatInput.remainingTime": "<gray><arg:0> seconds", "smod.chatInput.remainingTime": "<gray><arg:0> seconds",
"smod.command.ban.fail.alreadyBanned": "This player is already banned.",
"smod.command.ban.fail.forceReason": "Please provide a reason.", "smod.command.ban.fail.forceReason": "Please provide a reason.",
"smod.command.ban.fail.protect": "This player can't be banned.", "smod.command.ban.fail.protect": "This player can't be banned.",
"smod.command.ban.fail.self": "You can't ban yourself.", "smod.command.ban.fail.self": "You can't ban yourself.",
@@ -21,6 +22,7 @@
"smod.command.modlogs.heading": "<primary>Player <secondary><arg:0> <gray>(<arg:1>)", "smod.command.modlogs.heading": "<primary>Player <secondary><arg:0> <gray>(<arg:1>)",
"smod.command.modlogs.mute": "<primary>- is muted until <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray>. Reason: <secondary><arg:2>", "smod.command.modlogs.mute": "<primary>- is muted until <secondary><arg:0></secondary> <gray>(in <arg:1>)</gray>. Reason: <secondary><arg:2>",
"smod.command.modlogs.none": "<primary>- is not currently muted or banned.", "smod.command.modlogs.none": "<primary>- is not currently muted or banned.",
"smod.command.mute.fail.alreadyMuted": "This player is already muted.",
"smod.command.mute.fail.forceReason": "Please provide a reason.", "smod.command.mute.fail.forceReason": "Please provide a reason.",
"smod.command.mute.fail.protect": "This player can't be muted.", "smod.command.mute.fail.protect": "This player can't be muted.",
"smod.command.mute.fail.self": "You can't mute yourself.", "smod.command.mute.fail.self": "You can't mute yourself.",
@@ -44,12 +46,14 @@
"smod.inventory.next": "Next page (<arg:0>/<arg:1>)", "smod.inventory.next": "Next page (<arg:0>/<arg:1>)",
"smod.inventory.previous": "Previous page (<arg:0>/<arg:1>)", "smod.inventory.previous": "Previous page (<arg:0>/<arg:1>)",
"smod.menu": "SMod Menu", "smod.menu": "SMod Menu",
"smod.menu.cancelConfirmation": "Are you sure that you want to cancel this punishment?",
"smod.menu.filter": "Filter: <arg:0>", "smod.menu.filter": "Filter: <arg:0>",
"smod.menu.filter.active": "Active punishments", "smod.menu.filter.active": "Active punishments",
"smod.menu.filter.all": "All punishments", "smod.menu.filter.all": "All punishments",
"smod.menu.filter.expired": "Expired punishments", "smod.menu.filter.expired": "Expired punishments",
"smod.menu.filter.switch": "\u00BB Click to switch filter", "smod.menu.filter.switch": "\u00BB Click to switch filter",
"smod.menu.info.click": "\u00BB Click to undo punishment", "smod.menu.info.cancelled": "<red>Cancelled by: <gold><arg:0>",
"smod.menu.info.click": "\u00BB Click to cancel punishment",
"smod.menu.info.duration": "<secondary>Duration: <primary><arg:0>", "smod.menu.info.duration": "<secondary>Duration: <primary><arg:0>",
"smod.menu.info.expiry.future": "<secondary>Expires: <primary>In <arg:0>", "smod.menu.info.expiry.future": "<secondary>Expires: <primary>In <arg:0>",
"smod.menu.info.expiry.past": "<secondary>Expired: <primary><arg:0> ago", "smod.menu.info.expiry.past": "<secondary>Expired: <primary><arg:0> ago",
@@ -57,7 +61,6 @@
"smod.menu.info.punishedBy": "<secondary>Punished by: <primary><arg:0>", "smod.menu.info.punishedBy": "<secondary>Punished by: <primary><arg:0>",
"smod.menu.info.reason": "<secondary>Reason: <primary><arg:0>", "smod.menu.info.reason": "<secondary>Reason: <primary><arg:0>",
"smod.menu.info.timestamp": "<secondary>Timestamp: <primary><arg:0>", "smod.menu.info.timestamp": "<secondary>Timestamp: <primary><arg:0>",
"smod.menu.info.undone": "<red>Undone by: <gold><arg:0>",
"smod.menu.search": "Search", "smod.menu.search": "Search",
"smod.menu.search.current": "Current search query: <arg:0>", "smod.menu.search.current": "Current search query: <arg:0>",
"smod.menu.search.new": "\u00BB Click to enter new search query", "smod.menu.search.new": "\u00BB Click to enter new search query",
@@ -73,10 +76,11 @@
"smod.menu.type": "Type: <arg:0>", "smod.menu.type": "Type: <arg:0>",
"smod.menu.type.all": "All", "smod.menu.type.all": "All",
"smod.menu.type.switch": "» Click to switch type", "smod.menu.type.switch": "» Click to switch type",
"smod.menu.undoConfirmation": "Are you sure that you want to undo this punishment?", "smod.punishment.broadcast.ban": "<primary><secondary><arg:0></secondary> was banned by <secondary><arg:1></secondary> for <secondary><arg:3></secondary>.<newline>Reason: <secondary><arg:2>",
"smod.punishment.broadcast.ban": "<primary><secondary><arg:0></secondary> was banned by <secondary><arg:1></secondary> for <secondary><arg:2></secondary>.<newline>Reason: <secondary><arg:3>", "smod.punishment.broadcast.kick": "<primary><secondary><arg:0></secondary> was kicked by <secondary><arg:1></secondary>.<newline>Reason: <secondary><arg:2>",
"smod.punishment.broadcast.kick": "<primary><secondary><arg:0></secondary> was kicked by <secondary><arg:1></secondary>.<newline>Reason: <secondary><arg:3>", "smod.punishment.broadcast.mute": "<primary><secondary><arg:0></secondary> was muted by <secondary><arg:1></secondary> for <secondary><arg:3></secondary>.<newline>Reason: <secondary><arg:2>",
"smod.punishment.broadcast.mute": "<primary><secondary><arg:0></secondary> was muted by <secondary><arg:1></secondary> for <secondary><arg:2></secondary>.<newline>Reason: <secondary><arg:3>", "smod.punishment.cancel.ban": "<primary><secondary><arg:0></secondary> was unbanned by <secondary><arg:1></secondary>.",
"smod.punishment.cancel.mute": "<primary><secondary><arg:0></secondary> was unmuted by <secondary><arg:1></secondary>.",
"smod.punishment.name.ban": "Ban", "smod.punishment.name.ban": "Ban",
"smod.punishment.name.kick": "Kick", "smod.punishment.name.kick": "Kick",
"smod.punishment.name.mute": "Mute", "smod.punishment.name.mute": "Mute",
@@ -84,8 +88,6 @@
"smod.punishment.playerMessage.kick": "<primary>You have been kicked by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1>", "smod.punishment.playerMessage.kick": "<primary>You have been kicked by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1>",
"smod.punishment.playerMessage.mute": "<primary>You have been muted by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your mute expires in <secondary><arg:2></secondary>.", "smod.punishment.playerMessage.mute": "<primary>You have been muted by <secondary><arg:0></secondary>.<newline>Reason: <secondary><arg:1></secondary><newline>Your mute expires in <secondary><arg:2></secondary>.",
"smod.punishment.playerMessage.mute.chat": "<primary>You can't run this command while you are muted.", "smod.punishment.playerMessage.mute.chat": "<primary>You can't run this command while you are muted.",
"smod.punishment.undo.ban": "<primary><secondary><arg:0></secondary> was unbanned by <secondary><arg:1></secondary>.",
"smod.punishment.undo.mute": "<primary><secondary><arg:0></secondary> was unmuted by <secondary><arg:1></secondary>.",
"smod.socialspy.command": "<primary>[<secondary>SocialSpy</secondary>] <arg:0>: <secondary><arg:1>", "smod.socialspy.command": "<primary>[<secondary>SocialSpy</secondary>] <arg:0>: <secondary><arg:1>",
"smod.time.days": "<arg:0> days", "smod.time.days": "<arg:0> days",
"smod.time.hours": "<arg:0> hours", "smod.time.hours": "<arg:0> hours",