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. Offline

    Kody_Jay

    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:

    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{
       
        @SuppressWarnings("unused")
        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("mocommands.tp")) {
         player.sendMessage(ChatColor.RED + "You do not have the mocommands.tp permission to use this command!");
      } else {
    @SuppressWarnings("deprecation")
    Player targetPlayer = player.getServer().getPlayer(args[0]);
    Location location1 = player.getLocation();
    targetPlayer.teleport(location1);
    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 Moderator Moderator

  4. Offline

    Kody_Jay

  5. Online

    timtower Moderator Moderator

    @Kody_Jay Where you are teleporting would be a good place probably.
     
  6. Offline

    Kody_Jay

    @timtower

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

Share This Page