mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-30 10:05:59 +00:00
50 lines
1.5 KiB
Java
50 lines
1.5 KiB
Java
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
import io.papermc.lib.PaperLib;
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.GameMode;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME)
|
|
@CommandParameters(description = "Quickly spectate someone.", usage = "/<command> <playername>", aliases = "spec")
|
|
public class Command_spectate extends FreedomCommand
|
|
{
|
|
|
|
@Override
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
{
|
|
if (args.length == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
Player player = getPlayer(args[0]);
|
|
if (player == null)
|
|
{
|
|
msg(PLAYER_NOT_FOUND);
|
|
return true;
|
|
}
|
|
|
|
if (player.getGameMode().equals(GameMode.SPECTATOR))
|
|
{
|
|
msg("You cannot spectate other players that are in spectator mode.", ChatColor.RED);
|
|
return true;
|
|
}
|
|
|
|
if (!playerSender.getGameMode().equals(GameMode.SPECTATOR))
|
|
{
|
|
playerSender.setGameMode(GameMode.SPECTATOR);
|
|
}
|
|
|
|
if (playerSender.getWorld() != player.getWorld())
|
|
{
|
|
PaperLib.teleportAsync(playerSender, player.getLocation());
|
|
}
|
|
|
|
playerSender.setSpectatorTarget(player);
|
|
return true;
|
|
}
|
|
} |