2022-01-30 01:31:10 +00:00
|
|
|
package dev.plex.command.impl;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableList;
|
2022-04-04 08:36:50 +00:00
|
|
|
import dev.plex.Plex;
|
2022-01-30 01:31:10 +00:00
|
|
|
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 net.kyori.adventure.text.Component;
|
2022-04-04 08:36:50 +00:00
|
|
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
|
|
import org.bukkit.Bukkit;
|
2022-01-30 01:31:10 +00:00
|
|
|
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;
|
2022-02-25 07:50:11 +00:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2022-01-30 01:31:10 +00:00
|
|
|
|
2022-04-04 08:36:50 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2022-01-30 01:31:10 +00:00
|
|
|
@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-25 07:50:11 +00:00
|
|
|
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
2022-01-30 01:31:10 +00:00
|
|
|
{
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
2022-02-14 05:55:50 +00:00
|
|
|
return usage();
|
2022-01-30 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-04-04 08:36:50 +00:00
|
|
|
plugin.getPunishmentManager().isAsyncBanned(targetUUID).whenComplete((aBoolean, throwable) ->
|
2022-01-30 01:53:22 +00:00
|
|
|
{
|
2022-04-04 08:36:50 +00:00
|
|
|
if (!aBoolean)
|
|
|
|
{
|
|
|
|
send(sender, MiniMessage.miniMessage().deserialize(new PlayerNotBannedException().getMessage()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
plugin.getPunishmentManager().unban(targetUUID);
|
|
|
|
PlexUtils.broadcast(messageComponent("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
|
|
|
|
{
|
2022-02-18 02:00:47 +00:00
|
|
|
return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
2022-01-30 01:31:10 +00:00
|
|
|
}
|
|
|
|
}
|