Solved Get players 180 blocks north from my location ?

Discussion in 'Plugin Development' started by Jace_oio, May 23, 2013.

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

    Jace_oio

    Hi,

    The title says it all :) how would I get all players 180 Blocks NORTH from my location ?

    Any help is appreciated :)

    - Best wishes Jace_OiO

    Any one :( ?

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

    Ugleh

    This is North as defined when pressing F3 in game, not sure if it is different to stuff like Bukkit with BlockFace.North, or the sun in minecraft.
    Code:
            Player thePlayer = event.getPlayer();
            Double offsetLocZ = thePlayer.getLocation().subtract(0, 0, 150).getZ();       
            for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                if(player.getLocation().getBlockZ() <= offsetLocZ){
                    //This player is 150 blocks north of thePlayer.
                }
     
  3. Offline

    Jace_oio

    Ugleh Thanks for the answer ill try it out instantly ! :)
     
  4. Offline

    lycano

    I would fetch a list of players at that location instead going through all players as there might be 100 players online at a time.

    Check the apidocs for Entity.getNearbyEntities.
    Note that you would have to filter all "non player instances" with Entity.getType() first and create a list of those players.

    This might sound like a con but if no player entity is at that location or the created list is empty then you can instantly return and skip all location checks which will improve performance.
     
  5. Offline

    Jace_oio

    Ugleh Maybe is a dumb question but how would I get West ?

    hehe lycano thanks for the answer, and I think your right :p

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

    Pink__Slime

    Open up Minecraft and login in to either a server or single player. Open F3 and look at your coordinates. Check if you are facing West.
    The things you want to check are:
    1. Which value changes x/z
    2. Does it go lower or higher?

    Now just substitute your answers into the code Ugleh provided.
    For example:
    Code:java
    1. Double offsetLocZ = thePlayer.getLocation().subtract(0, 0, 150).getZ();

    He subtracted 150 on the Z because when walking North, your Z value decreases so in turn, you are getting 150 blocks away from you.
    Next he checks if any player is 150 blocks away or further with this.
    Code:java
    1. if(player.getLocation().getBlockZ() <= offsetLocZ)
     
  7. Offline

    Jace_oio

    Pink__Slime I like understood the code but I didn't know how he declared it was North XD thanks for the answer :)
     
  8. Offline

    lycano

    Jace_oio check out the Location docs then you will instantly know how he did it and what you would have to change when you want another direction.
     
  9. Offline

    Ugleh

    Well from what I heard of the OP I probably dont understand. Did you want to get the person exactly 150 blocks north, or people who are 150 blocks or more away from the person, going north?
     
Thread Status:
Not open for further replies.

Share This Page