Distance from one location to another stored in a hashset

Discussion in 'Plugin Development' started by RipRoss, Dec 12, 2017.

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

    RipRoss

    How do I get the amount of blocks between one location and another, for example.. the persons locations and a blocks location.

    I have stored the locations in a hashset using

    Code:
     HashSet<Location> torches = new HashSet<Location>(); 
    I have a block place event like so:

    Code:
    @EventHandler
        public void onPlace(BlockPlaceEvent event) {
            Block block = event.getBlock();
            Location loc = event.getBlock().getLocation();
           
            if(block.getType() == Material.TORCH) {
                torches.add(loc);
            }
        }
    
    Now how would I say check the players location in relation to all locations in the hashset.

    Once within a certain range, it would trigger an event.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @RipRoss Loop over the values in torches?
     
  3. Offline

    RipRoss

    Can you give me an example please?
     
  4. Offline

    timtower Administrator Administrator Moderator

    Won't make an example for a simple loop
     
  5. Offline

    RipRoss

    I don't need the loop example, but how do I get the values from it? and then get the location of the values in the list.
     
Thread Status:
Not open for further replies.

Share This Page