2022-02-26 06:24:11 +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;
|
|
|
|
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-02-26 06:24:11 +00:00
|
|
|
import dev.plex.util.PlexUtils;
|
2022-04-19 20:19:55 +00:00
|
|
|
import dev.plex.util.TimeUtils;
|
|
|
|
import dev.plex.util.WebUtils;
|
2022-02-26 06:24:11 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2022-06-08 20:09:42 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2022-02-26 06:24:11 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
2023-03-08 20:26:10 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2022-02-26 06:24:11 +00:00
|
|
|
@CommandParameters(name = "tempban", usage = "/<command> <player> <time> [reason]", description = "Temporarily ban a player")
|
|
|
|
@CommandPermissions(level = Rank.ADMIN, permission = "plex.tempban", source = RequiredCommandSource.ANY)
|
|
|
|
|
|
|
|
public class TempbanCMD extends PlexCommand
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
|
|
|
{
|
|
|
|
if (args.length <= 1)
|
|
|
|
{
|
|
|
|
return usage();
|
|
|
|
}
|
|
|
|
|
2022-04-19 20:19:55 +00:00
|
|
|
UUID targetUUID = WebUtils.getFromName(args[0]);
|
2022-02-26 06:24:11 +00:00
|
|
|
String reason;
|
|
|
|
|
|
|
|
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
|
|
|
{
|
|
|
|
throw new PlayerNotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
|
|
|
Player player = Bukkit.getPlayer(targetUUID);
|
|
|
|
|
|
|
|
if (isAdmin(plexPlayer))
|
|
|
|
{
|
|
|
|
if (!isConsole(sender))
|
|
|
|
{
|
|
|
|
assert playerSender != null;
|
|
|
|
PlexPlayer plexPlayer1 = getPlexPlayer(playerSender);
|
2022-04-07 07:37:31 +00:00
|
|
|
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()) && plexPlayer.isAdminActive())
|
2022-02-26 06:24:11 +00:00
|
|
|
{
|
|
|
|
return messageComponent("higherRankThanYou");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plugin.getPunishmentManager().isBanned(targetUUID))
|
|
|
|
{
|
|
|
|
return messageComponent("playerBanned");
|
|
|
|
}
|
|
|
|
Punishment punishment = new Punishment(targetUUID, getUUID(sender));
|
2022-04-19 20:20:39 +00:00
|
|
|
punishment.setType(PunishmentType.TEMPBAN);
|
2022-02-26 06:24:11 +00:00
|
|
|
if (args.length > 2)
|
|
|
|
{
|
|
|
|
reason = StringUtils.join(args, " ", 2, args.length);
|
|
|
|
punishment.setReason(reason);
|
2022-05-10 05:00:48 +00:00
|
|
|
}
|
|
|
|
else
|
2022-02-26 06:24:11 +00:00
|
|
|
{
|
|
|
|
punishment.setReason("No reason provided.");
|
|
|
|
}
|
|
|
|
punishment.setPunishedUsername(plexPlayer.getName());
|
2022-04-19 20:19:55 +00:00
|
|
|
punishment.setEndDate(TimeUtils.createDate(args[1]));
|
2022-02-26 06:24:11 +00:00
|
|
|
punishment.setCustomTime(false);
|
|
|
|
punishment.setActive(!isAdmin(plexPlayer));
|
2022-04-02 23:03:58 +00:00
|
|
|
if (player != null)
|
|
|
|
{
|
|
|
|
punishment.setIp(player.getAddress().getAddress().getHostAddress().trim());
|
|
|
|
}
|
2022-04-04 08:36:50 +00:00
|
|
|
plugin.getPunishmentManager().punish(plexPlayer, punishment);
|
2022-02-26 06:24:11 +00:00
|
|
|
PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName()));
|
|
|
|
if (player != null)
|
|
|
|
{
|
2022-05-10 05:00:48 +00:00
|
|
|
BungeeUtil.kickPlayer(player, Punishment.generateBanMessage(punishment));
|
2022-02-26 06:24:11 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
|
|
|
{
|
2023-08-24 09:40:52 +00:00
|
|
|
return args.length == 1 && silentCheckRank(sender, Rank.ADMIN, "plex.tempban") ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
2022-02-26 06:24:11 +00:00
|
|
|
}
|
|
|
|
}
|