How do I teleport a player when they reach a Y 255 in a certain world

Discussion in 'Plugin Development' started by TRIPL3_CATS, Feb 11, 2015.

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

    TRIPL3_CATS

    Hello! I am trying to code a plugin when a player reaches Y 255 in a certain world (Survival) they will be teleported to the end (I am making a space world).
    Please help!
     
  2. Offline

    Signatured

    You could do this by making a PlayerMoveEvent, check the players world and location, check if their Y is greater than 255 (if (player.getLocation().getY >= 255)), if the player is higher than 255, teleport them to a location.

    I could give you an example later when I get home.
     
  3. Offline

    TRIPL3_CATS

    I am still confused how, you would need to give me an example :)
     
  4. Offline

    Signatured

    Something like:
    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent e) {
    3. Player player = e.getPlayer();
    4. if (player.getWorld().getName().equalsIgnoreCase("Survival") {
    5. int y = player.getLocation().getY();
    6. if (y >= 255) {
    7. World world = Bukkit.getWorld("Survival");
    8.  
    9. player.teleport(world.getSpawnLocation);
    10. }
    11. }
    12. }
     
  5. Offline

    drpk

    @Signatured I would suggest using a runnable, as that may cause quite some lag.
     
  6. Offline

    WesJD

    Konato_K likes this.
  7. Offline

    TRIPL3_CATS

    I tried this but, I cannot figure out how to organize the imports? It comes with errors on the lines
     
  8. Offline

    Signatured

    Where are you getting errors? What lines specifically?
     
  9. Offline

    TRIPL3_CATS

    On the lines with
    if (player.getWorld().getName().equalsIgnoreCase("Survival") {
    int y = player.getLocation().getY();
    and
    World world = Bukkit.getWorld("Survival");
    player.teleport(world.getSpawnLocation);


    at the bottom right it says the errors
     
  10. Offline

    Konato_K

    @WesJD This makes sense for some things, but in this case, checking if they moved a block is checking 3 coordinates, while just checking y is only 1, so it would be better to first check if they are above 255 and then check the world.
     
  11. Offline

    WesJD

  12. Offline

    ChipDev

    Thats a java problem, Did you learn it?
     
  13. Offline

    TRIPL3_CATS

    So, what do I do? D:
     
  14. Offline

    Konato_K

    @TRIPL3_CATS First check if they are above 255, then check if that's the world you want (using the world name is ok)
     
  15. Offline

    TRIPL3_CATS

    It says

    "getSpawnLocation cannot be resolved or is not a field"
     
  16. Offline

    SuperOriginal

    @TRIPL3_CATS Please don't copy paste. Just use the concept of that code that pertains to your issue.
     
  17. Offline

    Konato_K

    @TRIPL3_CATS With no intention to sound mean, you should probably learn java first.

    getSpawnLocation is a method.
     
Thread Status:
Not open for further replies.

Share This Page