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:
@@ -4,10 +4,11 @@ import com.mojang.brigadier.Command;
|
||||
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.command.argument.PlayerUUIDArgument;
|
||||
import de.shiewk.smoderation.paper.punishments.Mute;
|
||||
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 io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
|
||||
@@ -21,6 +22,12 @@ import static io.papermc.paper.command.brigadier.Commands.literal;
|
||||
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
|
||||
public final class UnmuteCommand implements CommandProvider {
|
||||
|
||||
private final PunishmentManager punishmentManager;
|
||||
|
||||
public UnmuteCommand(PunishmentManager punishmentManager) {
|
||||
this.punishmentManager = punishmentManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
|
||||
return literal("unmute")
|
||||
@@ -34,14 +41,15 @@ public final class UnmuteCommand implements CommandProvider {
|
||||
private int unmutePlayer(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
|
||||
UUID senderUUID = CommandUtil.getSenderUUID(context.getSource());
|
||||
UUID target = context.getArgument("player", UUID.class);
|
||||
final Punishment punishment = SModerationPaper.container.find(
|
||||
p -> p.to.equals(target) && p.isActive() && p.type == PunishmentType.MUTE
|
||||
final List<Punishment> punishments = punishmentManager.byTargetUUID(
|
||||
target,
|
||||
p -> p instanceof Mute mute && mute.isActive()
|
||||
);
|
||||
if (punishment != null) {
|
||||
punishment.undo(senderUUID);
|
||||
punishment.broadcastUndo(SModerationPaper.container);
|
||||
} else {
|
||||
CommandUtil.errorTranslatable("smod.command.unmute.fail.notMuted");
|
||||
for (Punishment punishment : punishments) {
|
||||
punishmentManager.cancel((TimedPunishment) punishment, senderUUID);
|
||||
}
|
||||
if (punishments.isEmpty()) {
|
||||
CommandUtil.errorTranslatable("smod.command.unmute.fail.notBanned");
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user