From 018a2365f8c65fee168b604cbcf1a20e119f1ec7 Mon Sep 17 00:00:00 2001 From: Hydrox6 Date: Sun, 24 Nov 2019 03:32:20 +0000 Subject: [PATCH 1/9] kourendlibrary: replace `final static` with `static final` --- .../client/plugins/kourendlibrary/KourendLibraryOverlay.java | 2 +- .../client/plugins/kourendlibrary/KourendLibraryPlugin.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java index 5cf7910ee6..a98acf39ff 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java @@ -52,7 +52,7 @@ import net.runelite.client.ui.overlay.OverlayUtil; class KourendLibraryOverlay extends Overlay { - private final static int MAXIMUM_DISTANCE = 24; + private static final int MAXIMUM_DISTANCE = 24; private final Library library; private final Client client; private final KourendLibraryConfig config; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java index 7ad44d2f96..b5ac1904e0 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java @@ -69,9 +69,9 @@ public class KourendLibraryPlugin extends Plugin { private static final Pattern BOOK_EXTRACTOR = Pattern.compile("'(.*)'"); private static final Pattern TAG_MATCHER = Pattern.compile("(<[^>]*>)"); - final static int REGION = 6459; + static final int REGION = 6459; - final static boolean debug = false; + static final boolean debug = false; @Inject private ClientToolbar clientToolbar; From de496e2d785991114549c974cd19ce42f8e96970 Mon Sep 17 00:00:00 2001 From: Hydrox6 Date: Sun, 24 Nov 2019 03:30:51 +0000 Subject: [PATCH 2/9] kourendlibrary: fix prediction not resetting when layout changes --- .../net/runelite/client/plugins/kourendlibrary/Library.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/Library.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/Library.java index 02618031db..5af160da87 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/Library.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/Library.java @@ -131,7 +131,7 @@ class Library else if (state != SolvedState.NO_DATA) { // We know all of the possible things in this shelf. - if (book != null) + if (book != null || bookcase.getPossibleBooks().stream().noneMatch(Book::isDarkManuscript)) { // Check to see if our guess is wrong if (!bookcase.getPossibleBooks().contains(book)) From 09da86884abe1e9834a4e4da55090ecb7ba682e9 Mon Sep 17 00:00:00 2001 From: Hydrox6 Date: Sun, 24 Nov 2019 05:00:11 +0000 Subject: [PATCH 3/9] kourendlibrary: add tutorial overlay --- .../kourendlibrary/KourendLibraryConfig.java | 10 ++ .../kourendlibrary/KourendLibraryPlugin.java | 5 + .../KourendLibraryTutorialOverlay.java | 109 ++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryTutorialOverlay.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java index 6ec40a00fd..af7b9d7e60 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java @@ -52,4 +52,14 @@ public interface KourendLibraryConfig extends Config { return true; } + + @ConfigItem( + keyName = "showTutorialOverlay", + name = "Show tutorial overlay", + description = "Whether to show an overlay to help understand how to use the plugin" + ) + default boolean showTutorialOverlay() + { + return true; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java index b5ac1904e0..46abbec99e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java @@ -88,6 +88,9 @@ public class KourendLibraryPlugin extends Plugin @Inject private KourendLibraryOverlay overlay; + @Inject + private KourendLibraryTutorialOverlay tutorialOverlay; + @Inject private KourendLibraryConfig config; @@ -125,6 +128,7 @@ public class KourendLibraryPlugin extends Plugin .build(); overlayManager.add(overlay); + overlayManager.add(tutorialOverlay); updatePlayerBooks(); @@ -139,6 +143,7 @@ public class KourendLibraryPlugin extends Plugin { overlay.setHidden(true); overlayManager.remove(overlay); + overlayManager.remove(tutorialOverlay); clientToolbar.removeNavigation(navButton); buttonAttached = false; lastBookcaseClick = null; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryTutorialOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryTutorialOverlay.java new file mode 100644 index 0000000000..6d6f3b4796 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryTutorialOverlay.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2019 Hydrox6 + * 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.kourendlibrary; + +import net.runelite.api.Client; +import net.runelite.api.Player; +import net.runelite.api.coords.WorldPoint; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.OverlayPriority; +import net.runelite.client.ui.overlay.components.LineComponent; +import net.runelite.client.ui.overlay.components.PanelComponent; +import javax.inject.Inject; +import java.awt.Dimension; +import java.awt.Graphics2D; + +class KourendLibraryTutorialOverlay extends Overlay +{ + private final Client client; + private final KourendLibraryConfig config; + private final Library library; + + private final PanelComponent panelComponent; + private final LineComponent noDataMessageComponent; + private final LineComponent incompleteMessageComponent; + private final LineComponent completeMessageComponent; + private final LineComponent sidebarMessageComponent; + + @Inject + private KourendLibraryTutorialOverlay(Client client, KourendLibraryConfig config, Library library) + { + this.client = client; + this.config = config; + this.library = library; + + panelComponent = new PanelComponent(); + panelComponent.setPreferredSize(new Dimension(177, 0)); + + noDataMessageComponent = LineComponent.builder().left("Click on the white squares to start finding books.").build(); + incompleteMessageComponent = LineComponent.builder().left("Some books have been found. Keep checking marked bookcases to find more.").build(); + completeMessageComponent = LineComponent.builder().left("All books found.").build(); + sidebarMessageComponent = LineComponent.builder().left("Locations are in the sidebar.").build(); + + setPriority(OverlayPriority.LOW); + setPosition(OverlayPosition.TOP_LEFT); + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (!config.showTutorialOverlay()) + { + return null; + } + + Player player = client.getLocalPlayer(); + if (player == null) + { + return null; + } + + WorldPoint playerLoc = player.getWorldLocation(); + if (playerLoc.getRegionID() != KourendLibraryPlugin.REGION) + { + return null; + } + + panelComponent.getChildren().clear(); + + switch (library.getState()) + { + case NO_DATA: + panelComponent.getChildren().add(noDataMessageComponent); + break; + case INCOMPLETE: + panelComponent.getChildren().add(incompleteMessageComponent); + panelComponent.getChildren().add(sidebarMessageComponent); + break; + case COMPLETE: + panelComponent.getChildren().add(completeMessageComponent); + panelComponent.getChildren().add(sidebarMessageComponent); + break; + } + + return panelComponent.render(graphics); + } +} From 76fdb50fa682b32e6c0544db39c2bb927aca55c4 Mon Sep 17 00:00:00 2001 From: Hydrox6 Date: Mon, 25 Nov 2019 12:22:47 +0000 Subject: [PATCH 4/9] kourendlibrary: remove unneeded hidden flag from overlay From testing, this flag didn't seem to do anything useful. It might have also led to certain users thinking that the plugin was broken if they had enabled the plugin after the client was started. --- .../plugins/kourendlibrary/KourendLibraryOverlay.java | 10 ---------- .../plugins/kourendlibrary/KourendLibraryPlugin.java | 3 --- 2 files changed, 13 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java index a98acf39ff..682aee3ace 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java @@ -36,8 +36,6 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import javax.annotation.Nullable; -import lombok.AccessLevel; -import lombok.Setter; import net.runelite.api.Client; import net.runelite.api.Perspective; import static net.runelite.api.Perspective.getCanvasTilePoly; @@ -58,9 +56,6 @@ class KourendLibraryOverlay extends Overlay private final KourendLibraryConfig config; private final KourendLibraryPlugin plugin; - @Setter(AccessLevel.PACKAGE) - private boolean hidden; - @Inject private KourendLibraryOverlay(Library library, Client client, KourendLibraryConfig config, KourendLibraryPlugin plugin) { @@ -76,11 +71,6 @@ class KourendLibraryOverlay extends Overlay @Override public Dimension render(Graphics2D g) { - if (hidden) - { - return null; - } - Player player = client.getLocalPlayer(); if (player == null) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java index 46abbec99e..dbc19fdf63 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java @@ -141,7 +141,6 @@ public class KourendLibraryPlugin extends Plugin @Override protected void shutDown() { - overlay.setHidden(true); overlayManager.remove(overlay); overlayManager.remove(tutorialOverlay); clientToolbar.removeNavigation(navButton); @@ -187,7 +186,6 @@ public class KourendLibraryPlugin extends Plugin if (MenuAction.GAME_OBJECT_FIRST_OPTION == menuOpt.getMenuAction() && menuOpt.getMenuTarget().contains("Bookshelf")) { lastBookcaseClick = WorldPoint.fromScene(client, menuOpt.getActionParam(), menuOpt.getWidgetId(), client.getPlane()); - overlay.setHidden(false); } } @@ -273,7 +271,6 @@ public class KourendLibraryPlugin extends Plugin return; } - overlay.setHidden(false); library.setCustomer(cust, book); panel.update(); } From 67f7927b3e73216416db439e2228dae0e121f6ea Mon Sep 17 00:00:00 2001 From: Shawn Shadrix Date: Wed, 27 Nov 2019 12:57:03 +0000 Subject: [PATCH 5/9] kourendlibrary: highlight the customer's desired book in the overlay --- .../client/plugins/kourendlibrary/KourendLibraryOverlay.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java index 682aee3ace..2af0381076 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java @@ -125,7 +125,7 @@ class KourendLibraryOverlay extends Overlay book = possible.iterator().next(); bookIsKnown = true; } - Color color = bookIsKnown ? Color.ORANGE : Color.WHITE; + Color color = bookIsKnown ? (book == library.getCustomerBook() ? Color.GREEN : Color.ORANGE) : Color.WHITE; // Render the poly on the floor if (!(bookIsKnown && book == null) && (library.getState() == SolvedState.NO_DATA || book != null || !possible.isEmpty()) && !shouldHideOverlayIfDuplicateBook(book)) From 0527abce8173b5de83a9b03d5dff9f8332f0cf97 Mon Sep 17 00:00:00 2001 From: Hydrox6 Date: Wed, 27 Nov 2019 13:19:45 +0000 Subject: [PATCH 6/9] kourendlibrary: add option to hide Varlamore Envoy Co-authored-by: Shawn Shadrix --- .../kourendlibrary/KourendLibraryConfig.java | 10 +++++++++ .../kourendlibrary/KourendLibraryOverlay.java | 6 ++++++ .../kourendlibrary/KourendLibraryPanel.java | 21 +++++++++++++++++-- .../kourendlibrary/KourendLibraryPlugin.java | 5 +++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java index af7b9d7e60..2abb7c2255 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryConfig.java @@ -53,6 +53,16 @@ public interface KourendLibraryConfig extends Config return true; } + @ConfigItem( + keyName = "hideVarlamoreEnvoy", + name = "Hide Varlamore Envoy", + description = "Whether to hide Varlamore Envoy, as it is only required in the Depths of Despair quest, and is never asked for." + ) + default boolean hideVarlamoreEnvoy() + { + return false; + } + @ConfigItem( keyName = "showTutorialOverlay", name = "Show tutorial overlay", diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java index 2af0381076..d54fc448f5 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java @@ -125,6 +125,12 @@ class KourendLibraryOverlay extends Overlay book = possible.iterator().next(); bookIsKnown = true; } + + if (book == Book.VARLAMORE_ENVOY && config.hideVarlamoreEnvoy()) + { + continue; + } + Color color = bookIsKnown ? (book == library.getCustomerBook() ? Color.GREEN : Color.ORANGE) : Color.WHITE; // Render the poly on the floor diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java index 90900667f1..f65f0c7a63 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPanel.java @@ -54,8 +54,8 @@ class KourendLibraryPanel extends PluginPanel private static final ImageIcon RESET_ICON; private static final ImageIcon RESET_CLICK_ICON; - @Inject - private Library library; + private final KourendLibraryConfig config; + private final Library library; private final HashMap bookPanels = new HashMap<>(); @@ -66,6 +66,15 @@ class KourendLibraryPanel extends PluginPanel RESET_CLICK_ICON = new ImageIcon(ImageUtil.alphaOffset(resetIcon, -100)); } + @Inject + KourendLibraryPanel(KourendLibraryConfig config, Library library) + { + super(); + + this.config = config; + this.library = library; + } + void init() { setLayout(new BorderLayout(0, 5)); @@ -80,6 +89,7 @@ class KourendLibraryPanel extends PluginPanel c.gridy = 0; Stream.of(Book.values()) .filter(b -> !b.isDarkManuscript()) + .filter(b -> !config.hideVarlamoreEnvoy() || b != Book.VARLAMORE_ENVOY) .sorted(Comparator.comparing(Book::getShortName)) .forEach(b -> { @@ -156,4 +166,11 @@ class KourendLibraryPanel extends PluginPanel } }); } + + void reload() + { + bookPanels.clear(); + removeAll(); + init(); + } } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java index dbc19fdf63..030b7d9252 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java @@ -158,6 +158,11 @@ public class KourendLibraryPlugin extends Plugin return; } + if (ev.getKey().equals("hideVarlamoreEnvoy")) + { + panel.reload(); + } + SwingUtilities.invokeLater(() -> { if (!config.hideButton()) From 7734b1199e817622bce22574472a62e0489b857a Mon Sep 17 00:00:00 2001 From: Hydrox6 Date: Wed, 27 Nov 2019 23:21:39 +0000 Subject: [PATCH 7/9] kourendlibrary: optimize NPC marking code --- .../kourendlibrary/KourendLibraryOverlay.java | 32 +++++++++++-------- .../kourendlibrary/KourendLibraryPlugin.java | 25 +++++++++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java index d54fc448f5..b317d5d89c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java @@ -37,6 +37,7 @@ import java.util.Set; import java.util.stream.Collectors; import javax.annotation.Nullable; import net.runelite.api.Client; +import net.runelite.api.NPC; import net.runelite.api.Perspective; import static net.runelite.api.Perspective.getCanvasTilePoly; import net.runelite.api.Player; @@ -212,21 +213,24 @@ class KourendLibraryOverlay extends Overlay LibraryCustomer customer = library.getCustomer(); if (customer != null) { - client.getNpcs().stream() - .filter(n -> n.getId() == customer.getId()) - .forEach(n -> + for (NPC n : plugin.getNpcsToMark()) + { + if (n.getId() != customer.getId()) { - Book b = library.getCustomerBook(); - boolean doesPlayerContainBook = b != null && plugin.doesPlayerContainBook(b); - LocalPoint local = n.getLocalLocation(); - Polygon poly = getCanvasTilePoly(client, local); - OverlayUtil.renderPolygon(g, poly, doesPlayerContainBook ? Color.GREEN : Color.WHITE); - Point screen = Perspective.localToCanvas(client, local, client.getPlane(), n.getLogicalHeight()); - if (screen != null) - { - g.drawImage(b.getIcon(), screen.getX() - (b.getIcon().getWidth() / 2), screen.getY() - b.getIcon().getHeight(), null); - } - }); + continue; + } + + Book b = library.getCustomerBook(); + boolean doesPlayerContainBook = plugin.doesPlayerContainBook(b); + LocalPoint local = n.getLocalLocation(); + Polygon poly = getCanvasTilePoly(client, local); + OverlayUtil.renderPolygon(g, poly, doesPlayerContainBook ? Color.GREEN : Color.WHITE); + Point screen = Perspective.localToCanvas(client, local, client.getPlane(), n.getLogicalHeight()); + if (screen != null) + { + g.drawImage(b.getIcon(), screen.getX() - (b.getIcon().getWidth() / 2), screen.getY() - b.getIcon().getHeight(), null); + } + } } return null; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java index 030b7d9252..cf2d5bca44 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java @@ -27,10 +27,14 @@ package net.runelite.client.plugins.kourendlibrary; import com.google.inject.Provides; import java.awt.image.BufferedImage; import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.inject.Inject; import javax.swing.SwingUtilities; +import lombok.AccessLevel; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import net.runelite.api.AnimationID; import net.runelite.api.ChatMessageType; @@ -39,10 +43,13 @@ import net.runelite.api.InventoryID; import net.runelite.api.Item; import net.runelite.api.ItemContainer; import net.runelite.api.MenuAction; +import net.runelite.api.NPC; import net.runelite.api.Player; import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.AnimationChanged; import net.runelite.api.events.ChatMessage; +import net.runelite.api.events.NpcDespawned; +import net.runelite.api.events.NpcSpawned; import net.runelite.client.events.ConfigChanged; import net.runelite.api.events.GameTick; import net.runelite.api.events.ItemContainerChanged; @@ -104,6 +111,9 @@ public class KourendLibraryPlugin extends Plugin private WorldPoint lastBookcaseAnimatedOn = null; private EnumSet playerBooks = null; + @Getter(AccessLevel.PACKAGE) + private final Set npcsToMark = new HashSet<>(); + @Provides KourendLibraryConfig provideConfig(ConfigManager configManager) { @@ -294,6 +304,21 @@ public class KourendLibraryPlugin extends Plugin updatePlayerBooks(); } + @Subscribe + public void onNpcSpawned(NpcSpawned event) + { + if (LibraryCustomer.getById(event.getNpc().getId()) != null) + { + npcsToMark.add(event.getNpc()); + } + } + + @Subscribe + public void onNpcDespawned(NpcDespawned event) + { + npcsToMark.remove(event.getNpc()); + } + boolean doesPlayerContainBook(Book book) { return playerBooks.contains(book); From c0b193fd2e1d76678cf906bdaa1073033d1c943f Mon Sep 17 00:00:00 2001 From: Hydrox6 Date: Wed, 4 Dec 2019 16:05:48 +0000 Subject: [PATCH 8/9] kourendlibrary: remove LibraryCustomer --- .../kourendlibrary/KourendLibraryOverlay.java | 6 +- .../kourendlibrary/KourendLibraryPlugin.java | 15 +++-- .../plugins/kourendlibrary/Library.java | 6 +- .../kourendlibrary/LibraryCustomer.java | 67 ------------------- 4 files changed, 16 insertions(+), 78 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/LibraryCustomer.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java index b317d5d89c..31d304e782 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryOverlay.java @@ -210,12 +210,12 @@ class KourendLibraryOverlay extends Overlay } // Render the customer's wanted book on their head and a poly under their feet - LibraryCustomer customer = library.getCustomer(); - if (customer != null) + int customerId = library.getCustomerId(); + if (customerId != -1) { for (NPC n : plugin.getNpcsToMark()) { - if (n.getId() != customer.getId()) + if (n.getId() != customerId) { continue; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java index cf2d5bca44..c9770baab7 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/KourendLibraryPlugin.java @@ -44,6 +44,7 @@ import net.runelite.api.Item; import net.runelite.api.ItemContainer; import net.runelite.api.MenuAction; import net.runelite.api.NPC; +import net.runelite.api.NpcID; import net.runelite.api.Player; import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.AnimationChanged; @@ -270,8 +271,7 @@ public class KourendLibraryPlugin extends Plugin Widget npcHead = client.getWidget(WidgetInfo.DIALOG_NPC_HEAD_MODEL); if (npcHead != null) { - LibraryCustomer cust = LibraryCustomer.getById(npcHead.getModelId()); - if (cust != null) + if (isLibraryCustomer(npcHead.getModelId())) { Widget textw = client.getWidget(WidgetInfo.DIALOG_NPC_TEXT); String text = textw.getText(); @@ -286,12 +286,12 @@ public class KourendLibraryPlugin extends Plugin return; } - library.setCustomer(cust, book); + library.setCustomer(npcHead.getModelId(), book); panel.update(); } else if (text.contains("You can have this other book") || text.contains("please accept a token of my thanks.") || text.contains("Thanks, I'll get on with reading it.")) { - library.setCustomer(null, null); + library.setCustomer(-1, null); panel.update(); } } @@ -307,7 +307,7 @@ public class KourendLibraryPlugin extends Plugin @Subscribe public void onNpcSpawned(NpcSpawned event) { - if (LibraryCustomer.getById(event.getNpc().getId()) != null) + if (isLibraryCustomer(event.getNpc().getId())) { npcsToMark.add(event.getNpc()); } @@ -345,4 +345,9 @@ public class KourendLibraryPlugin extends Plugin playerBooks = books; } } + + static boolean isLibraryCustomer(int npcId) + { + return npcId == NpcID.VILLIA || npcId == NpcID.PROFESSOR_GRACKLEBONE || npcId == NpcID.SAM_7049; + } } \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/Library.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/Library.java index 5af160da87..ea74a84b39 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/Library.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/Library.java @@ -74,7 +74,7 @@ class Library private Book customerBook; @Getter - private LibraryCustomer customer; + private int customerId; Library() { @@ -93,9 +93,9 @@ class Library return Collections.unmodifiableList(byIndex); } - void setCustomer(LibraryCustomer customer, Book book) + void setCustomer(int customerId, Book book) { - this.customer = customer; + this.customerId = customerId; this.customerBook = book; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/LibraryCustomer.java b/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/LibraryCustomer.java deleted file mode 100644 index 229ed37efe..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/kourendlibrary/LibraryCustomer.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2018 Abex - * 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.kourendlibrary; - -import java.util.HashMap; -import java.util.Map; -import lombok.Getter; - -import net.runelite.api.NpcID; - -enum LibraryCustomer -{ - VILLIA(NpcID.VILLIA, "Villia"), - PROFESSOR_GRACKLEBONE(NpcID.PROFESSOR_GRACKLEBONE, "Prof. Gracklebone"), - SAM(NpcID.SAM_7049, "Sam"); - - @Getter - private final int id; - - @Getter - private final String name; - - private static final Map byId = buildIdMap(); - - LibraryCustomer(int id, String name) - { - this.id = id; - this.name = name; - } - - static LibraryCustomer getById(int id) - { - return byId.get(id); - } - - private static Map buildIdMap() - { - Map byId = new HashMap<>(); - for (LibraryCustomer c : values()) - { - byId.put(c.id, c); - } - return byId; - } -} From a0e867ec8e1116fe653944139c7ade26a81127c3 Mon Sep 17 00:00:00 2001 From: Max Weber Date: Thu, 5 Dec 2019 08:40:39 -0700 Subject: [PATCH 9/9] fix ChatSplitBuilder crashing when receiving a friend login/out message --- runelite-client/src/main/scripts/ChatSplitBuilder.rs2asm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runelite-client/src/main/scripts/ChatSplitBuilder.rs2asm b/runelite-client/src/main/scripts/ChatSplitBuilder.rs2asm index 6c87c8b256..f8e1ca2f4c 100644 --- a/runelite-client/src/main/scripts/ChatSplitBuilder.rs2asm +++ b/runelite-client/src/main/scripts/ChatSplitBuilder.rs2asm @@ -482,7 +482,7 @@ LABEL407: runelite_callback ; Invoke callback pop_int ; Pop the id of the messageNode sload 0 ; Load the log in/out message - join_string 3 ; Add the timestamp to the message + join_string 2 ; Add the timestamp to the message iload 9 iload 10 iconst 10682368