Skip to content

Commit

Permalink
testing item container fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-Vann committed Aug 17, 2023
1 parent 52d41a1 commit 5bf5468
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/com/example/EthanApiPlugin/Collections/Bank.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
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;
import net.runelite.client.RuneLite;
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 {
static Client client = RuneLite.getInjector().getInstance(Client.class);
static List<Widget> 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()));
Expand Down

0 comments on commit 5bf5468

Please sign in to comment.