[IMPORTANT] Setting variable as a world for teleport method

Discussion in 'Plugin Development' started by ZyphiorMC, Aug 17, 2014.

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

    ZyphiorMC

    Hey I am making a paintball plugin for my server, but I am having trouble setting a variable to a world string. I have tried using 'String lobbyWorld = "lobby";' as well as what is currently shown. I need to teleport the player to the spawn (lobby) when they login, which is what I am having trouble with.

    Here is my current code:
    Code:java
    1. public class main extends JavaPlugin implements Listener
    2. {
    3. String prefix = ChatColor.BLUE + "[" + ChatColor.AQUA + "Paintball" + ChatColor.BLUE + "] " + ChatColor.RED;
    4.  
    5. public void onEnable()
    6. {
    7. PluginManager pm = Bukkit.getServer().getPluginManager();
    8. pm.registerEvents(this, this);
    9. }
    10.  
    11. public void onDisable()
    12. {
    13.  
    14. }
    15.  
    16. @EventHandler
    17. public void onPlayerJoin(PlayerJoinEvent event)
    18. {
    19. World lobbyWorld = "lobby";
    20. int lobbyX = 0;
    21. int lobbyY = 5;
    22. int lobbyZ = 0;
    23. int lobbyPitch = 0;
    24. int lobbyYaw = 0;
    25.  
    26. Player player = event.getPlayer();
    27. PlayerInventory pi = player.getInventory();
    28. pi.clear();
    29. player.sendMessage(prefix + "Welcome to " + ChatColor.GREEN + "Zyphior" + ChatColor.RED + "!");
    30. Location loc = new Location(lobbyWorld, lobbyX, lobbyY, lobbyZ, lobbyPitch, lobbyYaw);
    31. player.teleport(loc);
    32. }
    33. }


    If you need more information, let me know. :)
     
  2. Offline

    mechoriet

    Whats your error exactly

    Like you got a stacktrace?

    Did you tried also hard coded like in the Location method
     
  3. Offline

    ZyphiorMC

  4. Offline

    mechoriet

    you should change the
    World lobbyWorld ="lobby";
    to
    String lobbyWorld = "lobby";

    look good at the error next time

    your error:
    in the type Entity is not applicable for the arguments(String, int, int, int)
     
  5. Offline

    ZyphiorMC

    mechoriet - Still doesn't teleport the player to the location and the eclipse client looks like this

    [​IMG]
     
  6. Offline

    Lurvik

    [​IMG]

    If we look where I've circled we can see the important part of the stack trace. "The method teleport(Location, PlayerTeleportEvent.TeleportCause) in the type Entity is not applicable for the arguments (String, int, int, int) at me.Da_Pepsi_Monster.Paintball.main.onPlayerJoin(main.java:43)"

    The problem here is there is no method called "teleport" that takes the arguments String, int, int, int. You call this on line 43 in "main.java". What you should provide is a Location (there's a method that only takes a Location).

    Instead of creating a new Location you should modify an existing one (it tends to be easier).

    Code:java
    1.  
    2. Location newLoc = player.getLocation().clone();
    3. newLoc.setWorld(lobbyworld);
    4. newLow.setX(lobbyX);
    5. newloc.setY(lobbyY);
    6. newLoc.setZ(lobbyZ);
    7. player.teleport(loc);
    8.  
     
  7. Offline

    Bart

    A location requires a World and 3 coordinates - you got the three coordinates and the world object but you do not assign the world object correctly - the string "lobbyWorld" can't be assigned to a World object.

    Code:
    World world = getServer().getWorld("lobbyWorld");
     
    player.teleport(new Location(world, x, y, z, pitch, yaw));
    
     
  8. Offline

    ZyphiorMC

    Bart - Thank you! Your code worked for me :D

    This is now the code for the event:
    Code:java
    1. public void onPlayerJoin(PlayerJoinEvent event)
    2. {
    3. Player player = event.getPlayer();
    4.  
    5. World lobbyWorld = getServer().getWorld("world");
    6. int lobbyX = 0;
    7. int lobbyY = 5;
    8. int lobbyZ = 0;
    9. int lobbyPitch = 90;
    10. int lobbyYaw = 0;
    11.  
    12. PlayerInventory pi = player.getInventory();
    13. pi.clear();
    14. player.sendMessage(prefix + "Welcome to " + ChatColor.GREEN + "Zyphior" + ChatColor.RED + "!");
    15. Location lobbyLoc = new Location(lobbyWorld, lobbyX, lobbyY, lobbyZ, lobbyPitch, lobbyYaw);
    16. player.teleport(lobbyLoc);
    17. }
     
    Bart likes this.
Thread Status:
Not open for further replies.

Share This Page