Solved Compass pointing towards someone in a list

Discussion in 'Plugin Development' started by SantaClawz69, Aug 10, 2016.

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

    SantaClawz69

    Hey, so my plugin is basically a plugin that relates around a wanted system and police and whatnot, and waas wondering if it was possible for a compass to point to the closes person in an arraylist? Sorry I'm a bit new to the whole compass thing, so if someone could demonstrate an example or something that would be great!
     
  2. Offline

    Zombie_Striker

    @SantaClawz69
    Yes, it is possible. Use Player#setCompassTarget(Location) to set direction for a compass for an individual player. You will need to use a RepeatingTask in order for the compass to be accurate (since the players will move). For finding out who is closest, Do the following:
    1. Create a double. This is the closest distance between two players
    2. Create a Player. This is the closest player from above.
    3. Create a for loop. Loop through all the players online.
    4. If the distance between the two players is less than the double above, then set the double equal to this new distance, and the player equal to the player from the for loop.
    5. After you have looped through all the players, the player from step #2 will be the closest player.
     
  3. Offline

    SantaClawz69

    Thank you, but I was asking if I could get the closest player that is in an arraylist. Not just any player, my plugin is supposed to point it's arrow to the closest wanted man. So I made an arraylist of wanted people. I'm wondering if it can point towards a person depending on the arraylist.
     
  4. Offline

    Zombie_Striker

    @SantaClawz69
    If you only want the players in an arraylist, loop through that arraylist instead of everyone online.
     
  5. Offline

    SantaClawz69

    Thank you, I got it!
     
  6. Offline

    MrGeneralQ

    Once again, an actual usefull answer that can be used in many cases. Thanks @Zombie_Striker !
     
Thread Status:
Not open for further replies.

Share This Page