Plex/src/main/java/me/totalfreedom/plex/command/impl/FreezeCMD.java

57 lines
2.1 KiB
Java
Raw Normal View History

2020-11-03 02:58:56 +00:00
package me.totalfreedom.plex.command.impl;
2020-11-05 21:17:14 +00:00
import com.google.common.collect.ImmutableList;
import java.time.Instant;
import java.util.Date;
2020-11-06 01:29:38 +00:00
import java.util.List;
import java.util.UUID;
2020-11-03 02:58:56 +00:00
import me.totalfreedom.plex.cache.PlayerCache;
import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters;
import me.totalfreedom.plex.command.annotation.CommandPermissions;
import me.totalfreedom.plex.command.exception.CommandArgumentException;
import me.totalfreedom.plex.command.source.CommandSource;
import me.totalfreedom.plex.player.PunishedPlayer;
import me.totalfreedom.plex.punishment.Punishment;
import me.totalfreedom.plex.punishment.PunishmentType;
2020-11-03 02:58:56 +00:00
import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.util.PlexUtils;
import org.bukkit.entity.Player;
@CommandParameters(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
{
public FreezeCMD()
{
super("freeze");
}
@Override
public void execute(CommandSource sender, String[] args)
{
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()), sender.isConsoleSender() ? null : sender.getPlayer().getUniqueId());
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()));
2020-11-03 02:58:56 +00:00
}
@Override
public List<String> onTabComplete(CommandSource sender, String[] args)
{
2020-11-05 21:17:14 +00:00
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
2020-11-03 02:58:56 +00:00
}
}