Solved /tp command teleports players to you?

Discussion in 'Plugin Help/Development/Requests' started by Kody_Jay, Oct 2, 2016.

Thread Status:
Not open for further replies.
  1. I am making a plugin, and in my TP class, I have set up a command so that when you type '/tp <username>' it would teleport you to that player, I have been having a problem with this though. When I use that command, it teleports that player to you, not you to that player. Here is my code:

    package me.kody_jay.MoCommands;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    public class ForceTeleportCommand implements CommandExecutor{
        private Core core;
        public ForceTeleportCommand(Core core) {
            this.core = core;
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    Player player = (Player) sender;
    if (cmd.getName().equalsIgnoreCase("tp")){
    if(args.length == 0){
    player.sendMessage(ChatColor.RED + "Usage : /tp <username>");
    }if(args.length == 1){
        if (!player.hasPermission("")) {
         player.sendMessage(ChatColor.RED + "You do not have the permission to use this command!");
      } else {
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    Location location1 = player.getLocation();
    player.sendMessage(ChatColor.GOLD + "Teleporting you to " + ChatColor.RED + targetPlayer.getName()); 
    return false;
    If anybody could help me with this, it would be greatly appreciated.
  2. Player targetPlayer = player.getServer().getPlayer(args[0]);

    should be

    Player targetPlayer = Bukkit.getServer().getPlayer(args[0]);
  3. Online

    timtower Administrator Administrator Moderator

  4. Online

    timtower Administrator Administrator Moderator

    @Kody_Jay Where you are teleporting would be a good place probably.
  5. @timtower

    Found it, thanks.
Thread Status:
Not open for further replies.

Share This Page