From 5bf54686e9e4dc7aab92ca0976cce5c69dc66800 Mon Sep 17 00:00:00 2001 From: Ethan Vann Date: Thu, 17 Aug 2023 06:25:50 -0400 Subject: [PATCH] testing item container fixes --- .../EthanApiPlugin/Collections/Bank.java | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/EthanApiPlugin/Collections/Bank.java b/src/main/java/com/example/EthanApiPlugin/Collections/Bank.java index 9ac2aa096..777455a11 100644 --- a/src/main/java/com/example/EthanApiPlugin/Collections/Bank.java +++ b/src/main/java/com/example/EthanApiPlugin/Collections/Bank.java @@ -1,8 +1,11 @@ package com.example.EthanApiPlugin.Collections; import com.example.EthanApiPlugin.Collections.query.ItemQuery; +import com.example.EthanApiPlugin.EthanApiPlugin; import net.runelite.api.Client; import net.runelite.api.GameState; +import net.runelite.api.InventoryID; +import net.runelite.api.Item; import net.runelite.api.events.GameStateChanged; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetInfo; @@ -10,9 +13,9 @@ import net.runelite.client.eventbus.Subscribe; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; public class Bank { @@ -20,10 +23,27 @@ public class Bank { static List bankItems = new ArrayList<>(); boolean bankUpdate = true; static int lastUpdateTick = 0; + public static ItemQuery search() { if (lastUpdateTick < client.getTickCount()) { - bankItems = - Arrays.stream(client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER).getDynamicChildren()).filter(Objects::nonNull).filter(x -> x.getItemId() != 6512 && x.getItemId() != -1).collect(Collectors.toList()); + Bank.bankItems.clear(); + int i = 0; + for (Item item : client.getItemContainer(InventoryID.BANK).getItems()) { + try { + if (item == null) { + i++; + continue; + } + if (EthanApiPlugin.itemDefs.get(item.getId()).getPlaceholderTemplateId() == 14401) { + i++; + continue; + } + Bank.bankItems.add(new BankItemWidget(EthanApiPlugin.itemDefs.get(item.getId()).getName(), item.getId(), item.getQuantity(), i)); + } catch (NullPointerException | ExecutionException ex) { + //todo fix this + } + i++; + } lastUpdateTick = client.getTickCount(); } return new ItemQuery(bankItems.stream().filter(Objects::nonNull).collect(Collectors.toList()));