diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index 09610e774e..01b29fe814 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -69,7 +69,7 @@ import net.runelite.api.events.WidgetLoaded; import net.runelite.api.vars.AccountType; import net.runelite.api.widgets.Widget; import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID; -import static net.runelite.api.widgets.WidgetID.GENERIC_SCROLL_GROUP_ID; +import static net.runelite.api.widgets.WidgetID.DIARY_QUEST_GROUP_ID; import static net.runelite.api.widgets.WidgetID.KILL_LOGS_GROUP_ID; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.callback.ClientThread; @@ -109,9 +109,9 @@ import org.apache.commons.text.WordUtils; public class ChatCommandsPlugin extends Plugin { private static final Pattern KILLCOUNT_PATTERN = Pattern.compile("Your (?:completion count for |subdued |completed )?(.+?) (?:(?:kill|harvest|lap|completion) )?(?:count )?is: (\\d+)"); - private static final String COX_TEAM_SIZES = "(?:\\d+(?:\\+|-\\d+)? players|Solo)"; - private static final Pattern RAIDS_PB_PATTERN = Pattern.compile("Congratulations - your raid is complete!
Team size: " + COX_TEAM_SIZES + " Duration: (?[0-9:]+(?:\\.[0-9]+)?) \\(new personal best\\)"); - private static final Pattern RAIDS_DURATION_PATTERN = Pattern.compile("Congratulations - your raid is complete!
Team size: " + COX_TEAM_SIZES + " Duration: [0-9:.]+ Personal best: (?[0-9:]+(?:\\.[0-9]+)?)"); + private static final String TEAM_SIZES = "(?:\\d+(?:\\+|-\\d+)? players|Solo)"; + private static final Pattern RAIDS_PB_PATTERN = Pattern.compile("Congratulations - your raid is complete!
Team size: " + TEAM_SIZES + " Duration: (?[0-9:]+(?:\\.[0-9]+)?) \\(new personal best\\)"); + private static final Pattern RAIDS_DURATION_PATTERN = Pattern.compile("Congratulations - your raid is complete!
Team size: " + TEAM_SIZES + " Duration: [0-9:.]+ Personal best: (?[0-9:]+(?:\\.[0-9]+)?)"); private static final Pattern TOB_WAVE_PB_PATTERN = Pattern.compile("Theatre of Blood wave completion time: (?[0-9:]+(?:\\.[0-9]+)?) \\(new personal best\\)"); private static final Pattern TOB_WAVE_DURATION_PATTERN = Pattern.compile("Theatre of Blood wave completion time: [0-9:.]+\\. Personal best: (?[0-9:]+(?:\\.[0-9]+)?)"); private static final Pattern KILL_DURATION_PATTERN = Pattern.compile("(?i)(?:(?:Fight |Lap |Challenge |Corrupted challenge )?duration:|Subdued in) [0-9:.]+\\. Personal best: (?:)?(?[0-9:]+(?:\\.[0-9]+)?)"); @@ -119,9 +119,7 @@ public class ChatCommandsPlugin extends Plugin private static final Pattern DUEL_ARENA_WINS_PATTERN = Pattern.compile("You (were defeated|won)! You have(?: now)? won (\\d+) duels?"); private static final Pattern DUEL_ARENA_LOSSES_PATTERN = Pattern.compile("You have(?: now)? lost (\\d+) duels?"); private static final Pattern ADVENTURE_LOG_TITLE_PATTERN = Pattern.compile("The Exploits of (.+)"); - private static final Pattern ADVENTURE_LOG_COX_PB_PATTERN = Pattern.compile("Fastest (?:kill|run)(?: - \\(Team size: " + COX_TEAM_SIZES + "\\))?: ([0-9:]+(?:\\.[0-9]+)?)"); - private static final Pattern ADVENTURE_LOG_BOSS_PB_PATTERN = Pattern.compile("[a-zA-Z]+(?: [a-zA-Z]+)*"); - private static final Pattern ADVENTURE_LOG_PB_PATTERN = Pattern.compile("(" + ADVENTURE_LOG_BOSS_PB_PATTERN + "(?: - " + ADVENTURE_LOG_BOSS_PB_PATTERN + ")*) (?:" + ADVENTURE_LOG_COX_PB_PATTERN + "( )*)+"); + private static final Pattern ADVENTURE_LOG_PB_PATTERN = Pattern.compile("Fastest (?:kill|run)(?: - \\(Team size: " + TEAM_SIZES + "\\))?: ([0-9:]+(?:\\.[0-9]+)?)"); private static final Pattern HS_PB_PATTERN = Pattern.compile("Floor (?\\d) time: (?[0-9:]+(?:\\.[0-9]+)?)(?: \\(new personal best\\)|. Personal best: (?[0-9:]+(?:\\.[0-9]+)?))" + "(?:
Overall time: (?[0-9:]+(?:\\.[0-9]+)?)(?: \\(new personal best\\)|. Personal best: (?[0-9:]+(?:\\.[0-9]+)?)))?"); private static final Pattern HS_KC_FLOOR_PATTERN = Pattern.compile("You have completed Floor (\\d) of the Hallowed Sepulchre! Total completions: ([0-9,]+)\\."); @@ -392,6 +390,9 @@ public class ChatCommandsPlugin extends Plugin unsetPb(boss); unsetKc(boss.replace(":", ".")); unsetPb(boss.replace(":", ".")); + // Unset old story mode + unsetKc("Theatre of Blood Story Mode"); + unsetPb("Theatre of Blood Story Mode"); } setKc(renamedBoss, kc); @@ -630,37 +631,47 @@ public class ChatCommandsPlugin extends Plugin } } + // Adventure log - Counters if (scrollInterfaceLoaded) { scrollInterfaceLoaded = false; if (client.getLocalPlayer().getName().equals(pohOwner)) { - String counterText = Text.sanitizeMultilineText(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT).getText()); - Matcher mCounterText = ADVENTURE_LOG_PB_PATTERN.matcher(counterText); - while (mCounterText.find()) + Widget parent = client.getWidget(WidgetInfo.DIARY_QUEST_WIDGET_TEXT); + // Each line is a separate static child + Widget[] children = parent.getStaticChildren(); + String[] text = Arrays.stream(children) + .map(Widget::getText) + .map(Text::removeTags) + .toArray(String[]::new); + + for (int i = 0; i < text.length; ++i) { - String bossName = longBossName(mCounterText.group(1)); - if (bossName.equalsIgnoreCase("chambers of xeric") || - bossName.equalsIgnoreCase("chambers of xeric challenge mode")) + String boss = longBossName(text[i]); + double pb = Double.MAX_VALUE; + + for (i = i + 1; i < text.length; ++i) { - Matcher mCoxRuns = ADVENTURE_LOG_COX_PB_PATTERN.matcher(mCounterText.group()); - double bestPbTime = Double.MAX_VALUE; - while (mCoxRuns.find()) + String line = text[i]; + if (line.isEmpty()) { - bestPbTime = Math.min(timeStringToSeconds(mCoxRuns.group(1)), bestPbTime); + break; } - // So we don't reset people's already saved PB's if they had one before the update - double currentPb = getPb(bossName); - if (currentPb == 0 || currentPb > bestPbTime) + + // Some bosses have multiple pbs for each team size, just use the lowest + Matcher matcher = ADVENTURE_LOG_PB_PATTERN.matcher(line); + if (matcher.find()) { - setPb(bossName, bestPbTime); + double s = timeStringToSeconds(matcher.group(1)); + pb = Math.min(pb, s); } } - else + + if (pb < Double.MAX_VALUE) { - String pbTime = mCounterText.group(2); - setPb(bossName, timeStringToSeconds(pbTime)); + log.debug("Found adventure log PB for {}: {}", boss, pb); + setPb(boss, pb); } } } @@ -719,7 +730,7 @@ public class ChatCommandsPlugin extends Plugin case KILL_LOGS_GROUP_ID: bossLogLoaded = true; break; - case GENERIC_SCROLL_GROUP_ID: + case DIARY_QUEST_GROUP_ID: scrollInterfaceLoaded = true; break; } @@ -1965,13 +1976,17 @@ public class ChatCommandsPlugin extends Plugin case "raids 2": return "Theatre of Blood"; - case "Theatre of Blood: Story Mode": + case "theatre of blood: story mode": case "tob sm": case "tob story mode": case "tob story": - return "Theatre of Blood Story Mode"; + case "Theatre of Blood: Entry Mode": + case "tob em": + case "tob entry mode": + case "tob entry": + return "Theatre of Blood Entry Mode"; - case "Theatre of Blood: Hard Mode": + case "theatre of blood: hard mode": case "tob cm": case "tob hm": case "tob hard mode": diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java index a93b06a90f..53f3276b12 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java @@ -479,14 +479,14 @@ public class GrandExchangePlugin extends Plugin private WorldType getGeWorldType() { EnumSet worldTypes = client.getWorldType(); - if (worldTypes.contains(net.runelite.api.WorldType.DEADMAN)) - { - return WorldType.DEADMAN; - } - else if (worldTypes.contains(net.runelite.api.WorldType.DEADMAN_TOURNAMENT)) + if (worldTypes.contains(net.runelite.api.WorldType.DEADMAN_TOURNAMENT)) { return WorldType.DEADMAN_TOURNAMENT; } + else if (worldTypes.contains(net.runelite.api.WorldType.DEADMAN)) + { + return WorldType.DEADMAN; + } else { return null; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingMinimapOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingMinimapOverlay.java deleted file mode 100644 index ab35f9f945..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingMinimapOverlay.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018, Seth - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.client.plugins.implings; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.util.List; -import javax.inject.Inject; -import net.runelite.api.NPC; -import net.runelite.api.Point; -import net.runelite.client.ui.overlay.Overlay; -import net.runelite.client.ui.overlay.OverlayLayer; -import net.runelite.client.ui.overlay.OverlayPosition; -import net.runelite.client.ui.overlay.OverlayUtil; - -public class ImplingMinimapOverlay extends Overlay -{ - private final ImplingsPlugin plugin; - private final ImplingsConfig config; - - @Inject - private ImplingMinimapOverlay(ImplingsPlugin plugin, ImplingsConfig config) - { - setPosition(OverlayPosition.DYNAMIC); - setLayer(OverlayLayer.ABOVE_WIDGETS); - this.plugin = plugin; - this.config = config; - } - - @Override - public Dimension render(Graphics2D graphics) - { - List imps = plugin.getImplings(); - if (imps.isEmpty()) - { - return null; - } - - for (NPC imp : imps) - { - Point impLocation = imp.getMinimapLocation(); - Color color = plugin.npcToColor(imp); - if (!plugin.showNpc(imp) || impLocation == null || color == null) - { - continue; - } - - OverlayUtil.renderMinimapLocation(graphics, impLocation, color); - - if (config.showName()) - { - Point textLocation = new Point(impLocation.getX() + 1, impLocation.getY()); - OverlayUtil.renderTextLocation(graphics, textLocation, imp.getName(), color); - } - } - - return null; - } -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsConfig.java index a11ef6f7df..b9f09853a1 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsConfig.java @@ -31,13 +31,11 @@ import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; import net.runelite.client.config.ConfigSection; -/** - * - * @author robin - */ -@ConfigGroup("implings") +@ConfigGroup(ImplingsConfig.GROUP) public interface ImplingsConfig extends Config { + String GROUP = "implings"; + enum ImplingMode { NONE, diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsOverlay.java index 8f58fbe7f2..67472b2e49 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsOverlay.java @@ -28,13 +28,10 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Polygon; -import java.util.List; import javax.inject.Inject; -import net.runelite.api.Actor; import net.runelite.api.Client; -import net.runelite.api.NPC; -import net.runelite.api.Point; import net.runelite.api.Perspective; +import net.runelite.api.Point; import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.WorldPoint; import net.runelite.client.ui.overlay.Overlay; @@ -42,10 +39,7 @@ import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayUtil; -/** - * @author robin - */ -public class ImplingsOverlay extends Overlay +class ImplingsOverlay extends Overlay { private final Client client; private final ImplingsConfig config; @@ -64,25 +58,6 @@ public class ImplingsOverlay extends Overlay @Override public Dimension render(Graphics2D graphics) { - List implings = plugin.getImplings(); - - if (implings.isEmpty()) - { - return null; - } - - for (NPC imp : implings) - { - Color color = plugin.npcToColor(imp); - if (!plugin.showNpc(imp) || color == null) - { - continue; - } - - drawImp(graphics, imp, imp.getName(), color); - } - - //Draw static spawns if (config.showSpawn()) { for (ImplingSpawn spawn : ImplingSpawn.values()) @@ -126,20 +101,4 @@ public class ImplingsOverlay extends Overlay OverlayUtil.renderTextLocation(graphics, textPoint, text, color); } } - - private void drawImp(Graphics2D graphics, Actor actor, String text, Color color) - { - Polygon poly = actor.getCanvasTilePoly(); - if (poly != null) - { - OverlayUtil.renderPolygon(graphics, poly, color); - } - - Point textLocation = actor.getCanvasTextLocation(graphics, text, actor.getLogicalHeight()); - if (textLocation != null) - { - OverlayUtil.renderTextLocation(graphics, textLocation, text, color); - } - } - } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsPlugin.java index f2c25bcbda..6b671ae7d3 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/implings/ImplingsPlugin.java @@ -26,22 +26,22 @@ package net.runelite.client.plugins.implings; import com.google.inject.Provides; import java.awt.Color; -import java.util.ArrayList; -import java.util.List; +import java.util.function.Function; import javax.inject.Inject; -import lombok.AccessLevel; -import lombok.Getter; -import net.runelite.api.GameState; import net.runelite.api.NPC; -import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.NpcChanged; -import net.runelite.api.events.NpcDespawned; import net.runelite.api.events.NpcSpawned; import net.runelite.client.Notifier; +import net.runelite.client.callback.ClientThread; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.events.ConfigChanged; import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDependency; import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.plugins.npchighlight.HighlightedNpc; +import net.runelite.client.plugins.npchighlight.NpcIndicatorsPlugin; +import net.runelite.client.plugins.npchighlight.NpcIndicatorsService; import net.runelite.client.ui.overlay.OverlayManager; @PluginDescriptor( @@ -49,26 +49,45 @@ import net.runelite.client.ui.overlay.OverlayManager; description = "Highlight nearby implings on the minimap and on-screen", tags = {"hunter", "minimap", "overlay", "imp"} ) +@PluginDependency(NpcIndicatorsPlugin.class) public class ImplingsPlugin extends Plugin { - @Getter(AccessLevel.PACKAGE) - private final List implings = new ArrayList<>(); - @Inject private OverlayManager overlayManager; @Inject private ImplingsOverlay overlay; - @Inject - private ImplingMinimapOverlay minimapOverlay; - @Inject private ImplingsConfig config; @Inject private Notifier notifier; + @Inject + private NpcIndicatorsService npcIndicatorsService; + + @Inject + private ClientThread clientThread; + + public final Function isTarget = (npc) -> + { + Impling impling = Impling.findImpling(npc.getId()); + if (impling != null && showImpling(impling)) + { + Color color = implingColor(impling); + return HighlightedNpc.builder() + .npc(npc) + .highlightColor(color) + .fillColor(new Color(0, 0, 0, 50)) + .tile(true) + .name(true) + .nameOnMinimap(config.showName()) + .build(); + } + return null; + }; + @Provides ImplingsConfig getConfig(ConfigManager configManager) { @@ -79,15 +98,25 @@ public class ImplingsPlugin extends Plugin protected void startUp() { overlayManager.add(overlay); - overlayManager.add(minimapOverlay); + npcIndicatorsService.registerHighlighter(isTarget); } @Override protected void shutDown() { - implings.clear(); + npcIndicatorsService.unregisterHighlighter(isTarget); overlayManager.remove(overlay); - overlayManager.remove(minimapOverlay); + } + + @Subscribe + private void onConfigChanged(ConfigChanged event) + { + if (!event.getGroup().equals(ImplingsConfig.GROUP)) + { + return; + } + + clientThread.invoke(npcIndicatorsService::rebuild); } @Subscribe @@ -102,8 +131,6 @@ public class ImplingsPlugin extends Plugin { notifier.notify(impling.getImplingType().getName() + " impling is in the area"); } - - implings.add(npc); } } @@ -119,43 +146,11 @@ public class ImplingsPlugin extends Plugin { notifier.notify(impling.getImplingType().getName() + " impling is in the area"); } - - if (!implings.contains(npc)) - { - implings.add(npc); - } } } - @Subscribe - public void onGameStateChanged(GameStateChanged event) + private boolean showImpling(Impling impling) { - if (event.getGameState() == GameState.LOGIN_SCREEN || event.getGameState() == GameState.HOPPING) - { - implings.clear(); - } - } - - @Subscribe - public void onNpcDespawned(NpcDespawned npcDespawned) - { - if (implings.isEmpty()) - { - return; - } - - NPC npc = npcDespawned.getNpc(); - implings.remove(npc); - } - - boolean showNpc(NPC npc) - { - Impling impling = Impling.findImpling(npc.getId()); - if (impling == null) - { - return false; - } - ImplingsConfig.ImplingMode impMode = showImplingType(impling.getImplingType()); return impMode == ImplingsConfig.ImplingMode.HIGHLIGHT || impMode == ImplingsConfig.ImplingMode.NOTIFY; } @@ -193,17 +188,10 @@ public class ImplingsPlugin extends Plugin } } - Color npcToColor(NPC npc) + private Color implingColor(Impling impling) { - Impling impling = Impling.findImpling(npc.getId()); - if (impling == null) - { - return null; - } - switch (impling.getImplingType()) { - case BABY: return config.getBabyColor(); case YOUNG: @@ -229,7 +217,7 @@ public class ImplingsPlugin extends Plugin case LUCKY: return config.getLuckyColor(); default: - return null; + throw new IllegalArgumentException(); } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/HighlightedNpc.java b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/HighlightedNpc.java new file mode 100644 index 0000000000..8622b1091f --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/HighlightedNpc.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.npchighlight; + +import java.awt.Color; +import lombok.Builder; +import lombok.Value; +import net.runelite.api.NPC; + +@Value +@Builder +public class HighlightedNpc +{ + NPC npc; + Color highlightColor; + Color fillColor; + boolean hull; + boolean tile; + boolean swTile; + boolean outline; + boolean name; + boolean nameOnMinimap; +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java index 0db3baf6de..ef2f8630f0 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java @@ -39,7 +39,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.Predicate; +import java.util.function.Function; import javax.inject.Inject; import lombok.AccessLevel; import lombok.Getter; @@ -116,7 +116,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService * NPCs to highlight */ @Getter(AccessLevel.PACKAGE) - private final Set highlightedNpcs = new HashSet<>(); + private final Map highlightedNpcs = new HashMap<>(); /** * Dead NPCs that should be displayed with a respawn indicator if the config is on. @@ -175,7 +175,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService */ private boolean skipNextSpawnCheck = false; - private final List> higlightPredicates = new ArrayList<>(); + private final List> higlightPredicates = new ArrayList<>(); @Provides NpcIndicatorsConfig provideConfig(ConfigManager configManager) @@ -265,7 +265,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService color = config.deadNpcMenuColor(); } - if (color == null && highlightedNpcs.contains(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs())) + if (color == null && highlightedNpcs.containsKey(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs())) { color = config.highlightColor(); } @@ -365,7 +365,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService memorizeNpc(npc); npcTags.add(id); } - highlightedNpcs.add(npc); + highlightedNpcs.put(npc, highlightedNpc(npc)); } } else @@ -391,14 +391,14 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService if (npcTags.contains(npc.getIndex())) { memorizeNpc(npc); - highlightedNpcs.add(npc); + highlightedNpcs.put(npc, highlightedNpc(npc)); spawnedNpcsThisTick.add(npc); return; } if (highlightMatchesNPCName(npcName)) { - highlightedNpcs.add(npc); + highlightedNpcs.put(npc, highlightedNpc(npc)); if (!client.isInInstancedRegion()) { memorizeNpc(npc); @@ -407,11 +407,12 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService return; } - for (Predicate predicate : higlightPredicates) + for (Function predicate : higlightPredicates) { - if (predicate.test(npc)) + HighlightedNpc highlightedNpc = predicate.apply(npc); + if (highlightedNpc != null) { - highlightedNpcs.add(npc); + highlightedNpcs.put(npc, highlightedNpc); if (!client.isInInstancedRegion()) { memorizeNpc(npc); @@ -452,7 +453,18 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService if (npcTags.contains(npc.getIndex()) || highlightMatchesNPCName(npcName)) { - highlightedNpcs.add(npc); + highlightedNpcs.put(npc, highlightedNpc(npc)); + return; + } + + for (Function predicate : higlightPredicates) + { + HighlightedNpc highlightedNpc = predicate.apply(npc); + if (highlightedNpc != null) + { + highlightedNpcs.put(npc, highlightedNpc); + return; + } } } @@ -586,7 +598,7 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService if (npcTags.contains(npc.getIndex())) { - highlightedNpcs.add(npc); + highlightedNpcs.put(npc, highlightedNpc(npc)); continue; } @@ -596,19 +608,20 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService { memorizeNpc(npc); } - highlightedNpcs.add(npc); + highlightedNpcs.put(npc, highlightedNpc(npc)); continue; } - for (Predicate predicate : higlightPredicates) + for (Function predicate : higlightPredicates) { - if (predicate.test(npc)) + HighlightedNpc highlightedNpc = predicate.apply(npc); + if (highlightedNpc != null) { if (!client.isInInstancedRegion()) { memorizeNpc(npc); } - highlightedNpcs.add(npc); + highlightedNpcs.put(npc, highlightedNpc); continue outer; } } @@ -721,14 +734,29 @@ public class NpcIndicatorsPlugin extends Plugin implements NpcIndicatorsService teleportGraphicsObjectSpawnedThisTick.clear(); } + private HighlightedNpc highlightedNpc(NPC npc) + { + return HighlightedNpc.builder() + .npc(npc) + .highlightColor(config.highlightColor()) + .fillColor(config.fillColor()) + .hull(config.highlightHull()) + .tile(config.highlightTile()) + .swTile(config.highlightSouthWestTile()) + .outline(config.highlightOutline()) + .name(config.drawNames()) + .nameOnMinimap(config.drawMinimapNames()) + .build(); + } + @Override - public void registerHighlighter(Predicate p) + public void registerHighlighter(Function p) { higlightPredicates.add(p); } @Override - public void unregisterHighlighter(Predicate p) + public void unregisterHighlighter(Function p) { higlightPredicates.remove(p); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsService.java b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsService.java index 43a3b91694..440f33fd65 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsService.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsService.java @@ -24,12 +24,12 @@ */ package net.runelite.client.plugins.npchighlight; -import java.util.function.Predicate; +import java.util.function.Function; import net.runelite.api.NPC; public interface NpcIndicatorsService { - void registerHighlighter(Predicate p); - void unregisterHighlighter(Predicate p); + void registerHighlighter(Function p); + void unregisterHighlighter(Function p); void rebuild(); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcMinimapOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcMinimapOverlay.java index 52a17975a7..b8905f93ea 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcMinimapOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcMinimapOverlay.java @@ -55,16 +55,18 @@ public class NpcMinimapOverlay extends Overlay @Override public Dimension render(Graphics2D graphics) { - for (NPC npc : plugin.getHighlightedNpcs()) + for (HighlightedNpc highlightedNpc : plugin.getHighlightedNpcs().values()) { - renderNpcOverlay(graphics, npc, Text.removeTags(npc.getName()), config.highlightColor()); + renderNpcOverlay(graphics, highlightedNpc); } return null; } - private void renderNpcOverlay(Graphics2D graphics, NPC actor, String name, Color color) + private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc) { + NPC actor = highlightedNpc.getNpc(); + String name = Text.removeTags(actor.getName()); NPCComposition npcComposition = actor.getTransformedComposition(); if (npcComposition == null || !npcComposition.isInteractible() || (actor.isDead() && config.ignoreDeadNpcs())) @@ -75,9 +77,10 @@ public class NpcMinimapOverlay extends Overlay Point minimapLocation = actor.getMinimapLocation(); if (minimapLocation != null) { + Color color = highlightedNpc.getHighlightColor(); OverlayUtil.renderMinimapLocation(graphics, minimapLocation, color.darker()); - if (config.drawMinimapNames()) + if (highlightedNpc.isNameOnMinimap()) { OverlayUtil.renderTextLocation(graphics, minimapLocation, name, color); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcSceneOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcSceneOverlay.java index 8c2b2b3b06..84e428918c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcSceneOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcSceneOverlay.java @@ -89,9 +89,9 @@ public class NpcSceneOverlay extends Overlay plugin.getDeadNpcsToDisplay().forEach((id, npc) -> renderNpcRespawn(npc, graphics)); } - for (NPC npc : plugin.getHighlightedNpcs()) + for (HighlightedNpc highlightedNpc : plugin.getHighlightedNpcs().values()) { - renderNpcOverlay(graphics, npc); + renderNpcOverlay(graphics, highlightedNpc); } return null; @@ -141,8 +141,9 @@ public class NpcSceneOverlay extends Overlay } } - private void renderNpcOverlay(Graphics2D graphics, NPC actor) + private void renderNpcOverlay(Graphics2D graphics, HighlightedNpc highlightedNpc) { + NPC actor = highlightedNpc.getNpc(); NPCComposition npcComposition = actor.getTransformedComposition(); if (npcComposition == null || !npcComposition.isInteractible() || (actor.isDead() && config.ignoreDeadNpcs())) @@ -150,16 +151,16 @@ public class NpcSceneOverlay extends Overlay return; } - final Color borderColor = config.highlightColor(); - final Color fillColor = config.fillColor(); + final Color borderColor = highlightedNpc.getHighlightColor(); + final Color fillColor = highlightedNpc.getFillColor(); - if (config.highlightHull()) + if (highlightedNpc.isHull()) { Shape objectClickbox = actor.getConvexHull(); renderPoly(graphics, borderColor, fillColor, objectClickbox); } - if (config.highlightTile()) + if (highlightedNpc.isTile()) { int size = npcComposition.getSize(); LocalPoint lp = actor.getLocalLocation(); @@ -168,7 +169,7 @@ public class NpcSceneOverlay extends Overlay renderPoly(graphics, borderColor, fillColor, tilePoly); } - if (config.highlightSouthWestTile()) + if (highlightedNpc.isSwTile()) { int size = npcComposition.getSize(); LocalPoint lp = actor.getLocalLocation(); @@ -181,12 +182,12 @@ public class NpcSceneOverlay extends Overlay renderPoly(graphics, borderColor, fillColor, southWestTilePoly); } - if (config.highlightOutline()) + if (highlightedNpc.isOutline()) { modelOutlineRenderer.drawOutline(actor, (int)config.borderWidth(), borderColor, config.outlineFeather()); } - if (config.drawNames() && actor.getName() != null) + if (highlightedNpc.isName() && actor.getName() != null) { String npcName = Text.removeTags(actor.getName()); Point textLocation = actor.getCanvasTextLocation(graphics, npcName, actor.getLogicalHeight() + 40); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerConfig.java index 258ea51b17..55952cb6d2 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerConfig.java @@ -25,6 +25,8 @@ */ package net.runelite.client.plugins.slayer; +import java.awt.Color; +import net.runelite.client.config.Alpha; import net.runelite.client.config.Config; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigItem; @@ -90,17 +92,51 @@ public interface SlayerConfig extends Config @ConfigItem( position = 5, - keyName = "highlightTargets", - name = "Highlight Targets", - description = "Highlight monsters you can kill for your current slayer assignment" + keyName = "highlightHull", + name = "Highlight hull", + description = "Configures whether the NPC hull should be highlighted" ) - default boolean highlightTargets() + default boolean highlightHull() + { + return false; + } + + @ConfigItem( + position = 6, + keyName = "highlightTile", + name = "Highlight tile", + description = "Configures whether the NPC tile should be highlighted" + ) + default boolean highlightTile() { return false; } @ConfigItem( position = 7, + keyName = "highlightOutline", + name = "Highlight outline", + description = "Configures whether or not the NPC outline should be highlighted" + ) + default boolean highlightOutline() + { + return false; + } + + @Alpha + @ConfigItem( + position = 8, + keyName = "targetColor", + name = "Target color", + description = "Color of the highlighted targets" + ) + default Color getTargetColor() + { + return Color.RED; + } + + @ConfigItem( + position = 9, keyName = "weaknessPrompt", name = "Show Monster Weakness", description = "Show an overlay on a monster when it is weak enough to finish off (Only Lizards, Gargoyles & Rockslugs)" @@ -111,7 +147,7 @@ public interface SlayerConfig extends Config } @ConfigItem( - position = 8, + position = 10, keyName = "taskCommand", name = "Task Command", description = "Configures whether the slayer task command is enabled
!task" diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerPlugin.java index 729debeb25..6983270fa1 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerPlugin.java @@ -39,7 +39,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.ScheduledExecutorService; -import java.util.function.Predicate; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.inject.Inject; @@ -86,6 +86,7 @@ import net.runelite.client.game.ItemManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDependency; import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.plugins.npchighlight.HighlightedNpc; import net.runelite.client.plugins.npchighlight.NpcIndicatorsPlugin; import net.runelite.client.plugins.npchighlight.NpcIndicatorsService; import net.runelite.client.ui.overlay.OverlayManager; @@ -210,7 +211,23 @@ public class SlayerPlugin extends Plugin private boolean loginFlag; private final List targetNames = new ArrayList<>(); - public final Predicate isTarget = (n) -> config.highlightTargets() && targets.contains(n); + public final Function isTarget = (n) -> + { + if ((config.highlightHull() || config.highlightTile() || config.highlightOutline()) && targets.contains(n)) + { + Color color = config.getTargetColor(); + return HighlightedNpc.builder() + .npc(n) + .highlightColor(color) + .fillColor(ColorUtil.colorWithAlpha(color, color.getAlpha() / 12)) + .hull(config.highlightHull()) + .tile(config.highlightTile()) + .outline(config.highlightOutline()) + .build(); + + } + return null; + }; @Override protected void startUp() throws Exception @@ -603,7 +620,7 @@ public class SlayerPlugin extends Plugin } else { - npcIndicatorsService.rebuild(); + clientThread.invoke(npcIndicatorsService::rebuild); } } diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java index 6d510e1516..5fe725c00f 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/chatcommands/ChatCommandsPluginTest.java @@ -1,967 +1,1075 @@ -/* - * Copyright (c) 2018, Adam - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package net.runelite.client.plugins.chatcommands; - -import com.google.common.collect.Sets; -import com.google.inject.Guice; -import com.google.inject.testing.fieldbinder.Bind; -import com.google.inject.testing.fieldbinder.BoundFieldModule; -import java.io.IOException; -import java.util.concurrent.ScheduledExecutorService; -import javax.inject.Inject; -import net.runelite.api.ChatMessageType; -import static net.runelite.api.ChatMessageType.FRIENDSCHATNOTIFICATION; -import static net.runelite.api.ChatMessageType.GAMEMESSAGE; -import static net.runelite.api.ChatMessageType.TRADE; -import net.runelite.api.Client; -import net.runelite.api.MessageNode; -import net.runelite.api.Player; -import net.runelite.api.events.ChatMessage; -import net.runelite.api.events.GameTick; -import net.runelite.api.events.WidgetLoaded; -import net.runelite.api.widgets.Widget; -import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID; -import static net.runelite.api.widgets.WidgetID.GENERIC_SCROLL_GROUP_ID; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.client.chat.ChatCommandManager; -import net.runelite.client.chat.ChatMessageManager; -import net.runelite.client.config.ChatColorConfig; -import net.runelite.client.config.ConfigManager; -import net.runelite.client.config.RuneLiteConfig; -import net.runelite.http.api.chat.ChatClient; -import net.runelite.http.api.hiscore.HiscoreClient; -import net.runelite.http.api.hiscore.HiscoreSkill; -import net.runelite.http.api.hiscore.SingleHiscoreSkillResult; -import net.runelite.http.api.hiscore.Skill; -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; -import static org.mockito.Mockito.when; -import org.mockito.junit.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) -public class ChatCommandsPluginTest -{ - private static final String PLAYER_NAME = "Adam"; - - @Mock - @Bind - Client client; - - @Mock - @Bind - ConfigManager configManager; - - @Mock - @Bind - ScheduledExecutorService scheduledExecutorService; - - @Mock - @Bind - ChatColorConfig chatColorConfig; - - @Mock - @Bind - ChatCommandManager chatCommandManager; - - @Mock - @Bind - HiscoreClient hiscoreClient; - - @Mock - @Bind - ChatMessageManager chatMessageManager; - - @Mock - @Bind - ChatClient chatClient; - - @Mock - @Bind - RuneLiteConfig runeLiteConfig; - - @Mock - @Bind - ChatCommandsConfig chatCommandsConfig; - - @Inject - ChatCommandsPlugin chatCommandsPlugin; - - @Before - public void before() - { - Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this); - - Player player = mock(Player.class); - when(player.getName()).thenReturn(PLAYER_NAME); - when(client.getLocalPlayer()).thenReturn(player); - } - - @Test - public void testStartupShutdown() - { - chatCommandsPlugin.startUp(); - chatCommandsPlugin.shutDown(); - - ArgumentCaptor registerCaptor = ArgumentCaptor.forClass(String.class); - verify(chatCommandManager, atLeastOnce()).registerCommand(registerCaptor.capture(), any()); - verify(chatCommandManager, atLeastOnce()).registerCommandAsync(registerCaptor.capture(), any()); - verify(chatCommandManager, atLeastOnce()).registerCommandAsync(registerCaptor.capture(), any(), any()); - - ArgumentCaptor unregisterCaptor = ArgumentCaptor.forClass(String.class); - verify(chatCommandManager, atLeastOnce()).unregisterCommand(unregisterCaptor.capture()); - - assertEquals(Sets.newHashSet(registerCaptor.getAllValues()), Sets.newHashSet(unregisterCaptor.getAllValues())); - } - - @Test - public void testCorporealBeastKill() - { - ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Corporeal Beast kill count is: 4.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "corporeal beast", 4); - } - - @Test - public void testTheatreOfBlood() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", - "Wave 'The Final Challenge' (Normal Mode) complete!
Duration: 2:42.0
Theatre of Blood wave completion time: 17:00.20 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood count is: 73.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood", 73); - verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood", 17 * 60 + .2); - } - - @Test - public void testTheatreOfBloodNoPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", - "Wave 'The Final Challenge' (Normal Mode) complete!
Duration: 2:42
Theatre of Blood wave completion time: 17:00. Personal best: 13:52.80", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood count is: 73.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood", 73); - verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood", 13 * 60 + 52.8); - } - - @Test - public void testTheatreOfBloodStoryMode() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", - "Wave 'The Final Challenge' (Story Mode) complete!
Duration: 2:42
Theatre of Blood wave completion time: 17:00 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood: Story Mode count is: 73.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood story mode", 73); - verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood story mode", 17 * 60.); - } - - @Test - public void testWintertodt() - { - ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your subdued Wintertodt count is: 4.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "wintertodt", 4); - } - - @Test - public void testKreearra() - { - ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: 4.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "kree'arra", 4); - } - - @Test - public void testBarrows() - { - ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Barrows chest count is: 277.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "barrows chests", 277); - } - - @Test - public void testHerbiboar() - { - ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your herbiboar harvest count is: 4091.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "herbiboar", 4091); - } - - @Test - public void testGauntlet() - { - ChatMessage gauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 123.", null, 0); - chatCommandsPlugin.onChatMessage(gauntletMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "gauntlet", 123); - } - - @Test - public void testCorruptedGauntlet() - { - ChatMessage corruptedGauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Corrupted Gauntlet completion count is: 4729.", null, 0); - chatCommandsPlugin.onChatMessage(corruptedGauntletMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "corrupted gauntlet", 4729); - } - - @Test - public void testPersonalBest() - { - final String FIGHT_DURATION = "Fight duration: 2:06. Personal best: 1:19."; - final String FIGHT_DURATION_PRECISE = "Fight duration: 2:06.40. Personal best: 1:19.20."; - - // This sets lastBoss - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: 4.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION, null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "kree'arra", 79.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION_PRECISE, null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "kree'arra", 79.2); - } - - @Test - public void testPersonalBestNoTrailingPeriod() - { - final String FIGHT_DURATION = "Fight duration: 0:59. Personal best: 0:55"; - final String FIGHT_DURATION_PRECISE = "Fight duration: 0:59.20. Personal best: 0:55.40"; - - // This sets lastBoss - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Zulrah kill count is: 4.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION, null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 55.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION_PRECISE, null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 55.4); - } - - @Test - public void testNewPersonalBest() - { - final String NEW_PB = "Fight duration: 3:01 (new personal best)."; - final String NEW_PB_PRECISE = "Fight duration: 3:01.40 (new personal best)."; - - // This sets lastBoss - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: 4.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB, null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "kree'arra", 181.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB_PRECISE, null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "kree'arra", 181.4); - } - - @Test - public void testDuelArenaWin() - { - ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You won! You have now won 27 duels.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "duel arena wins", 27); - verify(configManager).setRSProfileConfiguration("killcount", "duel arena win streak", 1); - } - - @Test - public void testDuelArenaWin2() - { - ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You were defeated! You have won 22 duels.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "duel arena wins", 22); - } - - @Test - public void testDuelArenaLose() - { - ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You have now lost 999 duels.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessageEvent); - - verify(configManager).setRSProfileConfiguration("killcount", "duel arena losses", 999); - } - - @Test - public void testAgilityLap() - { - final String NEW_PB = "Lap duration: 1:01 (new personal best)."; - final String NEW_PB_PRECISE = "Lap duration: 1:01.20 (new personal best)."; - - // This sets lastBoss - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Prifddinas Agility Course lap count is: 2.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB, null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "prifddinas agility course", 61.0); - verify(configManager).setRSProfileConfiguration("killcount", "prifddinas agility course", 2); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB_PRECISE, null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "prifddinas agility course", 61.2); - } - - @Test - public void testZukNewPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzKal-Zuk kill count is: 2.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 104:31 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "tzkal-zuk", 104 * 60 + 31.0); - verify(configManager).setRSProfileConfiguration("killcount", "tzkal-zuk", 2); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 104:31.20 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - verify(configManager).setRSProfileConfiguration("personalbest", "tzkal-zuk", 104 * 60 + 31.2); - } - - @Test - public void testZukKill() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzKal-Zuk kill count is: 3.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 172:18. Personal best: 134:52", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "tzkal-zuk", 134 * 60 + 52.0); - verify(configManager).setRSProfileConfiguration("killcount", "tzkal-zuk", 3); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 172:18.40. Personal best: 134:52.20", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - verify(configManager).setRSProfileConfiguration("personalbest", "tzkal-zuk", 134 * 60 + 52.2); - } - - @Test - public void testGgNewPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: 1:36 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: 179.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 96.0); - verify(configManager).setRSProfileConfiguration("killcount", "grotesque guardians", 179); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: 1:36.40 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: 179.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 96.4); - } - - @Test - public void testGgKill() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: 2:41. Personal best: 2:14", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: 32.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 2 * 60 + 14.0); - verify(configManager).setRSProfileConfiguration("killcount", "grotesque guardians", 32); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: 2:41.40. Personal best: 2:14.20", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: 32.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 2 * 60 + 14.2); - } - - @Test - public void testGauntletPersonalBest() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 10:24. Personal best: 7:59.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 124.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "gauntlet", 124); - verify(configManager).setRSProfileConfiguration("personalbest", "gauntlet", 7 * 60 + 59.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 10:24.20. Personal best: 7:52.40.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 124.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "gauntlet", 7 * 60 + 52.4); - } - - @Test - public void testGauntletNewPersonalBest() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 10:24 (new personal best).", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 124.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "gauntlet", 10 * 60 + 24.0); - verify(configManager).setRSProfileConfiguration("killcount", "gauntlet", 124); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 10:24.40 (new personal best).", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 124.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "gauntlet", 10 * 60 + 24.4); - } - - @Test - public void testCoXKill() - { - ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "Congratulations - your raid is complete!
Team size: 24+ players Duration: 37:04 (new personal best)>", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: 51.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "chambers of xeric", 51); - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 37 * 60 + 4.0); - - // Precise times - chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "Congratulations - your raid is complete!
Team size: 24+ players Duration: 37:04.20 (new personal best)>", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: 51.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 37 * 60 + 4.2); - } - - @Test - public void testCoXKillNoPb() - { - ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "Congratulations - your raid is complete!
Team size: 11-15 players Duration: 23:25 Personal best: 20:19", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: 52.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "chambers of xeric", 52); - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 20 * 60 + 19.0); - - // Precise times - chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "Congratulations - your raid is complete!
Team size: 11-15 players Duration: 23:25.40 Personal best: 20:19.20", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: 52.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 20 * 60 + 19.2); - } - - @Test - public void testAdventureLogCountersPage() - { - Widget advLogWidget = mock(Widget.class); - Widget advLogExploitsTextWidget = mock(Widget.class); - when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); - when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME); - when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget); - when(configManager.getRSProfileConfiguration(anyString(), anyString(), any(Class.class))).thenReturn(2224.0); - - WidgetLoaded advLogEvent = new WidgetLoaded(); - advLogEvent.setGroupId(ADVENTURE_LOG_ID); - chatCommandsPlugin.onWidgetLoaded(advLogEvent); - chatCommandsPlugin.onGameTick(new GameTick()); - - String COUNTER_TEXT = "Duel Arena
Wins: 4
Losses: 2" + - "

Last Man Standing
Rank: 0" + - "

Treasure Trails
Beginner: 0
Easy: 7" + - "
Medium: 28
Hard: 108
Elite: 15" + - "
Master: 27
Rank: Novice" + - "

Chompy Hunting
Kills: 1,000
Rank: Ogre Expert" + - "

Order of the White Knights
Rank: Master
with a kill score of 1,300" + - "

TzHaar Fight Cave
Fastest run: 38:10" + - "

Inferno
Fastest run: -

Zulrah
" + - "Fastest kill: 5:48

Vorkath
Fastest kill: 1:21" + - "

Galvek
Fastest kill: -

Grotesque Guardians
" + - "Fastest kill: 2:49

Alchemical Hydra
Fastest kill: -" + - "

Hespori
Fastest kill: 0:57

Nightmare
" + - "Fastest kill: 3:30

The Gauntlet
Fastest run: -" + - "

The Corrupted Gauntlet
Fastest run: -

Fragment of Seren
Fastest kill: -" + - "

Chambers of Xeric
Fastest run - (Team size: 24+ players): 24:17" + - "

Chambers of Xeric - Challenge mode
Fastest run - (Team size: Solo): 22:15" + - "

Barbarian Assault
High-level gambles: 0

Fremennik spirits rested: 0"; - - Widget countersPage = mock(Widget.class); - when(countersPage.getText()).thenReturn(COUNTER_TEXT); - when(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT)).thenReturn(countersPage); - - WidgetLoaded countersLogEvent = new WidgetLoaded(); - countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID); - chatCommandsPlugin.onWidgetLoaded(countersLogEvent); - chatCommandsPlugin.onGameTick(new GameTick()); - - verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 38 * 60 + 10.0); - verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 5 * 60 + 48.0); - verify(configManager).setRSProfileConfiguration("personalbest", "vorkath", 60 + 21.0); - verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 2 * 60 + 49.0); - verify(configManager).setRSProfileConfiguration("personalbest", "hespori", 57.0); - verify(configManager).setRSProfileConfiguration("personalbest", "nightmare", 3 * 60 + 30.0); - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 24 * 60 + 17.0); - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric challenge mode", 22 * 60 + 15.0); - } - - @Test - public void testAdventurerLogCountersPage2() - { - Widget advLogWidget = mock(Widget.class); - Widget advLogExploitsTextWidget = mock(Widget.class); - when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); - when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME); - when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget); - - WidgetLoaded advLogEvent = new WidgetLoaded(); - advLogEvent.setGroupId(ADVENTURE_LOG_ID); - chatCommandsPlugin.onWidgetLoaded(advLogEvent); - chatCommandsPlugin.onGameTick(new GameTick()); - - String COUNTER_TEXT = "Duel Arena
Wins: 12
Losses: 20" + - "

