/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.royaldev.royalcommands.rcommands; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.royaldev.royalcommands.MessageColor; import org.royaldev.royalcommands.RUtils; import org.royaldev.royalcommands.RoyalCommands; import org.royaldev.royalcommands.wrappers.player.MemoryRPlayer; import org.royaldev.royalcommands.wrappers.player.RPlayer; @ReflectCommand public class CmdTeleport extends BaseCommand { public CmdTeleport(final RoyalCommands instance, final String name) { super(instance, name, true); } @Override public boolean runCommand(final CommandSender cs, final Command cmd, final String label, final String[] args) { if (!(cs instanceof Player)) { cs.sendMessage(MessageColor.NEGATIVE + "This command is only available to players!"); return true; } if (args.length < 1) { cs.sendMessage(cmd.getDescription()); return false; } final Player t = this.plugin.getServer().getPlayer(args[0]); if (t == null || this.plugin.isVanished(t, cs)) { cs.sendMessage(MessageColor.NEGATIVE + "That player does not exist!"); return true; } if (!RUtils.isTeleportAllowed(t) && !this.ah.isAuthorized(cs, "rcmds.tpoverride")) { cs.sendMessage(MessageColor.NEGATIVE + "That player has teleportation off!"); return true; } final Player p = (Player) cs; final RPlayer rp = MemoryRPlayer.getRPlayer(p); p.sendMessage(MessageColor.POSITIVE + "Teleporting you to " + MessageColor.NEUTRAL + t.getName() + MessageColor.POSITIVE + "."); final String error = rp.getTeleporter().teleport(t); if (!error.isEmpty()) { p.sendMessage(MessageColor.NEGATIVE + error); return true; } return true; } }