1
mirror of https://github.com/Shiewk/SModeration.git synced 2026-04-28 05:54:16 +02:00
Files
SModeration/src/main/java/de/shiewk/smoderation/paper/command/UnbanCommand.java
T

59 lines
2.2 KiB
Java

package de.shiewk.smoderation.paper.command;
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.Punishment;
import de.shiewk.smoderation.paper.punishments.PunishmentType;
import de.shiewk.smoderation.paper.util.CommandUtil;
import io.papermc.paper.command.brigadier.CommandSourceStack;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import static io.papermc.paper.command.brigadier.Commands.argument;
import static io.papermc.paper.command.brigadier.Commands.literal;
@SuppressWarnings("UnstableApiUsage") // Paper Brigadier API
public final class UnbanCommand implements CommandProvider {
@Override
public LiteralCommandNode<CommandSourceStack> getCommandNode() {
return literal("unban")
.requires(CommandUtil.requirePermission("smod.unban"))
.then(argument("player", new PlayerUUIDArgument())
.executes(this::unbanPlayer)
)
.build();
}
private int unbanPlayer(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.BAN
);
if (punishment != null) {
punishment.undo(senderUUID);
punishment.broadcastUndo(SModerationPaper.container);
} else {
CommandUtil.errorTranslatable("smod.command.unban.fail.notBanned");
}
return Command.SINGLE_SUCCESS;
}
@Override
public String getCommandDescription() {
return "Unbans a banned player.";
}
@Override
public Collection<String> getAliases() {
return List.of("smodunban");
}
}