teleport a player to another [solved]

Discussion in 'Plugin Development' started by mrzeapple, Aug 10, 2013.

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


    this is my code
    I get an error with the args[1] part
  2. mrzeapple args[1] needs to be a Location type object.

    EDIT: Try using ((Location) args[1])
  3. Offline


    It gives me an error cannot cast string to location
    Also love your pic
  4. Offline


    I assume this is happening inside an onCommand() method?

    If that is true, then the args array is an array of strings, NOT player objects.

    It's a string with the NAME of the player, not the player object itself.
    Try this:

    2. // Assuming myPlugin is an instance of JavaPlugin. If you follow the convention
    3. // of putting an onCommand() inside your plugin class itself, you can just use
    4. // "this" in place of myPlugin:
    5. Player p = myPlugin.getServer().getPlayer( args[1] );
    6. if( p != null) {
    7. player.teleport( p );
    8. } else {
    9. // some sort of error message here: no player with that name found.
    10. }
  5. Thank you! :D Grumpy Cat is my "mascot", so to say. Besides, my pic is extremely cute. :3
  6. Offline


    You can't cast a string to location directly.
    Create a new Location and use that as parameter for teleport().
    For example:
    Location tele = new Location(world, x, y, z);
    Where "world" is the world as "World" object, and x, y, z are the coords as doubles.
    So parse the given coords to double values and get the current world from the player. (or from the command, if he wants to teleport to another world)

    And before doing this, you need to check if the player gave all arguments needed and in the right format.
    But this depends on how your command looks.

    EDIT: Did'nt see your last post. Forget this post...
  7. Or you could just get the location of the player you're trying to teleport to?
  8. Offline


    Thank you that worked
  9. Change the topic to solved.
Thread Status:
Not open for further replies.

Share This Page