Teleport method

Discussion in 'Plugin Development' started by TheRoflcopter, Jun 1, 2014.

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

    TheRoflcopter

    Hey everyone, I'm new to bukkit and I keep getting stuck at the really not complex stuff.

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("top")){
    2. Location currentLoc = p.getLocation();
    3. int highestY = currentLoc.getWorld().getHighestBlockYAt((int)currentLoc.getBlockX(),(int) currentLoc.getZ());
    4. Location tpLoc = new Location(w,currentLoc.getBlockX(),highestY,currentLoc.getBlockZ());
    5. p.teleport(tpLoc);
    6.  
    7. }


    I want player to get teleported to the highest block possible after executing the command /top. The problem is that i get teleported off-center. I read somewhere that i have to add 0.5 to both X and Y, but the teleport method is requiring int. If i would add the 0.5, i would get teleported to a whole new block.
     
  2. Offline

    FeroGB

    TheRoflcopter I think this may help:
    .getBlockX() will get the X coordinate and will return everything before the decimal point. This means it can be used as a integer. To get the proper location you would need to do .getX() etc.
     
    TheRoflcopter likes this.
  3. Offline

    metalhedd

    Code:java
    1.  
    2. Location tpLoc = new Location(w,currentLoc.getBlockX(),highestY,currentLoc.getBlockZ());
    3. p.teleport(tpLoc);
    4.  


    the teleport method doesn't take any int parameters. it takes a Location. A Location has no such restrictions on whether it's values are integer or not. What ever gave you the impression you were limited to integers here?

    Code:java
    1.  
    2. Location tpLoc = new Location(w,currentLoc.getBlockX() + 0.5d, highestY, currentLoc.getBlockZ() + 0.5d);
    3. p.teleport(tpLoc);
    4.  


    done.
     
    TheRoflcopter likes this.
  4. Offline

    TheRoflcopter

    This helped, thanks. My phrasing was wrong :< One more thing, tho. Whats the difference between doing "+0.5" and "0.5d"
     
  5. Offline

    metalhedd

    nothing really, it's just being explicit about the type (double), but it's not necessary as double is the default whena decimal point is present.
     
Thread Status:
Not open for further replies.

Share This Page