bootstrap iutils: add additional filters to EquipmentItemStream and InventoryItemStream

UtilsScript add new inventory and equipment check methods
This commit is contained in:
illumineawake 2021-08-22 18:57:01 +10:00
parent 2c9943d629
commit fbb77126c7
6 changed files with 33 additions and 28 deletions

View File

@ -23,7 +23,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
version = "4.4.8"
version = "4.4.9"
project.extra["PluginName"] = "iUtils"
project.extra["PluginDescription"] = "Illumine - Utils required for plugins to function with added automation"

View File

@ -17,10 +17,7 @@ import net.runelite.client.plugins.iutils.walking.Walking;
import javax.inject.Inject;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@ -37,7 +34,7 @@ public abstract class UtilsScript extends Plugin {
protected Equipment equipment;
@Inject
protected Combat combat;
// @Inject
// @Inject
protected StandardSpellbook standardSpellbook;
@Inject
protected Prayers prayers;
@ -109,11 +106,10 @@ public abstract class UtilsScript extends Plugin {
}
protected void obtain(List<ItemQuantity> items) {
if (items.isEmpty() ||
Items(items)) {
if (items.isEmpty() || hasItems(items)) {
return;
}
obtain(items.toArray(ItemQuantity[]::new));
}
@ -193,27 +189,27 @@ public abstract class UtilsScript extends Plugin {
return bankItem == null ? 0 : bankItem.quantity();
}
protected boolean equipmentHasItemsID(Integer items) {
return game.equipment().withId(items).findFirst().isPresent();
protected boolean equipmentHasItem(int... ids) {
return game.equipment().withId(ids).findFirst().isPresent();
}
protected boolean equipmentHasItemsID(Collection<Integer> items) {
protected boolean equipmentHasItem(Collection<Integer> items) {
return game.equipment().withId(items).findFirst().isPresent();
}
protected boolean inventoryHasItemsName(String items) {
return game.inventory().withNamePart(items).findFirst().isPresent();
}
protected boolean inventoryHasItemsName(Collection<String> items) {
for (String item : items) {
return game.inventory().withNamePart(item).findFirst().isPresent();
}
return false;
protected boolean inventoryHasItem(String... names) {
return game.inventory().withNamePart(names).findFirst().isPresent();
}
protected boolean inventoryHasItems(Integer items) {
return game.inventory().withId(items).findFirst().isPresent();
protected boolean inventoryHasItemName(Collection<String> names) {
return game.inventory().withNamePart(names).findFirst().isPresent();
}
protected boolean inventoryHasItems(Collection<Integer> items) {
protected boolean inventoryHasItem(int... ids) {
return game.inventory().withId(ids).findFirst().isPresent();
}
protected boolean inventoryHasItem(Collection<Integer> items) {
return game.inventory().withId(items).findFirst().isPresent();
}

View File

@ -5,6 +5,7 @@ import net.runelite.client.plugins.iutils.game.EquipmentItem;
import net.runelite.client.plugins.iutils.util.RandomizedStreamAdapter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Objects;
import java.util.stream.Stream;
@ -27,14 +28,14 @@ public class EquipmentItemStream extends RandomizedStreamAdapter<EquipmentItem,
}
/**
* Returns a stream consisting of the elements of this stream with
* any of the given {@link InventoryItem#id()}s
* any of the given {@link EquipmentItem#id()}s
*/
public EquipmentItemStream withId(Collection<Integer> ids) {
return filter(o -> ids.stream().anyMatch(id -> o.id() == id));
}
/**
* Returns a stream consisting of the elements of this stream that don't match
* any of the given {@link InventoryItem#id()}s
* any of the given {@link EquipmentItem#id()}s
*/
public EquipmentItemStream withoutId(Collection<Integer> ids) {
return filter(o -> ids.stream().noneMatch(id -> o.id() == id));
@ -42,7 +43,7 @@ public class EquipmentItemStream extends RandomizedStreamAdapter<EquipmentItem,
/**
* Returns a stream consisting of the elements of this stream that don't match
* any of the given {@link InventoryItem#id()}s
* any of the given {@link EquipmentItem#id()}s
*/
public EquipmentItemStream withoutId(int... ids) {
return filter(o -> Arrays.stream(ids).noneMatch(id -> o.id() == id));
@ -72,7 +73,7 @@ public class EquipmentItemStream extends RandomizedStreamAdapter<EquipmentItem,
}
/**
* Returns a stream consisting of the elements of this stream that don't match
* any of the given {@link InventoryItem#name()}s
* any of the given {@link EquipmentItem#name()}s
*/
public EquipmentItemStream withoutNamePart(String... names) {
return filter(o -> Arrays.stream(names).noneMatch(name -> o.name().toLowerCase().contains(name.toLowerCase())));

View File

@ -75,6 +75,14 @@ public class InventoryItemStream extends RandomizedStreamAdapter<InventoryItem,
return filter(o -> Arrays.stream(names).anyMatch(name -> o.name().toLowerCase().contains(name.toLowerCase())));
}
/**
* Returns a stream consisting of the elements of this stream whose
* {@link InventoryItem#name()}s contain any of the given name parts
*/
public InventoryItemStream withNamePart(Collection<String> names) {
return filter(o -> names.stream().anyMatch(name -> o.name().toLowerCase().contains(name.toLowerCase())));
}
/**
* Returns a stream consisting of the elements of this stream that don't match
* any of the given {@link InventoryItem#name()}s

File diff suppressed because one or more lines are too long