Last Man Standing
Rank: 0" + - "

Treasure Trails
Beginner: 1
Easy: 4" + - "
Medium: 35
Hard: 66
Elite: 2" + - "
Master: 0
Rank: Novice" + - "

Chompy Hunting
Kills: 300
Rank: Ogre Forester" + - "

Order of the White Knights
Rank: Unrated
with a kill score of 99" + - "

TzHaar Fight Cave
Fastest run: 65:12" + - "

Inferno
Fastest run: -

Zulrah
" + - "Fastest kill: 2:55

Vorkath
Fastest kill: 1:37" + - "

Galvek
Fastest kill: -

Grotesque Guardians
" + - "Fastest kill: -

Alchemical Hydra
Fastest kill: -" + - "

Hespori
Fastest kill: 1:42

Nightmare
" + - "Fastest kill: -

The Gauntlet
Fastest run: -" + - "

The Corrupted Gauntlet
Fastest run: -

Fragment of Seren
Fastest kill: -" + - "

Chambers of Xeric
Fastest run - (Team size: Solo): 21:23
Fastest run - (Team size: 3 players): 27:16" + - "

Chambers of Xeric - Challenge mode
Fastest run - (Team size: Solo): 34:30
Fastest run - (Team size: 4 players): 21:26" + - "

