diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/ClueScrollPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/ClueScrollPlugin.java index ae999af2df..c8ea036c76 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/ClueScrollPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/ClueScrollPlugin.java @@ -34,6 +34,7 @@ import java.time.Duration; import java.time.Instant; import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.stream.Stream; import javax.imageio.ImageIO; import javax.inject.Inject; @@ -76,6 +77,7 @@ import net.runelite.client.plugins.cluescrolls.clues.EmoteClue; import net.runelite.client.plugins.cluescrolls.clues.FairyRingClue; import net.runelite.client.plugins.cluescrolls.clues.HotColdClue; import net.runelite.client.plugins.cluescrolls.clues.LocationClueScroll; +import net.runelite.client.plugins.cluescrolls.clues.LocationsClueScroll; import net.runelite.client.plugins.cluescrolls.clues.MapClue; import net.runelite.client.plugins.cluescrolls.clues.NpcClueScroll; import net.runelite.client.plugins.cluescrolls.clues.ObjectClueScroll; @@ -138,10 +140,9 @@ public class ClueScrollPlugin extends Plugin @Inject private WorldMapPointManager worldMapPointManager; - private ClueScrollWorldMapPoint worldMapPoint; - private Integer clueItemId; private boolean clueItemChanged = false; + private boolean worldMapPointsSet = false; static { @@ -187,9 +188,9 @@ public class ClueScrollPlugin extends Plugin return; } - if (clue instanceof HotColdClue) + if (clue instanceof LocationsClueScroll) { - ((HotColdClue)clue).update(event.getMessage(), this); + ((LocationsClueScroll)clue).update(event.getMessage(), this); } if (!event.getMessage().equals("The strange device cools as you find your treasure.") @@ -257,6 +258,12 @@ public class ClueScrollPlugin extends Plugin objectsToMark = null; equippedItems = null; + if (clue instanceof LocationsClueScroll) + { + final List locations = ((LocationsClueScroll) clue).getLocations(); + addMapPoints(locations.toArray(new WorldPoint[locations.size()])); + } + // If we have location clue, set world location before all other types of clues // to allow NPCs and objects to override it when needed if (clue instanceof LocationClueScroll) @@ -268,7 +275,7 @@ public class ClueScrollPlugin extends Plugin client.setHintArrow(location); } - setMapPoint(location); + addMapPoints(location); } if (clue instanceof NpcClueScroll) @@ -288,7 +295,7 @@ public class ClueScrollPlugin extends Plugin client.setHintArrow(npcsToMark[0]); } - setMapPoint(npcsToMark[0].getWorldLocation()); + addMapPoints(npcsToMark[0].getWorldLocation()); } } } @@ -381,19 +388,15 @@ public class ClueScrollPlugin extends Plugin clueItemId = null; } - if (clue instanceof HotColdClue) + if (clue instanceof LocationsClueScroll) { - ((HotColdClue) clue).resetHotCold(); + ((LocationsClueScroll) clue).reset(); } clueItemChanged = false; clue = null; - - if (worldMapPoint != null) - { - worldMapPointManager.remove(worldMapPoint); - worldMapPoint = null; - } + worldMapPointManager.removeIf(point -> point instanceof ClueScrollWorldMapPoint); + worldMapPointsSet = false; if (config.displayHintArrows()) { @@ -549,12 +552,18 @@ public class ClueScrollPlugin extends Plugin return new WorldPoint(x2, y2, 0); } - private void setMapPoint(WorldPoint point) + private void addMapPoints(WorldPoint... points) { - if (worldMapPoint == null) + if (worldMapPointsSet) { - worldMapPoint = new ClueScrollWorldMapPoint(point); - worldMapPointManager.add(worldMapPoint); + return; + } + + worldMapPointsSet = true; + + for (final WorldPoint point : points) + { + worldMapPointManager.add(new ClueScrollWorldMapPoint(point)); } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/HotColdClue.java b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/HotColdClue.java index f088b9edc2..4325747df7 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/HotColdClue.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/HotColdClue.java @@ -24,6 +24,7 @@ */ package net.runelite.client.plugins.cluescrolls.clues; +import com.google.common.collect.Lists; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; @@ -58,7 +59,7 @@ import net.runelite.client.ui.overlay.components.TitleComponent; @Getter @RequiredArgsConstructor -public class HotColdClue extends ClueScroll implements TextClueScroll, NpcClueScroll +public class HotColdClue extends ClueScroll implements LocationClueScroll, LocationsClueScroll, TextClueScroll, NpcClueScroll { private static final Pattern INITIAL_STRANGE_DEVICE_MESSAGE = Pattern.compile("The device is (.*)"); private static final Pattern STRANGE_DEVICE_MESSAGE = Pattern.compile("The device is (.*), (.*) last time\\."); @@ -76,6 +77,22 @@ public class HotColdClue extends ClueScroll implements TextClueScroll, NpcClueSc private WorldPoint location; private WorldPoint lastWorldPoint; + public static HotColdClue forText(String text) + { + if (CLUE.text.equalsIgnoreCase(text)) + { + return CLUE; + } + + return null; + } + + @Override + public List getLocations() + { + return Lists.transform(digLocations, HotColdLocation::getWorldPoint); + } + @Override public void makeOverlayHint(PanelComponent panelComponent, ClueScrollPlugin plugin) { @@ -230,16 +247,7 @@ public class HotColdClue extends ClueScroll implements TextClueScroll, NpcClueSc } } - public static HotColdClue forText(String text) - { - if (CLUE.text.equalsIgnoreCase(text)) - { - return CLUE; - } - - return null; - } - + @Override public void update(final String message, final ClueScrollPlugin plugin) { if (!message.startsWith("The device is")) @@ -285,6 +293,13 @@ public class HotColdClue extends ClueScroll implements TextClueScroll, NpcClueSc } } + @Override + public void reset() + { + this.lastWorldPoint = null; + digLocations.clear(); + } + private void updatePossibleArea(WorldPoint currentWp, String temperature, String difference) { this.location = null; @@ -400,12 +415,6 @@ public class HotColdClue extends ClueScroll implements TextClueScroll, NpcClueSc private void markFinalSpot(WorldPoint wp) { this.location = wp; - resetHotCold(); - } - - public void resetHotCold() - { - this.lastWorldPoint = null; - digLocations.clear(); + reset(); } } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/LocationsClueScroll.java b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/LocationsClueScroll.java new file mode 100644 index 0000000000..8da309171e --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cluescrolls/clues/LocationsClueScroll.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * 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.cluescrolls.clues; + +import java.util.List; +import net.runelite.api.coords.WorldPoint; +import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin; + +public interface LocationsClueScroll +{ + void update(String message, ClueScrollPlugin plugin); + + void reset(); + + List getLocations(); +} diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlayMouseListener.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlayMouseListener.java index b86fb7e455..2ef625ff10 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlayMouseListener.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlayMouseListener.java @@ -56,7 +56,8 @@ public class WorldMapOverlayMouseListener extends MouseListener @Override public MouseEvent mousePressed(MouseEvent e) { - List worldMapPoints = worldMapPointManager.getWorldMapPoints(); + final List worldMapPoints = worldMapPointManager.getWorldMapPoints(); + if (SwingUtilities.isLeftMouseButton(e) && !worldMapPoints.isEmpty()) { Point mousePos = clientProvider.get().getMouseCanvasPosition(); @@ -84,7 +85,8 @@ public class WorldMapOverlayMouseListener extends MouseListener @Override public MouseEvent mouseMoved(MouseEvent mouseEvent) { - List worldMapPoints = worldMapPointManager.getWorldMapPoints(); + final List worldMapPoints = worldMapPointManager.getWorldMapPoints(); + if (worldMapPoints.isEmpty()) { return mouseEvent; diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPointManager.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPointManager.java index ae836478b9..1f0f5d051b 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPointManager.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapPointManager.java @@ -26,6 +26,7 @@ package net.runelite.client.ui.overlay.worldmap; import java.util.ArrayList; import java.util.List; +import java.util.function.Predicate; import javax.inject.Singleton; import lombok.AccessLevel; import lombok.Getter; @@ -45,4 +46,9 @@ public class WorldMapPointManager { worldMapPoints.remove(worldMapPoint); } + + public void removeIf(Predicate filter) + { + worldMapPoints.removeIf(filter); + } }