2022-03-01 01:44:10 +00:00
|
|
|
package dev.plex.command.impl;
|
|
|
|
|
|
|
|
import dev.plex.cache.DataUtils;
|
|
|
|
import dev.plex.command.PlexCommand;
|
|
|
|
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.punishment.Punishment;
|
|
|
|
import dev.plex.punishment.PunishmentType;
|
|
|
|
import dev.plex.rank.enums.Rank;
|
2022-05-10 01:05:31 +00:00
|
|
|
import dev.plex.util.BungeeUtil;
|
2022-03-01 01:44:10 +00:00
|
|
|
import dev.plex.util.PlexUtils;
|
2022-04-19 21:49:45 +00:00
|
|
|
import dev.plex.util.TimeUtils;
|
2022-04-19 20:19:55 +00:00
|
|
|
import dev.plex.util.WebUtils;
|
2022-05-10 05:08:45 +00:00
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.ZonedDateTime;
|
|
|
|
import java.util.UUID;
|
2022-03-01 01:44:10 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
@CommandParameters(name = "kick", description = "Kicks a player", usage = "/<command> <player>")
|
|
|
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY)
|
|
|
|
public class KickCMD extends PlexCommand
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
|
|
|
{
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
return usage();
|
|
|
|
}
|
|
|
|
|
2022-04-19 20:19:55 +00:00
|
|
|
UUID targetUUID = WebUtils.getFromName(args[0]);
|
2022-03-01 01:44:10 +00:00
|
|
|
String reason = "No reason provided";
|
|
|
|
|
|
|
|
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
|
|
|
{
|
|
|
|
throw new PlayerNotFoundException();
|
|
|
|
}
|
|
|
|
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
|
|
|
Player player = Bukkit.getPlayer(targetUUID);
|
|
|
|
|
|
|
|
if (player == null)
|
|
|
|
{
|
|
|
|
throw new PlayerNotFoundException();
|
|
|
|
}
|
|
|
|
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
|
|
|
punishment.setType(PunishmentType.KICK);
|
|
|
|
if (args.length > 1)
|
|
|
|
{
|
|
|
|
reason = StringUtils.join(args, " ", 1, args.length);
|
|
|
|
punishment.setReason(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
punishment.setPunishedUsername(plexPlayer.getName());
|
2022-04-19 21:49:45 +00:00
|
|
|
punishment.setEndDate(ZonedDateTime.now(ZoneId.of(TimeUtils.TIMEZONE)));
|
2022-03-01 01:44:10 +00:00
|
|
|
punishment.setCustomTime(false);
|
|
|
|
punishment.setActive(false);
|
2022-04-02 23:03:58 +00:00
|
|
|
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
2022-04-04 08:36:50 +00:00
|
|
|
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
2022-03-01 01:44:10 +00:00
|
|
|
PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName()));
|
2022-05-10 05:00:48 +00:00
|
|
|
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
|
2022-03-01 01:44:10 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|