Barbarian Assault
High-level gambles: 0

Fremennik spirits rested: 0"; - - Widget countersPage = mock(Widget.class); - when(countersPage.getText()).thenReturn(COUNTER_TEXT); - when(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT)).thenReturn(countersPage); - - WidgetLoaded countersLogEvent = new WidgetLoaded(); - countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID); - chatCommandsPlugin.onWidgetLoaded(countersLogEvent); - chatCommandsPlugin.onGameTick(new GameTick()); - - verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 65 * 60 + 12.0); - verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 2 * 60 + 55.0); - verify(configManager).setRSProfileConfiguration("personalbest", "vorkath", 60 + 37.0); - verify(configManager).setRSProfileConfiguration("personalbest", "hespori", 60 + 42.0); - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 21 * 60 + 23.0); - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric challenge mode", 21 * 60 + 26.0); - } - - @Test - public void testAdventurerLogCountersPagePrecise() - { - Widget advLogWidget = mock(Widget.class); - Widget advLogExploitsTextWidget = mock(Widget.class); - when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); - when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME); - when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget); - - WidgetLoaded advLogEvent = new WidgetLoaded(); - advLogEvent.setGroupId(ADVENTURE_LOG_ID); - chatCommandsPlugin.onWidgetLoaded(advLogEvent); - chatCommandsPlugin.onGameTick(new GameTick()); - - String COUNTER_TEXT = "Duel Arena
Wins: 12
Losses: 20" + - "

