Solved Display Coordinates as int and not double?

Discussion in 'Plugin Development' started by Epicballzy, Aug 21, 2014.

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

    Epicballzy

    Hey, I'd like to be able to get the players location (x, y, z) and send them to the player as an int. Right now, they send as doubles. Its really unnecessary to send them as a double.

    How could I do that?

    Here's what I have:
    Code:java
    1. String playerName = args[0];
    2. if(player.getServer().getPlayer(playerName) != null) {
    3. Player target = player.getServer().getPlayer(playerName);
    4. String senderName = player.getName();
    5.  
    6. double x = player.getLocation().getX();
    7. double y = player.getLocation().getY();
    8. double z = player.getLocation().getZ();
    9.  
    10.  
    11. MessageManager.getInstance().sendMessage(target, ChatColor.RED + senderName + "'s coords are.. " + ChatColor.DARK_GRAY + "X: "
    12. + ChatColor.RED + x + ChatColor.DARK_GRAY + " Y:" + ChatColor.RED + y + ChatColor.DARK_GRAY + " Z: " + ChatColor.RED + z);
    13.  
    14. } else {
    15. MessageManager.getInstance().sendMessage(player, ChatColor.RED + playerName + " isn't online or is an invalid player.");
    16. return true;
    17. }


    Thanks!
     
  2. Offline

    NathanWolf

    Use getBlockX() (etc) instead of getX().

    EDIT: Ah, I see now. Yes, that ^^ is what you want :)
     
  3. Offline

    Epicballzy

    NathanWolf likes this.
  4. Offline

    ElliottOlson

    Epicballzy You can also just cast (int) to the double you have, and it automatically rounds it to the nearest number.
     
  5. Offline

    Necrodoom

    ElliottOlson it sets to floor. You are thinking of Math.round()
     
Thread Status:
Not open for further replies.

Share This Page