LootTrackerPlugin extends Plugin { @Subscribe public void onChatMessage(ChatMessage event) { if (event.getType() != ChatMessageType.GAMEMESSAGE && event.getType() != ChatMessageType.SPAM) { return; } final String message = event.getMessage(); if (message.equals(CHEST_LOOTED_MESSAGE) || message.equals(STONE_CHEST_LOOTED_MESSAGE) || message.equals(DORGESH_KAAN_CHEST_LOOTED_MESSAGE) || message.startsWith(GRUBBY_CHEST_LOOTED_MESSAGE) || LARRAN_LOOTED_PATTERN.matcher(message).matches()) { final int regionID = client.getLocalPlayer().getWorldLocation().getRegionID(); if (!CHEST_EVENT_TYPES.containsKey(regionID)) { return; } setEvent(LootRecordType.EVENT, CHEST_EVENT_TYPES.get(regionID)); takeInventorySnapshot(); return; } if (message.equals(COFFIN_LOOTED_MESSAGE) && isPlayerWithinMapRegion(HALLOWED_SEPULCHRE_MAP_REGIONS)) { setEvent(LootRecordType.EVENT, HALLOWED_SEPULCHRE_COFFIN_EVENT); takeInventorySnapshot(); return; } if (message.equals(HERBIBOAR_LOOTED_MESSAGE)) { if (processHerbiboarHerbSackLoot(event.getTimestamp())) { return; } setEvent(LootRecordType.EVENT, HERBIBOAR_EVENT, client.getBoostedSkillLevel(Skill.HERBLORE)); takeInventorySnapshot(); return; } final int regionID = client.getLocalPlayer().getWorldLocation().getRegionID(); if (HESPORI_REGION == regionID && message.equals(HESPORI_LOOTED_MESSAGE)) { setEvent(LootRecordType.EVENT, HESPORI_EVENT); takeInventorySnapshot(); return; } final Matcher hamStoreroomMatcher = HAM_CHEST_LOOTED_PATTERN.matcher(message); if (hamStoreroomMatcher.matches() && regionID == HAM_STOREROOM_REGION) { String keyType = hamStoreroomMatcher.group("key"); setEvent(LootRecordType.EVENT, String.format("H.A.M. chest (%s)", keyType)); takeInventorySnapshot(); return; } final Matcher pickpocketMatcher = PICKPOCKET_REGEX.matcher(message); if (pickpocketMatcher.matches()) { String pickpocketTarget = WordUtils.capitalize(pickpocketMatcher.group("target")); if (PICKPOCKET_DISAMBIGUATION_MAP.get(lastPickpocketTarget).contains(pickpocketTarget)) { setEvent(LootRecordType.PICKPOCKET, lastPickpocketTarget); } else { setEvent(LootRecordType.PICKPOCKET, pickpocketTarget); } takeInventorySnapshot(); return; } final Matcher m = CLUE_SCROLL_PATTERN.matcher(Text.removeTags(message)); if (m.find()) { final String type = m.group(1).toLowerCase(); switch (type) { case "beginner": setEvent(LootRecordType.EVENT, "Clue Scroll (Beginner)"); return; case "easy": setEvent(LootRecordType.EVENT, "Clue Scroll (Easy)"); return; case "medium": setEvent(LootRecordType.EVENT, "Clue Scroll (Medium)"); return; case "hard": setEvent(LootRecordType.EVENT, "Clue Scroll (Hard)"); return; case "elite": setEvent(LootRecordType.EVENT, "Clue Scroll (Elite)"); return; case "master": setEvent(LootRecordType.EVENT, "Clue Scroll (Master)"); return; } } if (SHADE_CHEST_NO_KEY_PATTERN.matcher(message).matches()) { resetEvent(); return; } final Matcher matcher = BIRDHOUSE_PATTERN.matcher(message); if (matcher.matches()) { final int xp = Integer.parseInt(matcher.group(1)); final String type = BIRDHOUSE_XP_TO_TYPE.get(xp); if (type == null) { log.debug("Unknown bird house type {}", xp); return; } setEvent(LootRecordType.EVENT, type, client.getRealSkillLevel(Skill.HUNTER)); takeInventorySnapshot(); } }  @Subscribe void onSessionOpen(SessionOpen sessionOpen); @Subscribe void onSessionClose(SessionClose sessionClose); @Subscribe void onConfigChanged(ConfigChanged event); @Subscribe void onClientShutdown(ClientShutdown event); @Subscribe void onGameStateChanged(final GameStateChanged event); @Subscribe void onNpcLootReceived(final NpcLootReceived npcLootReceived); @Subscribe void onPlayerLootReceived(final PlayerLootReceived playerLootReceived); @Subscribe void onWidgetLoaded(WidgetLoaded widgetLoaded); @Subscribe void onChatMessage(ChatMessage event); @Subscribe void onItemContainerChanged(ItemContainerChanged event); @Subscribe void onMenuOptionClicked(MenuOptionClicked event); @Schedule( period = 5, unit = ChronoUnit.MINUTES, asynchronous = true ) void submitLootTask();  }
@Test public void testPickPocket() { ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You pick the hero's pocket.", "", 0); lootTrackerPlugin.onChatMessage(chatMessage); assertEquals("Hero", lootTrackerPlugin.eventType); assertEquals(LootRecordType.PICKPOCKET, lootTrackerPlugin.lootRecordType); }
@Test public void testFirstClue() { ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.GAMEMESSAGE, "", "You have completed 1 master Treasure Trail.", "", 0); lootTrackerPlugin.onChatMessage(chatMessage); assertEquals("Clue Scroll (Master)", lootTrackerPlugin.eventType); assertEquals(LootRecordType.EVENT, lootTrackerPlugin.lootRecordType); }
@Test public void testBirdhouses() { ChatMessage chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You dismantle and discard the trap, retrieving 10 dead birds, 30 feathers and 1140 Hunter XP.", "", 0); lootTrackerPlugin.onChatMessage(chatMessage); assertEquals("Magic Bird House", lootTrackerPlugin.eventType); assertEquals(LootRecordType.EVENT, lootTrackerPlugin.lootRecordType); chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You dismantle and discard the trap, retrieving a nest, 10 dead birds, 50 feathers and 700 Hunter XP.", "", 0); lootTrackerPlugin.onChatMessage(chatMessage); assertEquals("Teak Bird House", lootTrackerPlugin.eventType); assertEquals(LootRecordType.EVENT, lootTrackerPlugin.lootRecordType); chatMessage = new ChatMessage(null, ChatMessageType.SPAM, "", "You dismantle and discard the trap, retrieving 2 nests, 10 dead birds, 40 feathers and 280 Hunter XP.", "", 0); lootTrackerPlugin.onChatMessage(chatMessage); assertEquals("Regular Bird House", lootTrackerPlugin.eventType); assertEquals(LootRecordType.EVENT, lootTrackerPlugin.lootRecordType); }