roguehippo Posted June 7, 2016 Share Posted June 7, 2016 i basically just need to know how to return a true if there are no "Logs" (or whatever item) in a given area. or if it would be easier if there are just no grounditems in an area at all, but this may cause future problems. Quote Link to comment Share on other sites More sharing options...
Lemons Posted June 7, 2016 Share Posted June 7, 2016 (edited) GroundItem logs = getScript().getGroundItems().closest( new AreaFilter<GroundItem>(area), new NameFilter<GroundItem>("Logs")); if (logs != null) { // Logs in the area } Edited June 7, 2016 by Lemons 2 Quote Link to comment Share on other sites More sharing options...
Explv Posted June 7, 2016 Share Posted June 7, 2016 (edited) i basically just need to know how to return a true if there are no "Logs" (or whatever item) in a given area. or if it would be easier if there are just no grounditems in an area at all, but this may cause future problems. Using the OSBot API: final boolean itemIsInArea(final Area area, final String itemName) { return getGroundItems().filter(new AreaFilter<>(area), new NameFilter<>(itemName)).size() > 0; } Using the Java 8 Stream API : final boolean itemIsInArea(final Area area, final String itemName) { return getGroundItems().getAll().stream().anyMatch(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem)); } Using a for loop: final boolean itemIsInArea(final Area area, final String itemName) { for(final GroundItem groundItem : getGroundItems().getAll()) { if(groundItem.getName().equals(itemName) && area.contains(groundItem)) { return true; } } return false; } If you want to get the closest matching item in the area you can do: With the OSBot API: final Optional<GroundItem> closestItemInArea(final Area area, final String itemName) { return Optional.ofNullable(getGroundItems().closest(new AreaFilter<>(area), new NameFilter<>(itemName))); } With the Java 8 Stream API: final Optional<GroundItem> closestItemInArea(final Area area, final String itemName) { return getGroundItems().getAll() .stream() .filter(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem)) .min((g1, g2) -> Integer.compare(myPosition().distance(g1.getPosition()), myPosition().distance(g2.getPosition()))); } Or if you want to get any matching item in the area (not necessarily the closest) you can do: With the OSBot API: final Optional<GroundItem> getItemInArea(final Area area, final String itemName) { return Optional.ofNullable(getGroundItems().singleFilter(getGroundItems().getAll(), new AreaFilter<>(area), new NameFilter<>(itemName))); } With the Java 8 Stream API: final Optional<GroundItem> getItemInArea(final Area area, final String itemName) { return getGroundItems().getAll() .stream() .filter(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem)) .findAny(); } Edited June 7, 2016 by Explv 2 Quote Link to comment Share on other sites More sharing options...
FrostBug Posted June 7, 2016 Share Posted June 7, 2016 Using the OSBot API: final boolean itemIsInArea(final Area area, final String itemName) { return getGroundItems().filter(new AreaFilter<>(area), new NameFilter<>(itemName)).size() > 0; } Using the Java 8 Stream API : final boolean itemIsInArea(final Area area, final String itemName) { return getGroundItems().getAll().stream().anyMatch(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem)); } Using a for loop: final boolean itemIsInArea(final Area area, final String itemName) { for(final GroundItem groundItem : getGroundItems().getAll()) { if(groundItem.getName().equals(itemName) && area.contains(groundItem)) { return true; } } return false; } If you want to get the closest matching item in the area you can do: With the OSBot API: final Optional<GroundItem> closestItemInArea(final Area area, final String itemName) { return Optional.ofNullable(getGroundItems().closest(new AreaFilter<>(area), new NameFilter<>(itemName))); } With the Java 8 Stream API: final Optional<GroundItem> closestItemInArea(final Area area, final String itemName) { return getGroundItems().getAll() .stream() .filter(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem)) .min((g1, g2) -> Integer.compare(myPosition().distance(g1.getPosition()), myPosition().distance(g2.getPosition()))); } Or if you want to get any matching item in the area (not necessarily the closest) you can do: With the OSBot API: final Optional<GroundItem> getItemInArea(final Area area, final String itemName) { return Optional.ofNullable(getGroundItems().singleFilter(getGroundItems().getAll(), new AreaFilter<>(area), new NameFilter<>(itemName))); } With the Java 8 Stream API: final Optional<GroundItem> getItemInArea(final Area area, final String itemName) { return getGroundItems().getAll() .stream() .filter(groundItem -> groundItem.getName().equals(itemName) && area.contains(groundItem)) .findAny(); } What r u doing with ur life mane 2 Quote Link to comment Share on other sites More sharing options...
Explv Posted June 7, 2016 Share Posted June 7, 2016 What r u doing with ur life mane I was bored Quote Link to comment Share on other sites More sharing options...
Lone Posted June 7, 2016 Share Posted June 7, 2016 I was bored I don't believe Quote Link to comment Share on other sites More sharing options...
roguehippo Posted June 8, 2016 Author Share Posted June 8, 2016 I was bored wow! thank you explv! you are as helpful as ever Quote Link to comment Share on other sites More sharing options...