SlayerPlugin extends Plugin { @Subscribe public void onStatChanged(StatChanged statChanged) { if (statChanged.getSkill() != SLAYER) { return; } int slayerExp = statChanged.getXp(); if (slayerExp <= cachedXp) { return; } if (cachedXp == -1) { cachedXp = slayerExp; return; } final int delta = slayerExp - cachedXp; cachedXp = slayerExp; log.debug("Slayer xp change delta: {}, killed npcs: {}", delta, taggedNpcsDiedPrevTick); final Task task = Task.getTask(taskName); if (task != null && task.getExpectedKillExp() > 0) { if (task.getExpectedKillExp() == delta) { killed(1); } } else { killed(max(taggedNpcsDiedPrevTick, 1)); } }  @Subscribe void onGameStateChanged(GameStateChanged event); @Subscribe void onNpcSpawned(NpcSpawned npcSpawned); @Subscribe void onNpcDespawned(NpcDespawned npcDespawned); @Subscribe void onGameTick(GameTick tick); @Subscribe void onChatMessage(ChatMessage event); @Subscribe void onStatChanged(StatChanged statChanged); @Subscribe void onHitsplatApplied(HitsplatApplied hitsplatApplied); @Subscribe void onActorDeath(ActorDeath actorDeath);  }
@Test public void testCorrectlyCapturedTaskKill() { final Player player = mock(Player.class); when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0)); when(client.getLocalPlayer()).thenReturn(player); StatChanged statChanged = new StatChanged( Skill.SLAYER, 100, 2, 2 ); slayerPlugin.onStatChanged(statChanged); slayerPlugin.setTaskName("Dagannoth"); slayerPlugin.setAmount(143); statChanged = new StatChanged( Skill.SLAYER, 110, 2, 2 ); slayerPlugin.onStatChanged(statChanged); assertEquals(142, slayerPlugin.getAmount()); }
@Test public void testIncorrectlyCapturedTaskKill() { final Player player = mock(Player.class); when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0)); when(client.getLocalPlayer()).thenReturn(player); StatChanged statChanged = new StatChanged( Skill.SLAYER, 100, 2, 2 ); slayerPlugin.onStatChanged(statChanged); slayerPlugin.setTaskName("Monster"); slayerPlugin.setAmount(98); assert Task.getTask("Monster") == null; statChanged = new StatChanged( Skill.SLAYER, 110, 2, 2 ); slayerPlugin.onStatChanged(statChanged); assertEquals(97, slayerPlugin.getAmount()); }
@Test public void testJadTaskKill() { final Player player = mock(Player.class); when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0)); when(client.getLocalPlayer()).thenReturn(player); StatChanged statChanged = new StatChanged( Skill.SLAYER, 100, 2, 2 ); slayerPlugin.onStatChanged(statChanged); slayerPlugin.setTaskName("TzTok-Jad"); slayerPlugin.setAmount(1); statChanged = new StatChanged( Skill.SLAYER, 110, 2, 2 ); slayerPlugin.onStatChanged(statChanged); assertEquals(1, slayerPlugin.getAmount()); statChanged = new StatChanged( Skill.SLAYER, 25360, -1, -1 ); slayerPlugin.onStatChanged(statChanged); assertEquals(0, slayerPlugin.getAmount()); }
@Test public void testZukTaskKill() { final Player player = mock(Player.class); when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0)); when(client.getLocalPlayer()).thenReturn(player); StatChanged statChanged = new StatChanged( Skill.SLAYER, 110, 2, 2 ); slayerPlugin.onStatChanged(statChanged); slayerPlugin.setTaskName("TzKal-Zuk"); slayerPlugin.setAmount(1); statChanged = new StatChanged( Skill.SLAYER, 125, 2, 2 ); slayerPlugin.onStatChanged(statChanged); assertEquals(1, slayerPlugin.getAmount()); statChanged = new StatChanged( Skill.SLAYER, 102_015, -1, -1 ); slayerPlugin.onStatChanged(statChanged); assertEquals(0, slayerPlugin.getAmount()); }
@Test public void testNewAccountSlayerKill() { final Player player = mock(Player.class); when(player.getLocalLocation()).thenReturn(new LocalPoint(0, 0)); when(client.getLocalPlayer()).thenReturn(player); slayerPlugin.setTaskName("Bears"); slayerPlugin.setAmount(35); StatChanged statChanged = new StatChanged( Skill.SLAYER, 0, 1, 1 ); slayerPlugin.onStatChanged(statChanged); statChanged = new StatChanged( Skill.SLAYER, 27, 1, 1 ); slayerPlugin.onStatChanged(statChanged); assertEquals(34, slayerPlugin.getAmount()); }