Skip to content

Commit

Permalink
#283 - Add POH Storage: Cape Hanger
Browse files Browse the repository at this point in the history
  • Loading branch information
Thource committed Sep 22, 2024
2 parents 365b0ba + 04cd195 commit 73fef0d
Show file tree
Hide file tree
Showing 37 changed files with 442 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.runelite.api.events.ActorDeath;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.FocusChanged;
import net.runelite.api.events.GameObjectSpawned;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.ItemContainerChanged;
Expand Down Expand Up @@ -519,6 +520,15 @@ void onGameTick(GameTick gameTick) {
SwingUtilities.invokeLater(panelContainer::softUpdate);
}

@Subscribe
void onGameObjectSpawned(GameObjectSpawned gameObjectSpawned) {
if (clientState == ClientState.LOGGED_OUT) {
return;
}

storageManagerManager.onGameObjectSpawned(gameObjectSpawned);
}

@Subscribe
void onMenuOptionClicked(MenuOptionClicked menuOption) {
if (clientState == ClientState.LOGGED_OUT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean onGameTick() {
if (itemContainerWatcher != null && itemContainerWatcher.wasJustUpdated()) {
items.clear();
items.addAll(itemContainerWatcher.getItems());
lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return true;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public boolean onItemContainerChanged(ItemContainerChanged itemContainerChanged)
}
}

lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ public enum Region {
REGION_OURANIA_HUNTER("Ourania Hunter Area", 9778),
REGION_PIRATES_COVE("Pirates' Cove", 8763),
REGION_PISCATORIS_HUNTER_AREA("Piscatoris Hunter Area", 9015, 9016, 9271, 9272, 9528),
REGION_POH("Player Owned House", 7513, 7514, 7769, 7770),
REGION_POH("Player Owned House", 7257, 7513, 7514, 7769, 7770, 8025, 8026),
REGION_POISON_WASTE("Poison Waste", 8752),
REGION_PORT_TYRAS("Port Tyras", 8496),
REGION_PURO_PURO("Puro Puro", 10307),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameObjectSpawned;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.WidgetClosed;
Expand Down Expand Up @@ -99,6 +100,10 @@ public boolean onGameTick() {
return false;
}

public boolean onGameObjectSpawned(GameObjectSpawned gameObjectSpawned) {
return false;
}

@SuppressWarnings("java:S1172") // the parameter is used in child classes
public boolean onWidgetLoaded(WidgetLoaded widgetLoaded) {
return false;
Expand Down Expand Up @@ -272,4 +277,8 @@ public long getItemCount(int canonicalId) {
return getItems().stream().filter(stack -> stack.getCanonicalId() == canonicalId)
.mapToLong(ItemStack::getQuantity).sum();
}

protected void updateLastUpdated() {
lastUpdated = System.currentTimeMillis();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.runelite.api.Client;
import net.runelite.api.events.ActorDeath;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameObjectSpawned;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.ItemDespawned;
Expand Down Expand Up @@ -75,6 +76,16 @@ public void onGameTick() {
}
}

/** Pass onGameObjectSpawned through to enabled storages. */
public void onGameObjectSpawned(GameObjectSpawned gameObjectSpawned) {
if (enabled) {
updateStorages(
storages.stream()
.filter(storage -> storage.isEnabled() && storage.onGameObjectSpawned(gameObjectSpawned))
.collect(Collectors.toList()));
}
}

/** Pass onWidgetLoaded through to enabled storages. */
public void onWidgetLoaded(WidgetLoaded widgetLoaded) {
if (enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.events.ActorDeath;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.GameObjectSpawned;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.ItemContainerChanged;
import net.runelite.api.events.ItemDespawned;
Expand Down Expand Up @@ -147,6 +148,10 @@ public void onGameTick() {
storageManagers.forEach(StorageManager::onGameTick);
}

public void onGameObjectSpawned(GameObjectSpawned gameObjectSpawned) {
storageManagers.forEach(m -> m.onGameObjectSpawned(gameObjectSpawned));
}

public void onWidgetLoaded(WidgetLoaded widgetLoaded) {
storageManagers.forEach(manager -> manager.onWidgetLoaded(widgetLoaded));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean onGameTick() {
compostStack.setQuantity(0);
supercompostStack.setQuantity(0);
ultracompostStack.setQuantity(0);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand All @@ -71,7 +71,7 @@ public boolean onGameTick() {
compostStack.setQuantity(0);
supercompostStack.setQuantity(0);
ultracompostStack.setQuantity(0);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();

if (widgetText.contains("ultracompost")) {
ultracompostStack.setQuantity(charges);
Expand Down Expand Up @@ -99,7 +99,7 @@ public void updateCompost(int type, int charges) {
compostStack.setQuantity(0);
supercompostStack.setQuantity(0);
ultracompostStack.setQuantity(0);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();

if (type == 2) {
compostStack.setQuantity(charges);
Expand All @@ -125,7 +125,7 @@ public boolean onChatMessage(ChatMessage chatMessage) {
compostStack.setQuantity(0);
supercompostStack.setQuantity(0);
ultracompostStack.setQuantity(0);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand All @@ -140,7 +140,7 @@ public boolean onChatMessage(ChatMessage chatMessage) {
compostStack.setQuantity(0);
supercompostStack.setQuantity(0);
ultracompostStack.setQuantity(0);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();

if (chatMessage.getMessage().contains("ultracompost")) {
ultracompostStack.setQuantity(charges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean onGameTick() {

if (widgetText.contains("is empty")) {
items.forEach(itemStack -> itemStack.setQuantity(0));
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand All @@ -65,7 +65,7 @@ public boolean onGameTick() {
}

itemStack.get().setQuantity(charges);
lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return true;
}
Expand All @@ -82,7 +82,7 @@ public boolean onChatMessage(ChatMessage chatMessage) {
}

items.forEach(itemStack -> itemStack.setQuantity(0));
lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean onGameTick() {
Widget emptyText = lootingBagWidget.getChild(28);
if (emptyText != null && Objects.equals(emptyText.getText(), "The bag is empty.")) {
items.clear();
lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return true;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ private boolean checkUsedItems() {
}

if (updated) {
lastUpdated = System.currentTimeMillis();
updateLastUpdated();
}

return updated;
Expand All @@ -102,7 +102,7 @@ private boolean checkForDeposit() {
}

if (updated) {
lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public boolean onChatMessage(ChatMessage chatMessage) {
oakPlankStack.setQuantity(0);
teakPlankStack.setQuantity(0);
mahoganyPlankStack.setQuantity(0);
lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand All @@ -70,7 +70,7 @@ public boolean onChatMessage(ChatMessage chatMessage) {
oakPlankStack.setQuantity(NumberUtils.toInt(matcher.group(2)));
teakPlankStack.setQuantity(NumberUtils.toInt(matcher.group(3)));
mahoganyPlankStack.setQuantity(NumberUtils.toInt(matcher.group(4)));
lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean onGameTick() {
}

items.clear();
lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand Down Expand Up @@ -85,7 +85,7 @@ private boolean checkForAdditions(String chatMessage) {

ItemStackUtils.addItemStack(
items, new ItemStack(optionalSeed.get().getItemId(), quantity, plugin));
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand All @@ -107,7 +107,7 @@ private boolean checkForRemovals(String chatMessage) {

ItemStackUtils.removeItemStack(
items, new ItemStack(optionalSeed.get().getItemId(), quantity, plugin));
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public boolean updateFromMain() {

int parsedCoins = NumberUtils.toInt(textWidget.getText().replaceAll("\\D+", ""), 0);
this.getCoinStack().setQuantity(parsedCoins);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand All @@ -56,7 +56,7 @@ public boolean updateFromDepositWithdraw() {

int parsedCoins = NumberUtils.toInt(matcher.group(1), 0);
this.getCoinStack().setQuantity(parsedCoins);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public boolean onGameTick() {
itemContainerWatcher.getItems().stream().filter(i -> i.getId() == 995).findFirst();
coinStack.setQuantity(coinsItem.map(ItemStack::getQuantity).orElse(0L));

lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return true;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ public boolean onItemContainerChanged(ItemContainerChanged itemContainerChanged)
return false;
}

lastUpdated = System.currentTimeMillis();
updateLastUpdated();
int coins = itemContainer.count(995);
if (coinStack.getQuantity() == coins) {
return !this.getType().isAutomatic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private boolean updateFromCollectWindow() {

long oldValue = coinStack.getQuantity();
coinStack.setQuantity(IntStream.range(0, 8).mapToLong(this::getCoinsInCollectSlot).sum());
lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return oldValue != coinStack.getQuantity();
}
Expand All @@ -54,7 +54,7 @@ private boolean updateFromGrandExchangeWindow() {

long oldValue = coinStack.getQuantity();
coinStack.setQuantity(IntStream.range(0, 8).mapToLong(this::getCoinsInGrandExchangeSlot).sum());
lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return oldValue != coinStack.getQuantity();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean onGameTick() {
}

coinStack.setQuantity(0);
lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public boolean onGameTick() {

int parsedCoins = NumberUtils.toInt(widget.getText().replaceAll("\\D+", ""), 0);
this.getCoinStack().setQuantity(parsedCoins);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public boolean onGameTick() {

int parsedCoins = NumberUtils.toInt(textWidget.getText().replaceAll("\\D+", ""), 0);
this.getCoinStack().setQuantity(parsedCoins);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public boolean onGameTick() {
Widget shopWidget = plugin.getClient().getWidget(753, 13);
if (shopWidget != null) {
points.setQuantity(Integer.parseInt(shopWidget.getText()));
lastUpdated = System.currentTimeMillis();
updateLastUpdated();
return true;
}

Expand All @@ -40,7 +40,7 @@ public boolean onGameTick() {
Matcher matcher = HAND_IN_PATTERN.matcher(chatWidget.getText());
if (matcher.find()) {
points.setQuantity(points.getQuantity() + NumberUtils.toInt(matcher.group(1)));
lastUpdated = System.currentTimeMillis();
updateLastUpdated();
didJustHandIn = true;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean onGameTick() {
final long lastCatalyticEnergy = catalyticEnergy.getQuantity();
elementalEnergy.setQuantity(NumberUtils.toInt(matcher.group(2), 0));
catalyticEnergy.setQuantity(NumberUtils.toInt(matcher.group(1), 0));
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return lastElementalEnergy != elementalEnergy.getQuantity()
|| lastCatalyticEnergy != catalyticEnergy.getQuantity();
Expand All @@ -82,7 +82,7 @@ public boolean onChatMessage(ChatMessage chatMessage) {

elementalEnergy.setQuantity(elementalEnergy.getQuantity() - 1);
catalyticEnergy.setQuantity(catalyticEnergy.getQuantity() - 1);
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return true;
}
Expand All @@ -96,7 +96,7 @@ public boolean onChatMessage(ChatMessage chatMessage) {
final long lastCatalyticEnergy = catalyticEnergy.getQuantity();
elementalEnergy.setQuantity(NumberUtils.toInt(matcher.group(1), 0));
catalyticEnergy.setQuantity(NumberUtils.toInt(matcher.group(2), 0));
this.lastUpdated = System.currentTimeMillis();
updateLastUpdated();

return lastElementalEnergy != elementalEnergy.getQuantity()
|| lastCatalyticEnergy != catalyticEnergy.getQuantity();
Expand Down
Loading

0 comments on commit 73fef0d

Please sign in to comment.