2022-01-30 01:31:10 +00:00
|
|
|
package dev.plex.command.impl;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
import dev.plex.cache.DataUtils;
|
|
|
|
import dev.plex.command.PlexCommand;
|
|
|
|
import dev.plex.command.annotation.CommandParameters;
|
|
|
|
import dev.plex.command.annotation.CommandPermissions;
|
2022-01-30 01:53:22 +00:00
|
|
|
import dev.plex.command.exception.PlayerNotBannedException;
|
2022-01-30 01:31:10 +00:00
|
|
|
import dev.plex.command.exception.PlayerNotFoundException;
|
|
|
|
import dev.plex.command.source.RequiredCommandSource;
|
2022-01-30 20:56:08 +00:00
|
|
|
import dev.plex.player.PlexPlayer;
|
2022-01-30 01:31:10 +00:00
|
|
|
import dev.plex.rank.enums.Rank;
|
|
|
|
import dev.plex.util.PlexUtils;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2022-02-04 04:01:30 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2022-01-30 01:31:10 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
|
|
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
|
|
|
|
|
|
|
public class UnbanCMD extends PlexCommand
|
|
|
|
{
|
|
|
|
@Override
|
2022-02-04 04:49:05 +00:00
|
|
|
public Component execute(@NotNull CommandSender sender, @NotNull Player playerSender, String[] args)
|
2022-01-30 01:31:10 +00:00
|
|
|
{
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
return usage(getUsage());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
2022-01-30 20:56:08 +00:00
|
|
|
PlexPlayer plexPlayer = getOfflinePlexPlayer(targetUUID);
|
2022-01-30 01:31:10 +00:00
|
|
|
|
2022-01-30 20:56:08 +00:00
|
|
|
if (!DataUtils.hasPlayedBefore(targetUUID))
|
2022-01-30 01:31:10 +00:00
|
|
|
{
|
|
|
|
throw new PlayerNotFoundException();
|
|
|
|
}
|
|
|
|
|
2022-01-30 01:53:22 +00:00
|
|
|
if (!plugin.getBanManager().isBanned(targetUUID))
|
|
|
|
{
|
|
|
|
throw new PlayerNotBannedException();
|
|
|
|
}
|
|
|
|
|
2022-01-30 01:31:10 +00:00
|
|
|
plugin.getBanManager().unban(targetUUID);
|
2022-01-30 20:56:08 +00:00
|
|
|
PlexUtils.broadcast(tl("unbanningPlayer", sender.getName(), plexPlayer.getName()));
|
2022-01-30 01:31:10 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
|
|
|
{
|
|
|
|
return args.length == 1 && isAdmin(sender) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
|
|
|
}
|
|
|
|
}
|