TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spectate.java

49 lines
1.4 KiB
Java
Raw Normal View History

2018-07-22 00:45:56 +00:00
package me.totalfreedom.totalfreedommod.command;
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.TRIAL_MOD, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Quickly spectate someone.", usage = "/<command> <playername>", aliases = "spec")
2018-07-22 00:45:56 +00:00
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())
{
playerSender.teleport(player);
}
2018-07-22 00:45:56 +00:00
playerSender.setSpectatorTarget(player);
2018-07-22 00:45:56 +00:00
return true;
}
}