Skip to content

Commit

Permalink
ge plugin: ignore offers being cleared on logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Jun 4, 2020
1 parent c2f80ed commit 0bc95fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ public void onGrandExchangeOfferChanged(GrandExchangeOfferChanged offerEvent)
final int slot = offerEvent.getSlot();
final GrandExchangeOffer offer = offerEvent.getOffer();

if (offer.getState() == GrandExchangeOfferState.EMPTY && client.getGameState() != GameState.LOGGED_IN)
{
// Trades are cleared by the client during LOGIN_SCREEN/HOPPING/LOGGING_IN, ignore those so we don't
// zero and re-submit the trade on login as an update
return;
}

log.debug("GE offer updated: state: {}, slot: {}, item: {}, qty: {}, login: {}",
offer.getState(), slot, offer.getItemId(), offer.getQuantitySold(), loginBurstGeUpdates);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@
import java.util.concurrent.ScheduledExecutorService;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.GrandExchangeOffer;
import net.runelite.api.GrandExchangeOfferState;
import net.runelite.api.ItemID;
import net.runelite.api.WorldType;
import net.runelite.api.events.GrandExchangeOfferChanged;
import net.runelite.client.Notifier;
import net.runelite.client.account.SessionManager;
import net.runelite.client.config.ConfigManager;
Expand All @@ -55,6 +57,7 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import org.mockito.Mock;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -218,4 +221,20 @@ public void testCancelTrade()
assertEquals(10, trade.getTotal());
assertEquals(25, trade.getSpent());
}

@Test
public void testHop()
{
when(client.getGameState()).thenReturn(GameState.HOPPING);

GrandExchangeOffer grandExchangeOffer = mock(GrandExchangeOffer.class);
when(grandExchangeOffer.getState()).thenReturn(GrandExchangeOfferState.EMPTY);

GrandExchangeOfferChanged grandExchangeOfferChanged = new GrandExchangeOfferChanged();
grandExchangeOfferChanged.setOffer(grandExchangeOffer);

grandExchangePlugin.onGrandExchangeOfferChanged(grandExchangeOfferChanged);

verify(configManager, never()).unsetConfiguration(anyString(), anyString());
}
}

0 comments on commit 0bc95fa

Please sign in to comment.