Solved Teleportation error

Discussion in 'Plugin Development' started by C0lA_K1nG, Aug 19, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    C0lA_K1nG

    Hey guy, all my other commands in my plugin work fine but the teleportation command doesn't. It doesn't give me a error or anything it just doesn't do anything that it is supposed to.\
    Heres my java code:
    Code:java
    1. if(commandLabel.equalsIgnoreCase("tp")){
    2. if(args.length == 0){
    3. player.sendMessage(ChatColor.DARK_RED + "[" + ChatColor.RED + "Usage Error" + ChatColor.DARK_RED + "]:" + ChatColor.GOLD + " Usage: /TP (player)");
    4. }else if(args.length == 1){
    5. Player targetPlayer = player.getServer().getPlayer(args[0]);
    6. Location targetPlayerLocation = targetPlayer.getLocation();
    7. player.teleport(targetPlayerLocation);
    8. }else if(args.length == 2){
    9. Player targetPlayer = player.getServer().getPlayer(args[0]);
    10. Player targetPlayer1 = player.getServer().getPlayer(args[1]);
    11. Location targetPlayer1Location = targetPlayer1.getLocation();
    12. targetPlayer.teleport(targetPlayer1Location);
    13. }
    14.  
     
  2. C0lA_K1nG
    Make sure you added the "tp" command to your plugin.yml. Also make sure you don't have any bracket mistakes in your code.

    ALSO you should check if targetplayer is not null, before checking their location and teleporting. If target is not online (or is null), you will get a NPE.
    Code:
    if(targetPlayer != null)
        // continue
     
  3. Offline

    ikyogre1

    Make sure everything in the plugin.yml is formatted correctly. My commands were not formatted correctly, and I could not get it to work.
     
  4. Offline

    C0lA_K1nG

    Seems like it is correct in my plugin.yml and i couldn't find any bracket errors. Hmmm... wonder what's wrong :p
     
  5. Offline

    Pawnguy7

    No errors in the console?

    Does the command run?

    Also, teleport also works with entities (because they all have a location), so you don't need to get their location to teleport to them.
     
  6. Offline

    C0lA_K1nG

    The command doesn't run. It does nothing. No errors, no message, no TP, no nothing! But it does show up when i do /help
     
  7. Offline

    Pawnguy7

    Try adding a broadcast before everything else in the command to see if it runs.

    If so, how are you calling it?
     
  8. Offline

    C0lA_K1nG

    I found out why! Thanks. I just added a random "}" right in the middle of my code :O!
     
Thread Status:
Not open for further replies.

Share This Page