Last Man Standing
Rank: 0" + - "

Treasure Trails
Beginner: 1
Easy: 4" + - "
Medium: 35
Hard: 66
Elite: 2" + - "
Master: 0
Rank: Novice" + - "

Chompy Hunting
Kills: 300
Rank: Ogre Forester" + - "

Order of the White Knights
Rank: Unrated
with a kill score of 99" + - "

TzHaar Fight Cave
Fastest run: 65:12.00" + - "

Inferno
Fastest run: -

Zulrah
" + - "Fastest kill: 2:55.20

Vorkath
Fastest kill: 1:37.20" + - "

Galvek
Fastest kill: -

Grotesque Guardians
" + - "Fastest kill: -

Alchemical Hydra
Fastest kill: -" + - "

Hespori
Fastest kill: 1:42.40

Nightmare
" + - "Fastest kill: -

The Gauntlet
Fastest run: -" + - "

The Corrupted Gauntlet
Fastest run: -

Fragment of Seren
Fastest kill: -" + - "

Chambers of Xeric
Fastest run - (Team size: Solo): 21:23.20
Fastest run - (Team size: 3 players): 27:16.40" + - "

Chambers of Xeric - Challenge mode
Fastest run - (Team size: Solo): 34:30.20
Fastest run - (Team size: 4 players): 21:26.00" + - "

