2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.command.impl;
|
2020-11-10 02:47:03 +00:00
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableList;
|
2022-01-04 03:04:39 +00:00
|
|
|
import dev.plex.cache.DataUtils;
|
|
|
|
import dev.plex.cache.PlayerCache;
|
|
|
|
import dev.plex.command.PlexCommand;
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.command.annotation.CommandParameters;
|
|
|
|
import dev.plex.command.annotation.CommandPermissions;
|
|
|
|
import dev.plex.command.exception.PlayerNotFoundException;
|
|
|
|
import dev.plex.command.source.RequiredCommandSource;
|
|
|
|
import dev.plex.player.PlexPlayer;
|
|
|
|
import dev.plex.player.PunishedPlayer;
|
2022-01-04 03:04:39 +00:00
|
|
|
import dev.plex.punishment.Punishment;
|
|
|
|
import dev.plex.punishment.PunishmentType;
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.rank.enums.Rank;
|
|
|
|
import dev.plex.util.PlexUtils;
|
2022-01-27 21:23:01 +00:00
|
|
|
import java.time.Instant;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
2022-01-27 09:00:50 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2020-11-10 02:47:03 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2022-01-27 09:00:50 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-11-10 02:47:03 +00:00
|
|
|
|
2022-01-27 09:00:50 +00:00
|
|
|
@CommandParameters(name = "ban", usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
2022-01-30 01:31:10 +00:00
|
|
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.ban", source = RequiredCommandSource.ANY)
|
2020-11-10 02:47:03 +00:00
|
|
|
|
|
|
|
public class BanCMD extends PlexCommand
|
|
|
|
{
|
|
|
|
@Override
|
2022-01-27 05:28:30 +00:00
|
|
|
public Component execute(CommandSender sender, String[] args)
|
2020-11-10 02:47:03 +00:00
|
|
|
{
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
2022-01-27 09:00:50 +00:00
|
|
|
return usage(getUsage());
|
2020-11-10 02:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args.length == 1)
|
|
|
|
{
|
|
|
|
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
|
|
|
|
|
|
|
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
|
|
|
{
|
|
|
|
throw new PlayerNotFoundException();
|
|
|
|
}
|
|
|
|
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
|
|
|
|
|
|
|
if (isAdmin(plexPlayer))
|
|
|
|
{
|
2022-01-27 09:00:50 +00:00
|
|
|
if (!isConsole(sender))
|
2020-11-10 02:47:03 +00:00
|
|
|
{
|
2022-01-27 09:00:50 +00:00
|
|
|
PlexPlayer plexPlayer1 = getPlexPlayer((Player) sender);
|
2020-11-10 02:47:03 +00:00
|
|
|
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
|
|
|
{
|
2022-01-27 09:00:50 +00:00
|
|
|
return tl("higherRankThanYou");
|
2020-11-10 02:47:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(targetUUID) == null ? new PunishedPlayer(targetUUID) : PlayerCache.getPunishedPlayer(targetUUID);
|
2022-01-27 09:00:50 +00:00
|
|
|
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
2020-11-10 02:47:03 +00:00
|
|
|
punishment.setType(PunishmentType.BAN);
|
|
|
|
punishment.setReason("");
|
|
|
|
punishment.setPunishedUsername(plexPlayer.getName());
|
2022-01-27 09:00:50 +00:00
|
|
|
//TODO: Debug End date
|
2020-11-10 02:47:03 +00:00
|
|
|
punishment.setEndDate(new Date(Instant.now().plusSeconds(10/*PlexUtils.secondsToHours(24)*/).getEpochSecond()));
|
|
|
|
punishment.setCustomTime(false);
|
|
|
|
plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment);
|
2022-01-30 01:31:10 +00:00
|
|
|
PlexUtils.broadcast(tl("unbanningPlayer", sender.getName(), plexPlayer.getName()));
|
2020-11-10 02:49:51 +00:00
|
|
|
if (Bukkit.getPlayer(targetUUID) != null)
|
2020-11-10 02:47:03 +00:00
|
|
|
{
|
2022-01-27 09:00:50 +00:00
|
|
|
Bukkit.getPlayer(targetUUID).kick(componentFromString("&cYou've been banned."));
|
2020-11-10 02:47:03 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-27 09:00:50 +00:00
|
|
|
return null;
|
2020-11-10 02:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-01-27 09:00:50 +00:00
|
|
|
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();
|
2020-11-10 02:47:03 +00:00
|
|
|
}
|
2022-01-27 09:00:50 +00:00
|
|
|
|
2020-11-10 02:47:03 +00:00
|
|
|
}
|