Plex/src/main/java/dev/plex/command/impl/FreezeCMD.java

55 lines
2.1 KiB
Java
Raw Normal View History

2021-01-03 07:21:15 +00:00
package dev.plex.command.impl;
2020-11-03 02:58:56 +00:00
2020-11-05 21:17:14 +00:00
import com.google.common.collect.ImmutableList;
2022-01-04 03:04:39 +00:00
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.CommandArgumentException;
2022-01-04 03:04:39 +00:00
import dev.plex.player.PunishedPlayer;
2021-01-03 07:21:15 +00:00
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
2022-01-04 03:04:39 +00:00
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
2022-01-04 03:04:39 +00:00
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
2022-01-04 03:04:39 +00:00
import java.time.Instant;
import java.util.Date;
2020-11-06 01:29:38 +00:00
import java.util.List;
import java.util.UUID;
@CommandParameters(name = "freeze", description = "Freeze a player on the server", usage = "/<command> <player>")
2020-11-03 02:58:56 +00:00
@CommandPermissions(level = Rank.ADMIN)
public class FreezeCMD extends PlexCommand
{
@Override
2022-01-27 05:28:30 +00:00
public Component execute(CommandSender sender, String[] args)
2020-11-03 02:58:56 +00:00
{
if (args.length != 1)
2020-11-06 01:29:38 +00:00
{
2020-11-03 02:58:56 +00:00
throw new CommandArgumentException();
2020-11-06 01:29:38 +00:00
}
2020-11-03 02:58:56 +00:00
Player player = getNonNullPlayer(args[0]);
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), getUUID(sender));
punishment.setCustomTime(false);
punishment.setEndDate(new Date(Instant.now().plusSeconds(10).toEpochMilli()));
punishment.setType(PunishmentType.FREEZE);
punishment.setPunishedUsername(player.getName());
punishment.setReason("");
plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment);
PlexUtils.broadcast(tl("frozePlayer", sender.getName(), player.getName()));
return null;
2020-11-03 02:58:56 +00:00
}
@Override
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
2020-11-03 02:58:56 +00:00
{
return args.length == 1 && isAdmin(sender) ? PlexUtils.getPlayerNameList() : ImmutableList.of();
2020-11-03 02:58:56 +00:00
}
}