Barbarian Assault
High-level gambles: 0

Fremennik spirits rested: 0"; - - Widget countersPage = mock(Widget.class); - when(countersPage.getText()).thenReturn(COUNTER_TEXT); - when(client.getWidget(WidgetInfo.GENERIC_SCROLL_TEXT)).thenReturn(countersPage); - - WidgetLoaded countersLogEvent = new WidgetLoaded(); - countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID); - chatCommandsPlugin.onWidgetLoaded(countersLogEvent); - chatCommandsPlugin.onGameTick(new GameTick()); - - verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 65 * 60 + 12.0); - verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 2 * 60 + 55.2); - verify(configManager).setRSProfileConfiguration("personalbest", "vorkath", 60 + 37.2); - verify(configManager).setRSProfileConfiguration("personalbest", "hespori", 60 + 42.40); - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 21 * 60 + 23.20); - verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric challenge mode", 21 * 60 + 26.0); - } - - @Test - public void testNotYourAdventureLogCountersPage() - { - Widget advLogWidget = mock(Widget.class); - Widget advLogExploitsTextWidget = mock(Widget.class); - when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); - when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + "not the player"); - when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget); - - WidgetLoaded advLogEvent = new WidgetLoaded(); - advLogEvent.setGroupId(ADVENTURE_LOG_ID); - chatCommandsPlugin.onWidgetLoaded(advLogEvent); - chatCommandsPlugin.onGameTick(new GameTick()); - - WidgetLoaded countersLogEvent = new WidgetLoaded(); - countersLogEvent.setGroupId(GENERIC_SCROLL_GROUP_ID); - chatCommandsPlugin.onWidgetLoaded(countersLogEvent); - chatCommandsPlugin.onGameTick(new GameTick()); - - verifyNoMoreInteractions(configManager); - } - - @Test - public void testPlayerSkillLookup() throws IOException - { - when(chatCommandsConfig.lvl()).thenReturn(true); - - SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult(); - skillResult.setPlayer(PLAYER_NAME); - skillResult.setSkill(new Skill(10, 1000, -1)); - - when(hiscoreClient.lookup(PLAYER_NAME, HiscoreSkill.ZULRAH, null)).thenReturn(skillResult); - - MessageNode messageNode = mock(MessageNode.class); - - ChatMessage chatMessage = new ChatMessage(); - chatMessage.setType(ChatMessageType.PUBLICCHAT); - chatMessage.setName(PLAYER_NAME); - chatMessage.setMessageNode(messageNode); - chatCommandsPlugin.playerSkillLookup(chatMessage, "!lvl zulrah"); - - verify(messageNode).setRuneLiteFormatMessage("Level Zulrah: 1000 Rank: 10"); - } - - @Test - public void testHsFloorNoPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 1 time: 1:19. Personal best: 0:28", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 1", 28.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 1 time: 1:19.20. Personal best: 0:28.40", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 1", 28.4); - } - - @Test - public void testHsFloorPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 2 time: 0:47 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 2", 47.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 2 time: 0:47.20 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 2", 47.2); - } - - @Test - public void testHsOverallPb_Pb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 4:46 (new personal best)
Overall time: 9:53 (new personal best)
", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 4 * 60 + 46.0); - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 9 * 60 + 53.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 4:46.20 (new personal best)
Overall time: 9:53.40 (new personal best)
", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 4 * 60 + 46.2); - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 9 * 60 + 53.4); - } - - @Test - public void testHsOverallPb_NoPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:26 (new personal best)
Overall time: 9:17. Personal best: 9:15
", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 26.0); - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 9 * 60 + 15.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:26.20 (new personal best)
Overall time: 9:17.00. Personal best: 9:15.40
", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 26.2); - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 9 * 60 + 15.4); - } - - @Test - public void testHsOverallNoPb_NoPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:56. Personal best: 3:05
Overall time: 9:14. Personal best: 7:49
", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 5.0); - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 7 * 60 + 49.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:56.40. Personal best: 3:05.20
Overall time: 9:14.20. Personal best: 7:49.20
", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 5.2); - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 7 * 60 + 49.2); - } - - @Test - public void testHsOverallNoPb_Pb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:10. Personal best: 3:04
Overall time: 7:47 (new personal best)
", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 4.0); - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 7 * 60 + 47.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:10.00. Personal best: 3:04.40
Overall time: 7:47.20 (new personal best)
", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 4.4); - verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 7 * 60 + 47.2); - } - - @Test - public void testHsFloorKc() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have completed Floor 5 of the Hallowed Sepulchre! Total completions: 1,114.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "hallowed sepulchre floor 5", 1114); - } - - @Test - public void testHsGhcKc() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have opened the Grand Hallowed Coffin 1,542 times!", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "hallowed sepulchre", 1542); - } - - @Test - public void testJadNewPbWithLeagueTask() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzTok-Jad kill count is: 2.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Congratulations, you've completed a master task: Complete the Fight Caves in 25:00.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 21:58 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 21 * 60 + 58.0); - verify(configManager).setRSProfileConfiguration("killcount", "tztok-jad", 2); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 21:58.40 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 21 * 60 + 58.4); - } - - @Test - public void testJadChallengeNewPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completion count for TzHaar-Ket-Rak's First Challenge is: 1.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 1:46 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 1); - verify(configManager).setRSProfileConfiguration("personalbest", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 60 + 46.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 1:46.40 (new personal best)", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 60 + 46.4); - } - - @Test - public void testJadChallengeNoPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completion count for TzHaar-Ket-Rak's First Challenge is: 3.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 1:10. Personal best: 0:59", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 3); - verify(configManager).setRSProfileConfiguration("personalbest", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 59.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 1:10.00. Personal best: 0:59.20", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 59.2); - } - - @Test - public void testTemporossNewPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in 6:35 (new personal best).", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: 60.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "tempoross", 60); - verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 6 * 60 + 35.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in 5:20.60 (new personal best).", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: 60.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 20.6); - } - - @Test - public void testTemporossNoPb() - { - ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in 7:40. Personal best: 5:38.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: 55.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("killcount", "tempoross", 55); - verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 38.0); - - // Precise times - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in 6:19.80. Personal best: 5:42.60.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: 55.", null, 0); - chatCommandsPlugin.onChatMessage(chatMessage); - - verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 42.6); - } - - @Test - public void testTimeStringToSeconds() - { - final double DELTA = 0.0001; - - // ss - assertEquals(55.0, ChatCommandsPlugin.timeStringToSeconds("55.00"), DELTA); - // mm:ss - assertEquals(6 * 60 + 55.4, ChatCommandsPlugin.timeStringToSeconds("6:55.40"), DELTA); - // h:mm:ss - assertEquals(2 * 3600 + 50 * 60 + 30.2, ChatCommandsPlugin.timeStringToSeconds("2:50:30.20"), DELTA); - } -} +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.chatcommands; + +import com.google.common.collect.Sets; +import com.google.gson.Gson; +import com.google.inject.Guice; +import com.google.inject.testing.fieldbinder.Bind; +import com.google.inject.testing.fieldbinder.BoundFieldModule; +import java.io.IOException; +import java.util.Arrays; +import java.util.concurrent.ScheduledExecutorService; +import javax.inject.Inject; +import net.runelite.api.ChatMessageType; +import static net.runelite.api.ChatMessageType.FRIENDSCHATNOTIFICATION; +import static net.runelite.api.ChatMessageType.GAMEMESSAGE; +import static net.runelite.api.ChatMessageType.TRADE; +import net.runelite.api.Client; +import net.runelite.api.MessageNode; +import net.runelite.api.Player; +import net.runelite.api.ScriptID; +import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.GameTick; +import net.runelite.api.events.ScriptPostFired; +import net.runelite.api.events.WidgetLoaded; +import net.runelite.api.widgets.Widget; +import static net.runelite.api.widgets.WidgetID.ADVENTURE_LOG_ID; +import static net.runelite.api.widgets.WidgetID.DIARY_QUEST_GROUP_ID; +import net.runelite.api.widgets.WidgetInfo; +import net.runelite.client.chat.ChatCommandManager; +import net.runelite.client.chat.ChatMessageManager; +import net.runelite.client.config.ChatColorConfig; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.config.RuneLiteConfig; +import net.runelite.http.api.RuneLiteAPI; +import net.runelite.http.api.chat.ChatClient; +import net.runelite.http.api.hiscore.HiscoreClient; +import net.runelite.http.api.hiscore.HiscoreSkill; +import net.runelite.http.api.hiscore.SingleHiscoreSkillResult; +import net.runelite.http.api.hiscore.Skill; +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import org.mockito.junit.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class ChatCommandsPluginTest +{ + private static final String PLAYER_NAME = "Adam"; + + @Mock + @Bind + Client client; + + @Mock + @Bind + ConfigManager configManager; + + @Mock + @Bind + ScheduledExecutorService scheduledExecutorService; + + @Mock + @Bind + ChatColorConfig chatColorConfig; + + @Mock + @Bind + ChatCommandManager chatCommandManager; + + @Mock + @Bind + HiscoreClient hiscoreClient; + + @Mock + @Bind + ChatMessageManager chatMessageManager; + + @Mock + @Bind + ChatClient chatClient; + + @Mock + @Bind + RuneLiteConfig runeLiteConfig; + + @Mock + @Bind + ChatCommandsConfig chatCommandsConfig; + + @Inject + ChatCommandsPlugin chatCommandsPlugin; + + final Gson gson = RuneLiteAPI.GSON; + + @Before + public void before() + { + Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this); + + Player player = mock(Player.class); + when(player.getName()).thenReturn(PLAYER_NAME); + when(client.getLocalPlayer()).thenReturn(player); + } + + @Test + public void testStartupShutdown() + { + chatCommandsPlugin.startUp(); + chatCommandsPlugin.shutDown(); + + ArgumentCaptor registerCaptor = ArgumentCaptor.forClass(String.class); + verify(chatCommandManager, atLeastOnce()).registerCommand(registerCaptor.capture(), any()); + verify(chatCommandManager, atLeastOnce()).registerCommandAsync(registerCaptor.capture(), any()); + verify(chatCommandManager, atLeastOnce()).registerCommandAsync(registerCaptor.capture(), any(), any()); + + ArgumentCaptor unregisterCaptor = ArgumentCaptor.forClass(String.class); + verify(chatCommandManager, atLeastOnce()).unregisterCommand(unregisterCaptor.capture()); + + assertEquals(Sets.newHashSet(registerCaptor.getAllValues()), Sets.newHashSet(unregisterCaptor.getAllValues())); + } + + @Test + public void testCorporealBeastKill() + { + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Corporeal Beast kill count is: 4.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "corporeal beast", 4); + } + + @Test + public void testTheatreOfBlood() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", + "Wave 'The Final Challenge' (Normal Mode) complete!
Duration: 2:42.0
Theatre of Blood wave completion time: 17:00.20 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood count is: 73.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood", 73); + verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood", 17 * 60 + .2); + } + + @Test + public void testTheatreOfBloodNoPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", + "Wave 'The Final Challenge' (Normal Mode) complete!
Duration: 2:42
Theatre of Blood wave completion time: 17:00. Personal best: 13:52.80", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood count is: 73.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood", 73); + verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood", 13 * 60 + 52.8); + } + + @Test + public void testTheatreOfBloodEntryMode() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", + "Wave 'The Final Challenge' (Entry Mode) complete!
Duration: 2:42
Theatre of Blood wave completion time: 17:00 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Theatre of Blood: Entry Mode count is: 73.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "theatre of blood entry mode", 73); + verify(configManager).setRSProfileConfiguration("personalbest", "theatre of blood entry mode", 17 * 60.); + } + + @Test + public void testWintertodt() + { + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your subdued Wintertodt count is: 4.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "wintertodt", 4); + } + + @Test + public void testKreearra() + { + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: 4.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "kree'arra", 4); + } + + @Test + public void testBarrows() + { + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your Barrows chest count is: 277.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "barrows chests", 277); + } + + @Test + public void testHerbiboar() + { + ChatMessage chatMessageEvent = new ChatMessage(null, GAMEMESSAGE, "", "Your herbiboar harvest count is: 4091.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "herbiboar", 4091); + } + + @Test + public void testGauntlet() + { + ChatMessage gauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 123.", null, 0); + chatCommandsPlugin.onChatMessage(gauntletMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "gauntlet", 123); + } + + @Test + public void testCorruptedGauntlet() + { + ChatMessage corruptedGauntletMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Corrupted Gauntlet completion count is: 4729.", null, 0); + chatCommandsPlugin.onChatMessage(corruptedGauntletMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "corrupted gauntlet", 4729); + } + + @Test + public void testPersonalBest() + { + final String FIGHT_DURATION = "Fight duration: 2:06. Personal best: 1:19."; + final String FIGHT_DURATION_PRECISE = "Fight duration: 2:06.40. Personal best: 1:19.20."; + + // This sets lastBoss + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: 4.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION, null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "kree'arra", 79.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION_PRECISE, null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "kree'arra", 79.2); + } + + @Test + public void testPersonalBestNoTrailingPeriod() + { + final String FIGHT_DURATION = "Fight duration: 0:59. Personal best: 0:55"; + final String FIGHT_DURATION_PRECISE = "Fight duration: 0:59.20. Personal best: 0:55.40"; + + // This sets lastBoss + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Zulrah kill count is: 4.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION, null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 55.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", FIGHT_DURATION_PRECISE, null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "zulrah", 55.4); + } + + @Test + public void testNewPersonalBest() + { + final String NEW_PB = "Fight duration: 3:01 (new personal best)."; + final String NEW_PB_PRECISE = "Fight duration: 3:01.40 (new personal best)."; + + // This sets lastBoss + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Kree'arra kill count is: 4.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB, null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "kree'arra", 181.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB_PRECISE, null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "kree'arra", 181.4); + } + + @Test + public void testDuelArenaWin() + { + ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You won! You have now won 27 duels.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "duel arena wins", 27); + verify(configManager).setRSProfileConfiguration("killcount", "duel arena win streak", 1); + } + + @Test + public void testDuelArenaWin2() + { + ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You were defeated! You have won 22 duels.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "duel arena wins", 22); + } + + @Test + public void testDuelArenaLose() + { + ChatMessage chatMessageEvent = new ChatMessage(null, TRADE, "", "You have now lost 999 duels.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessageEvent); + + verify(configManager).setRSProfileConfiguration("killcount", "duel arena losses", 999); + } + + @Test + public void testAgilityLap() + { + final String NEW_PB = "Lap duration: 1:01 (new personal best)."; + final String NEW_PB_PRECISE = "Lap duration: 1:01.20 (new personal best)."; + + // This sets lastBoss + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Prifddinas Agility Course lap count is: 2.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB, null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "prifddinas agility course", 61.0); + verify(configManager).setRSProfileConfiguration("killcount", "prifddinas agility course", 2); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", NEW_PB_PRECISE, null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "prifddinas agility course", 61.2); + } + + @Test + public void testZukNewPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzKal-Zuk kill count is: 2.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 104:31 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "tzkal-zuk", 104 * 60 + 31.0); + verify(configManager).setRSProfileConfiguration("killcount", "tzkal-zuk", 2); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 104:31.20 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + verify(configManager).setRSProfileConfiguration("personalbest", "tzkal-zuk", 104 * 60 + 31.2); + } + + @Test + public void testZukKill() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzKal-Zuk kill count is: 3.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 172:18. Personal best: 134:52", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "tzkal-zuk", 134 * 60 + 52.0); + verify(configManager).setRSProfileConfiguration("killcount", "tzkal-zuk", 3); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 172:18.40. Personal best: 134:52.20", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + verify(configManager).setRSProfileConfiguration("personalbest", "tzkal-zuk", 134 * 60 + 52.2); + } + + @Test + public void testGgNewPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: 1:36 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: 179.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 96.0); + verify(configManager).setRSProfileConfiguration("killcount", "grotesque guardians", 179); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: 1:36.40 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: 179.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 96.4); + } + + @Test + public void testGgKill() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: 2:41. Personal best: 2:14", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: 32.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 2 * 60 + 14.0); + verify(configManager).setRSProfileConfiguration("killcount", "grotesque guardians", 32); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Fight duration: 2:41.40. Personal best: 2:14.20", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Grotesque Guardians kill count is: 32.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "grotesque guardians", 2 * 60 + 14.2); + } + + @Test + public void testGauntletPersonalBest() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 10:24. Personal best: 7:59.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 124.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "gauntlet", 124); + verify(configManager).setRSProfileConfiguration("personalbest", "gauntlet", 7 * 60 + 59.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 10:24.20. Personal best: 7:52.40.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 124.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "gauntlet", 7 * 60 + 52.4); + } + + @Test + public void testGauntletNewPersonalBest() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 10:24 (new personal best).", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 124.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "gauntlet", 10 * 60 + 24.0); + verify(configManager).setRSProfileConfiguration("killcount", "gauntlet", 124); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 10:24.40 (new personal best).", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Gauntlet completion count is: 124.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "gauntlet", 10 * 60 + 24.4); + } + + @Test + public void testCoXKill() + { + ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "Congratulations - your raid is complete!
Team size: 24+ players Duration: 37:04 (new personal best)>", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: 51.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "chambers of xeric", 51); + verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 37 * 60 + 4.0); + + // Precise times + chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "Congratulations - your raid is complete!
Team size: 24+ players Duration: 37:04.20 (new personal best)>", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: 51.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 37 * 60 + 4.2); + } + + @Test + public void testCoXKillNoPb() + { + ChatMessage chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "Congratulations - your raid is complete!
Team size: 11-15 players Duration: 23:25 Personal best: 20:19", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: 52.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "chambers of xeric", 52); + verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 20 * 60 + 19.0); + + // Precise times + chatMessage = new ChatMessage(null, FRIENDSCHATNOTIFICATION, "", "Congratulations - your raid is complete!
Team size: 11-15 players Duration: 23:25.40 Personal best: 20:19.20", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completed Chambers of Xeric count is: 52.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 20 * 60 + 19.2); + } + + @Test + public void testPlayerSkillLookup() throws IOException + { + when(chatCommandsConfig.lvl()).thenReturn(true); + + SingleHiscoreSkillResult skillResult = new SingleHiscoreSkillResult(); + skillResult.setPlayer(PLAYER_NAME); + skillResult.setSkill(new Skill(10, 1000, -1)); + + when(hiscoreClient.lookup(PLAYER_NAME, HiscoreSkill.ZULRAH, null)).thenReturn(skillResult); + + MessageNode messageNode = mock(MessageNode.class); + + ChatMessage chatMessage = new ChatMessage(); + chatMessage.setType(ChatMessageType.PUBLICCHAT); + chatMessage.setName(PLAYER_NAME); + chatMessage.setMessageNode(messageNode); + chatCommandsPlugin.playerSkillLookup(chatMessage, "!lvl zulrah"); + + verify(messageNode).setRuneLiteFormatMessage("Level Zulrah: 1000 Rank: 10"); + } + + @Test + public void testHsFloorNoPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 1 time: 1:19. Personal best: 0:28", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 1", 28.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 1 time: 1:19.20. Personal best: 0:28.40", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 1", 28.4); + } + + @Test + public void testHsFloorPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 2 time: 0:47 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 2", 47.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 2 time: 0:47.20 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 2", 47.2); + } + + @Test + public void testHsOverallPb_Pb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 4:46 (new personal best)
Overall time: 9:53 (new personal best)
", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 4 * 60 + 46.0); + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 9 * 60 + 53.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 4:46.20 (new personal best)
Overall time: 9:53.40 (new personal best)
", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 4 * 60 + 46.2); + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 9 * 60 + 53.4); + } + + @Test + public void testHsOverallPb_NoPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:26 (new personal best)
Overall time: 9:17. Personal best: 9:15
", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 26.0); + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 9 * 60 + 15.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:26.20 (new personal best)
Overall time: 9:17.00. Personal best: 9:15.40
", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 26.2); + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 9 * 60 + 15.4); + } + + @Test + public void testHsOverallNoPb_NoPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:56. Personal best: 3:05
Overall time: 9:14. Personal best: 7:49
", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 5.0); + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 7 * 60 + 49.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:56.40. Personal best: 3:05.20
Overall time: 9:14.20. Personal best: 7:49.20
", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 5.2); + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 7 * 60 + 49.2); + } + + @Test + public void testHsOverallNoPb_Pb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:10. Personal best: 3:04
Overall time: 7:47 (new personal best)
", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 4.0); + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 7 * 60 + 47.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Floor 5 time: 3:10.00. Personal best: 3:04.40
Overall time: 7:47.20 (new personal best)
", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre floor 5", 3 * 60 + 4.4); + verify(configManager).setRSProfileConfiguration("personalbest", "hallowed sepulchre", 7 * 60 + 47.2); + } + + @Test + public void testHsFloorKc() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have completed Floor 5 of the Hallowed Sepulchre! Total completions: 1,114.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "hallowed sepulchre floor 5", 1114); + } + + @Test + public void testHsGhcKc() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "You have opened the Grand Hallowed Coffin 1,542 times!", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "hallowed sepulchre", 1542); + } + + @Test + public void testJadNewPbWithLeagueTask() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your TzTok-Jad kill count is: 2.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Congratulations, you've completed a master task: Complete the Fight Caves in 25:00.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 21:58 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 21 * 60 + 58.0); + verify(configManager).setRSProfileConfiguration("killcount", "tztok-jad", 2); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Duration: 21:58.40 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 21 * 60 + 58.4); + } + + @Test + public void testJadChallengeNewPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completion count for TzHaar-Ket-Rak's First Challenge is: 1.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 1:46 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 1); + verify(configManager).setRSProfileConfiguration("personalbest", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 60 + 46.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 1:46.40 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 60 + 46.4); + } + + @Test + public void testJadChallengeNoPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your completion count for TzHaar-Ket-Rak's First Challenge is: 3.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 1:10. Personal best: 0:59", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 3); + verify(configManager).setRSProfileConfiguration("personalbest", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 59.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Challenge duration: 1:10.00. Personal best: 0:59.20", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "TzHaar-Ket-Rak's First Challenge".toLowerCase(), 59.2); + } + + @Test + public void testTemporossNewPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in 6:35 (new personal best).", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: 60.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "tempoross", 60); + verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 6 * 60 + 35.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in 5:20.60 (new personal best).", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: 60.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 20.6); + } + + @Test + public void testTemporossNoPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in 7:40. Personal best: 5:38.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: 55.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "tempoross", 55); + verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 38.0); + + // Precise times + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Subdued in 6:19.80. Personal best: 5:42.60.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Tempoross kill count is: 55.", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 5 * 60 + 42.6); + } + + @Test + public void testNightmarePb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Nightmare kill count is: 1130", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Team size: 5 players Fight duration: 3:28 (new personal best)", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "nightmare", 1130); + verify(configManager).setRSProfileConfiguration("personalbest", "nightmare", 3 * 60 + 28.0); + } + + @Test + public void testNightmareNoPb() + { + ChatMessage chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Your Nightmare kill count is: 1130", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + chatMessage = new ChatMessage(null, GAMEMESSAGE, "", "Team size: Solo Fight duration: 10:47. Personal best: 8:44", null, 0); + chatCommandsPlugin.onChatMessage(chatMessage); + + verify(configManager).setRSProfileConfiguration("killcount", "nightmare", 1130); + verify(configManager).setRSProfileConfiguration("personalbest", "nightmare", 8 * 60 + 44.0); + } + + @Test + public void testPlayerPetList() + { + Widget logEntryHeaderWidget = mock(Widget.class); + when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER)).thenReturn(logEntryHeaderWidget); + + Widget[] logEntryHeaderItemsWidget = new Widget[1]; + when(logEntryHeaderWidget.getChildren()).thenReturn(logEntryHeaderItemsWidget); + + Widget logEntryHeaderTitleWidget = mock(Widget.class); + when(logEntryHeaderWidget.getChild(ChatCommandsPlugin.COL_LOG_ENTRY_HEADER_TITLE_INDEX)) + .thenReturn(logEntryHeaderTitleWidget); + when(logEntryHeaderTitleWidget.getText()).thenReturn("All Pets"); + + Widget logEntryItemsWidget = mock(Widget.class); + when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS)).thenReturn(logEntryItemsWidget); + + Widget[] logPetEntriesWidget = new Widget[3]; + for (int i = 0; i < 3; i++) + { + logPetEntriesWidget[i] = mock(Widget.class); + when(logPetEntriesWidget[i].getOpacity()).thenReturn(175); + } + + when(logPetEntriesWidget[1].getName()).thenReturn("Ikkle hydra"); + when(logPetEntriesWidget[1].getOpacity()).thenReturn(0); + + when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget); + + ScriptPostFired scriptPostFired = new ScriptPostFired(ScriptID.COLLECTION_DRAW_LIST); + chatCommandsPlugin.onScriptPostFired(scriptPostFired); + + chatCommandsPlugin.onGameTick(new GameTick()); + + Pet[] playerPetList = new Pet[1]; + playerPetList[0] = Pet.IKKLE_HYDRA; + + verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(playerPetList)); + } + + @Test + public void testEmptyPlayerPetList() + { + Widget logEntryHeaderWidget = mock(Widget.class); + when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER)).thenReturn(logEntryHeaderWidget); + + Widget[] logEntryHeaderItemsWidget = new Widget[1]; + when(logEntryHeaderWidget.getChildren()).thenReturn(logEntryHeaderItemsWidget); + + Widget logEntryHeaderTitleWidget = mock(Widget.class); + when(logEntryHeaderWidget.getChild(ChatCommandsPlugin.COL_LOG_ENTRY_HEADER_TITLE_INDEX)) + .thenReturn(logEntryHeaderTitleWidget); + when(logEntryHeaderTitleWidget.getText()).thenReturn("All Pets"); + + Widget logEntryItemsWidget = mock(Widget.class); + when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS)).thenReturn(logEntryItemsWidget); + + Widget[] logPetEntriesWidget = new Widget[3]; + for (int i = 0; i < 3; i++) + { + logPetEntriesWidget[i] = mock(Widget.class); + when(logPetEntriesWidget[i].getOpacity()).thenReturn(175); + } + + when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget); + + ScriptPostFired scriptPostFired = new ScriptPostFired(ScriptID.COLLECTION_DRAW_LIST); + chatCommandsPlugin.onScriptPostFired(scriptPostFired); + + chatCommandsPlugin.onGameTick(new GameTick()); + + verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(new Pet[0])); + } + + @Test + public void testUpdatePlayerPetList() + { + Widget logEntryHeaderWidget = mock(Widget.class); + when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_HEADER)).thenReturn(logEntryHeaderWidget); + + Widget[] logEntryHeaderItemsWidget = new Widget[1]; + when(logEntryHeaderWidget.getChildren()).thenReturn(logEntryHeaderItemsWidget); + + Widget logEntryHeaderTitleWidget = mock(Widget.class); + when(logEntryHeaderWidget.getChild(ChatCommandsPlugin.COL_LOG_ENTRY_HEADER_TITLE_INDEX)) + .thenReturn(logEntryHeaderTitleWidget); + when(logEntryHeaderTitleWidget.getText()).thenReturn("All Pets"); + + Widget logEntryItemsWidget = mock(Widget.class); + when(client.getWidget(WidgetInfo.COLLECTION_LOG_ENTRY_ITEMS)).thenReturn(logEntryItemsWidget); + + Widget[] logPetEntriesWidget = new Widget[3]; + for (int i = 0; i < 3; i++) + { + logPetEntriesWidget[i] = mock(Widget.class); + when(logPetEntriesWidget[i].getOpacity()).thenReturn(175); + } + + when(logPetEntriesWidget[1].getName()).thenReturn("Ikkle hydra"); + when(logPetEntriesWidget[1].getOpacity()).thenReturn(0); + + when(logEntryItemsWidget.getChildren()).thenReturn(logPetEntriesWidget); + + ScriptPostFired scriptPostFired = new ScriptPostFired(ScriptID.COLLECTION_DRAW_LIST); + chatCommandsPlugin.onScriptPostFired(scriptPostFired); + + chatCommandsPlugin.onGameTick(new GameTick()); + + Pet[] playerPetList = new Pet[1]; + playerPetList[0] = Pet.IKKLE_HYDRA; + + verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(playerPetList)); + + ChatMessage chatMessage = new ChatMessage(); + chatMessage.setMessage("New item added to your collection log: Chompy chick"); + chatMessage.setType(GAMEMESSAGE); + when(configManager.getRSProfileConfiguration("chatcommands", "pets", + String.class)).thenReturn(gson.toJson(playerPetList)); + chatCommandsPlugin.onChatMessage(chatMessage); + + playerPetList = new Pet[2]; + playerPetList[0] = Pet.IKKLE_HYDRA; + playerPetList[1] = Pet.CHOMPY_CHICK; + verify(configManager).setRSProfileConfiguration("chatcommands", "pets", gson.toJson(playerPetList)); + } + + @Test + public void testTimeStringToSeconds() + { + final double DELTA = 0.0001; + + // ss + assertEquals(55.0, ChatCommandsPlugin.timeStringToSeconds("55.00"), DELTA); + // mm:ss + assertEquals(6 * 60 + 55.4, ChatCommandsPlugin.timeStringToSeconds("6:55.40"), DELTA); + // h:mm:ss + assertEquals(2 * 3600 + 50 * 60 + 30.2, ChatCommandsPlugin.timeStringToSeconds("2:50:30.20"), DELTA); + } + + @Test + public void testCounters() + { + final String[] log = { + "Chompy Hunting", + "Kills: 1,003", + "Rank: Ogre Expert", + "", + "Order of the White Knights", + "Rank: Master", + "with a kill score of 1,300", + "", + "TzHaar Fight Cave", + "Fastest run: 33:53", + "", + "Inferno", + "Fastest run: 2:02:20", + "", + "Zulrah", + "Fastest kill: 0:47", + "", + "Vorkath", + "Fastest kill: 1:04", + "", + "Galvek", + "Fastest kill: -", + "", + "Grotesque Guardians", + "Fastest kill: 1:20", + "", + "Alchemical Hydra", + "Fastest kill: 1:34", + "", + "Hespori", + "Fastest kill: 1:24", + "", + // Nightmare is here 3x! + "Nightmare", // including one only called "Nightmare" + "Fastest kill: -", // with no time + "", + "The Nightmare", + "Fastest kill - (Team size: 6+ players): 3:22", + "", + "The Nightmare", + "Fastest kill - (Team size: 6+ players): 3:22", + "", + "Phosani's Nightmare", + "Fastest kill: -", + "", + "The Gauntlet", + "Fastest run: -", + "", + "The Corrupted Gauntlet", + "Fastest run: -", + "", + "Fragment of Seren", + "Fastest kill: -", + "", + "Chambers of Xeric", + "Fastest run - (Team size: Solo): 28:07", + "Fastest run - (Team size: 2 players): 24:40", + "Fastest run - (Team size: 3 players): 25:35", + "Fastest run - (Team size: 4 players): 22:40", + "Fastest run - (Team size: 5 players): 23:00", + "Fastest run - (Team size: 6 players): 28:11", + "", + "Chambers of Xeric - Challenge mode", + "Fastest run - (Team size: 3 players): 45:41", + "", + "Theatre of Blood", + "Fastest Room time (former): 18:45", + "Fastest Wave time (former): 22:01", + "Fastest Room time - (Team size: (3 player): 19:50", + "Fastest Overall time - (Team size: 3 player): 22:47", + "Fastest Room time - (Team size: (4 player): 17:38", + "Fastest Overall time - (Team size: 4 player): 20:31", + "Fastest Room time - (Team size: (5 player): 18:45", + "Fastest Overall time - (Team size: 5 player): 22:01", + "", + "Tempoross", + "Fastest run: 3:54", + "", + "Barbarian Assault", + "High-level gambles: 0", + "", + "Fremennik spirits rested: 0", + }; + + // adv log + Widget advLogWidget = mock(Widget.class); + Widget advLogExploitsTextWidget = mock(Widget.class); + when(advLogWidget.getChild(ChatCommandsPlugin.ADV_LOG_EXPLOITS_TEXT_INDEX)).thenReturn(advLogExploitsTextWidget); + when(advLogExploitsTextWidget.getText()).thenReturn("The Exploits of " + PLAYER_NAME); + when(client.getWidget(WidgetInfo.ADVENTURE_LOG)).thenReturn(advLogWidget); + + // counters + when(client.getWidget(WidgetInfo.DIARY_QUEST_WIDGET_TEXT)).thenAnswer(a -> + { + Widget widget = mock(Widget.class); + Widget[] children = Arrays.stream(log) + .map(s -> + { + Widget w = mock(Widget.class); + when(w.getText()).thenReturn(s); + return w; + }) + .toArray(Widget[]::new); + when(widget.getStaticChildren()).thenReturn(children); + return widget; + }); + + WidgetLoaded advLogEvent = new WidgetLoaded(); + advLogEvent.setGroupId(ADVENTURE_LOG_ID); + chatCommandsPlugin.onWidgetLoaded(advLogEvent); + chatCommandsPlugin.onGameTick(new GameTick()); + + WidgetLoaded countersLogEvent = new WidgetLoaded(); + countersLogEvent.setGroupId(DIARY_QUEST_GROUP_ID); + chatCommandsPlugin.onWidgetLoaded(countersLogEvent); + chatCommandsPlugin.onGameTick(new GameTick()); + + verify(configManager).setRSProfileConfiguration("personalbest", "tztok-jad", 2033.0); + verify(configManager).setRSProfileConfiguration("personalbest", "tempoross", 234.0); + verify(configManager).setRSProfileConfiguration("personalbest", "chambers of xeric", 1360.0); // the lowest time + } +} diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPluginTest.java index 1b903bf004..eb279f9567 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPluginTest.java @@ -155,12 +155,12 @@ public class NpcIndicatorsPluginTest when(npc.getName()).thenReturn("Joseph"); npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc)); - assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc)); + assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc)); when(npc.getName()).thenReturn("Werewolf"); npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null)); - assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc)); + assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc)); } @Test @@ -174,11 +174,11 @@ public class NpcIndicatorsPluginTest when(npc.getName()).thenReturn("Joseph"); npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc)); - assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc)); + assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc)); when(npc.getName()).thenReturn("Werewolf"); npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null)); - assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc)); + assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().containsKey(npc)); } }