1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-29 06:34:17 +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
@@ -6,7 +6,9 @@ import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.LiteralCommandNode;
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.PunishmentManager;
import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack;
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
public final class KickCommand implements CommandProvider {
private final PunishmentManager punishmentManager;
public KickCommand(PunishmentManager punishmentManager) {
this.punishmentManager = punishmentManager;
}
@Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("kick")
@@ -39,7 +47,7 @@ public final class KickCommand implements CommandProvider {
UUID sender = CommandUtil.getSenderUUID(context.getSource());
Player target = CommandUtil.getPlayerSingle(context, "player");
String reason = StringArgumentType.getString(context, "reason");
executeKick(sender, target, reason);
executeKick(punishmentManager, sender, target, reason);
return Command.SINGLE_SUCCESS;
}
@@ -49,24 +57,25 @@ public final class KickCommand implements CommandProvider {
}
UUID sender = CommandUtil.getSenderUUID(context.getSource());
Player target = CommandUtil.getPlayerSingle(context, "player");
executeKick(sender, target, Punishment.DEFAULT_REASON);
executeKick(punishmentManager, sender, target, Punishment.DEFAULT_REASON);
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();
if (sender.equals(targetId)) {
CommandUtil.errorTranslatable("smod.command.kick.fail.self");
} else if (target.hasPermission("smod.preventkick")){
CommandUtil.errorTranslatable("smod.command.kick.fail.protect");
}
final Punishment punishment = Punishment.kick(
Punishment punishment = new Kick(
Punishment.generateUUID(),
System.currentTimeMillis(),
sender,
targetId,
reason
);
Punishment.issue(punishment, SModerationPaper.container);
manager.tryIssue(punishment);
}
@Override