{HELP} Player Teleport

Discussion in 'Plugin Development' started by The Fancy Whale, Oct 8, 2013.

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

    The Fancy Whale

    I am getting the error: This method teleport(location) in the type Entity is not applicable for the arguments (string)
    Here is my code:
    Code:java
    1. player.teleport(getConfig().getString(args[2] + "SpawnLobby"));


    Thanks in advance!
    BTW the args 2 is because they are typing in the command /mc join (arena name)
    and the arena name spawnlobby's are in the config
     
  2. Offline

    Stealth2800

    You can't teleport an entity to a string. You can teleport an entity to either a Location or Entity.
     
  3. Offline

    The Fancy Whale

    stealth2800 So how do i teleport them to someplace predetermined?
     
  4. Offline

    cfil360

    The F
    You have to create a location. Locations require a world, a x, a y, and a z coordinate.
    If you just want to teleport them to a world's spawn then you can use this.
    Code:java
    1. Player player = (Player) sender;
    2. World w = p.getworld//gets the world the current player is in
    3. //World w = Bukkit.getServer().getWorld("spawn");//replace "spawn" with the name of the world you want to get
    4.  
    5. p.teleport(w.getSpawnLocation());

    Otherwise use something like this
    Code:java
    1. Player player = (Player) sender;
    2. Location l = new Location(player.getWorld(), x, y, z);
    3. player.teleport(l);
     
  5. Offline

    The Fancy Whale

    But i have custom arena names in my arena file. How do i teleport to certain locations in the arena file?
     
  6. Offline

    cfil360

    You have to save the world name, x, y and z coordinates in the arena file, then load them up and create the location
     
  7. Offline

    The Fancy Whale

    How do i "Load them up and create the location"

    Code:
    Location LobbySpawn = (Location) this.getConfig().getString(args[2] + "Spawn1");
    cfil360
    Locations cannot be set to strings how do I do this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  8. Offline

    xTrollxDudex

    The Fancy Whale
    Heard of constructors before? This is why you leans java BEFORE using the Bukkit API
     
  9. Offline

    Stealth2800

    You could do something like
    Code:
    World world = Bukkit.getWorld(getConfig().getString("spawn.world"));
    int x = getConfig().getInt("spawn.x");
    int y = getConfig().getInt("spawn.y");
    int z = getConfig().getInt("spawn.z");
    Location location = new Location(world, x, y, z);
    
    Implying that the config looks something like
    Code:
    spawn:
      world: world_nether
      x: 500
      y: 60
      z: -300
    Constructors are just basic Java. If you don't know what they are, you should be working on learning Java a little bit more instead before you move on to making things with it.
     
  10. Offline

    The Fancy Whale

    stealth2800 I know how to do that but it is not letting me use an argument in place of the word spawn in that case
     
  11. Offline

    cfil360

    It will just make sure you include the dot where necessary.
     
  12. Offline

    Goblom

    You are missing the YAML period before "SpawnLobby"
    Code:java
    1. args[2].toString() + ".SpawnLobby"
     
Thread Status:
Not open for further replies.

Share This Page