BankTagsPlugin extends Plugin implements MouseWheelListener { @Subscribe public void onScriptCallbackEvent(ScriptCallbackEvent event) { String eventName = event.getEventName(); int[] intStack = client.getIntStack(); String[] stringStack = client.getStringStack(); int intStackSize = client.getIntStackSize(); int stringStackSize = client.getStringStackSize(); tabInterface.handleScriptEvent(event); switch (eventName) { case "setSearchBankInputText": stringStack[stringStackSize - 1] = SEARCH_BANK_INPUT_TEXT; break; case "setSearchBankInputTextFound": { int matches = intStack[intStackSize - 1]; stringStack[stringStackSize - 1] = String.format(SEARCH_BANK_INPUT_TEXT_FOUND, matches); break; } case "bankSearchFilter": final int itemId = intStack[intStackSize - 1]; final String searchfilter = stringStack[stringStackSize - 1]; TagTab activeTab = tabInterface.getActiveTab(); String search = activeTab != null ? TAG_SEARCH + activeTab.getTag() : searchfilter; if (search.isEmpty()) { return; } boolean tagSearch = search.startsWith(TAG_SEARCH); if (tagSearch) { search = search.substring(TAG_SEARCH.length()).trim(); } if (tagManager.findTag(itemId, search)) { intStack[intStackSize - 2] = 1; } else if (tagSearch) { intStack[intStackSize - 2] = 0; } break; case "getSearchingTagTab": intStack[intStackSize - 1] = tabInterface.isActive() ? 1 : 0; break; } }  @Override void resetConfiguration(); @Override void startUp(); @Override void shutDown(); @Subscribe void onGrandExchangeSearched(GrandExchangeSearched event); @Subscribe void onScriptCallbackEvent(ScriptCallbackEvent event); @Subscribe void onMenuEntryAdded(MenuEntryAdded event); @Subscribe void onMenuOptionClicked(MenuOptionClicked event); @Subscribe void onConfigChanged(ConfigChanged configChanged); @Subscribe void onScriptPreFired(ScriptPreFired event); @Subscribe void onScriptPostFired(ScriptPostFired event); @Subscribe void onGameTick(GameTick event); @Subscribe void onDraggingWidgetChanged(DraggingWidgetChanged event); @Subscribe void onWidgetLoaded(WidgetLoaded event); @Override MouseWheelEvent mouseWheelMoved(MouseWheelEvent event); static final String CONFIG_GROUP; static final String TAG_SEARCH; static final String ICON_SEARCH; static final String TAG_TABS_CONFIG; static final String VAR_TAG_SUFFIX; }
@Test public void testExplicitSearch() { when(client.getIntStack()).thenReturn(new int[]{0, ABYSSAL_WHIP}); when(client.getStringStack()).thenReturn(new String[]{"tag:whip"}); when(configManager.getConfiguration(BankTagsPlugin.CONFIG_GROUP, TagManager.ITEM_KEY_PREFIX + ABYSSAL_WHIP)).thenReturn("herb,bossing,whip"); bankTagsPlugin.onScriptCallbackEvent(EVENT); assertEquals(1, client.getIntStack()[0]); when(client.getIntStack()).thenReturn(new int[]{0, ABYSSAL_WHIP}); when(configManager.getConfiguration(BankTagsPlugin.CONFIG_GROUP, TagManager.ITEM_KEY_PREFIX + ABYSSAL_WHIP)).thenReturn("herb,bossing,whip long tag"); bankTagsPlugin.onScriptCallbackEvent(EVENT); assertEquals(1, client.getIntStack()[0]); when(configManager.getConfiguration(BankTagsPlugin.CONFIG_GROUP, TagManager.ITEM_KEY_PREFIX + ABYSSAL_WHIP)).thenReturn("herb,bossing whip"); bankTagsPlugin.onScriptCallbackEvent(EVENT); assertEquals(0, client.getIntStack()[0]); }
@Test public void testFallThrough() { when(client.getIntStack()).thenReturn(new int[]{1, ABYSSAL_WHIP}); when(client.getStringStack()).thenReturn(new String[]{"whip"}); when(configManager.getConfiguration(BankTagsPlugin.CONFIG_GROUP, TagManager.ITEM_KEY_PREFIX + ABYSSAL_WHIP)).thenReturn("herb,bossing"); assertFalse(tagManager.findTag(ABYSSAL_WHIP, "whip")); bankTagsPlugin.onScriptCallbackEvent(EVENT); assertEquals(1, client.getIntStack()[0]); }
@Test public void testNonExplicitSearch() { when(client.getIntStack()).thenReturn(new int[]{0, ABYSSAL_WHIP}); when(client.getStringStack()).thenReturn(new String[]{"whip"}); when(configManager.getConfiguration(BankTagsPlugin.CONFIG_GROUP, TagManager.ITEM_KEY_PREFIX + ABYSSAL_WHIP)).thenReturn("herb,bossing,whip long tag"); bankTagsPlugin.onScriptCallbackEvent(EVENT); assertEquals(1, client.getIntStack()[0]); }