From 7c3419574d8b87b339f3ccf31f2bbc94c61c59b6 Mon Sep 17 00:00:00 2001 From: Max Weber Date: Tue, 30 Jul 2019 09:24:40 -0600 Subject: [PATCH 1/7] itemidentification: Add crystal sapling --- .../client/plugins/itemidentification/ItemIdentification.java | 1 + 1 file changed, 1 insertion(+) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemidentification/ItemIdentification.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemidentification/ItemIdentification.java index 4ab740ffc2..5270579246 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemidentification/ItemIdentification.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemidentification/ItemIdentification.java @@ -72,6 +72,7 @@ enum ItemIdentification MAGIC_SAPLING(Type.SAPLING, "Magic", "MAG", ItemID.MAGIC_SAPLING, ItemID.MAGIC_SEEDLING, ItemID.MAGIC_SEEDLING_W), REDWOOD_SAPLING(Type.SAPLING, "Red", "RED", ItemID.REDWOOD_SAPLING, ItemID.REDWOOD_SEEDLING, ItemID.REDWOOD_SEEDLING_W), SPIRIT_SAPLING(Type.SAPLING, "Spirit", "SPI", ItemID.SPIRIT_SAPLING, ItemID.SPIRIT_SEEDLING, ItemID.SPIRIT_SEEDLING_W), + CRYSTAL_SAPLING(Type.SAPLING, "Crystal", "CRY", ItemID.CRYSTAL_SAPLING, ItemID.CRYSTAL_SEEDLING, ItemID.CRYSTAL_SEEDLING_W), APPLE_SAPLING(Type.SAPLING, "Apple", "APP", ItemID.APPLE_SAPLING, ItemID.APPLE_SEEDLING, ItemID.APPLE_SEEDLING_W), BANANA_SAPLING(Type.SAPLING, "Banana", "BAN", ItemID.BANANA_SAPLING, ItemID.BANANA_SEEDLING, ItemID.BANANA_SEEDLING_W), From 35fe719e5758dc54e415a6d1e643ce7d2eb5543f Mon Sep 17 00:00:00 2001 From: Alexsuperfly Date: Fri, 26 Jul 2019 17:12:53 -0400 Subject: [PATCH 2/7] skill calc: add Prifddinas agility course --- .../client/plugins/skillcalculator/skill_agility.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/skillcalculator/skill_agility.json b/runelite-client/src/main/resources/net/runelite/client/plugins/skillcalculator/skill_agility.json index 19fca53730..b72b8d59e9 100644 --- a/runelite-client/src/main/resources/net/runelite/client/plugins/skillcalculator/skill_agility.json +++ b/runelite-client/src/main/resources/net/runelite/client/plugins/skillcalculator/skill_agility.json @@ -78,6 +78,12 @@ "name": "Pollnivneach Rooftop", "xp": 890 }, + { + "level": 75, + "icon": 23962, + "name": "Prifddinas Agility Course", + "xp": 1220 + }, { "level": 80, "icon": 11849, From e52f8fbfd361d6fb077135b125fe4707e7cd3e5c Mon Sep 17 00:00:00 2001 From: Alexsuperfly Date: Tue, 30 Jul 2019 13:35:29 -0400 Subject: [PATCH 3/7] skill calc: add crystal tree --- .../client/plugins/skillcalculator/skill_farming.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/skillcalculator/skill_farming.json b/runelite-client/src/main/resources/net/runelite/client/plugins/skillcalculator/skill_farming.json index bc5cde0ef6..5953579264 100644 --- a/runelite-client/src/main/resources/net/runelite/client/plugins/skillcalculator/skill_farming.json +++ b/runelite-client/src/main/resources/net/runelite/client/plugins/skillcalculator/skill_farming.json @@ -240,6 +240,12 @@ "name": "Lantadyme", "xp": 134.5 }, + { + "level": 74, + "icon": 23962, + "name": "Crystal Tree", + "xp": 13366 + }, { "level": 75, "icon": 1513, From 993716e11aeeee9eb9bf1e3c554281bc300b4976 Mon Sep 17 00:00:00 2001 From: Quasindro Date: Wed, 17 Jul 2019 01:04:27 +0200 Subject: [PATCH 4/7] nmz: Add total and per hour points to NMZ overlay --- .../nightmarezone/NightmareZoneOverlay.java | 14 +++++- .../nightmarezone/NightmareZonePlugin.java | 48 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java index 71ae196d3e..d732d14d3b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java @@ -30,6 +30,7 @@ import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.ItemID; import static net.runelite.api.MenuAction.RUNELITE_OVERLAY_CONFIG; +import net.runelite.api.VarPlayer; import net.runelite.api.Varbits; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetInfo; @@ -101,10 +102,21 @@ class NightmareZoneOverlay extends Overlay renderAbsorptionCounter(); + final int currentPoints = client.getVar(Varbits.NMZ_POINTS); + final int totalPoints = currentPoints + client.getVar(VarPlayer.NMZ_REWARD_POINTS); + panelComponent.getChildren().clear(); panelComponent.getChildren().add(LineComponent.builder() .left("Points: ") - .right(StackFormatter.formatNumber(client.getVar(Varbits.NMZ_POINTS))) + .right(StackFormatter.formatNumber(currentPoints)) + .build()); + panelComponent.getChildren().add(LineComponent.builder() + .left("Points/Hour: ") + .right(StackFormatter.formatNumber(plugin.getPointsPerHour())) + .build()); + panelComponent.getChildren().add(LineComponent.builder() + .left("Total: ") + .right(StackFormatter.formatNumber(totalPoints)) .build()); return panelComponent.render(graphics); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java index d5b91a94cd..2f75094c7c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java @@ -25,8 +25,11 @@ package net.runelite.client.plugins.nightmarezone; import com.google.inject.Provides; +import java.time.Duration; +import java.time.Instant; import java.util.Arrays; import javax.inject.Inject; +import lombok.Getter; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.Varbits; @@ -51,6 +54,7 @@ import net.runelite.client.util.Text; public class NightmareZonePlugin extends Plugin { private static final int[] NMZ_MAP_REGION = {9033}; + private static final Duration HOUR = Duration.ofHours(1); @Inject private Notifier notifier; @@ -67,6 +71,11 @@ public class NightmareZonePlugin extends Plugin @Inject private NightmareZoneOverlay overlay; + @Getter + private int pointsPerHour; + + private Instant nmzSessionStartTime; + // This starts as true since you need to get // above the threshold before sending notifications private boolean absorptionNotificationSend = true; @@ -90,6 +99,8 @@ public class NightmareZonePlugin extends Plugin { nmzWidget.setHidden(false); } + + resetPointsPerHour(); } @Subscribe @@ -114,12 +125,23 @@ public class NightmareZonePlugin extends Plugin absorptionNotificationSend = true; } + if (nmzSessionStartTime != null) + { + resetPointsPerHour(); + } + return; } + if (config.absorptionNotification()) { checkAbsorption(); } + + if (config.moveOverlay()) + { + pointsPerHour = calculatePointsPerHour(); + } } @Subscribe @@ -193,6 +215,32 @@ public class NightmareZonePlugin extends Plugin } } + private int calculatePointsPerHour() + { + Instant now = Instant.now(); + final int currentPoints = client.getVar(Varbits.NMZ_POINTS); + + if (nmzSessionStartTime == null) + { + nmzSessionStartTime = now; + } + + Duration timeSinceStart = Duration.between(nmzSessionStartTime, now); + + if (!timeSinceStart.isZero()) + { + return (int) ((double) currentPoints * (double) HOUR.toMillis() / (double) timeSinceStart.toMillis()); + } + + return 0; + } + + private void resetPointsPerHour() + { + nmzSessionStartTime = null; + pointsPerHour = 0; + } + public boolean isInNightmareZone() { return Arrays.equals(client.getMapRegions(), NMZ_MAP_REGION); From b1ff529e02632f36ab6b2bb6fd4ee94c96aefe06 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 30 Jul 2019 09:33:44 -0400 Subject: [PATCH 5/7] fps plugin: move fps off logout button on bottom line mode --- .../runelite/client/plugins/fps/FpsOverlay.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/fps/FpsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/fps/FpsOverlay.java index 654277744b..22bf76373b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/fps/FpsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/fps/FpsOverlay.java @@ -31,6 +31,8 @@ import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.Point; import net.runelite.api.events.FocusChanged; +import net.runelite.api.widgets.Widget; +import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayPosition; @@ -48,7 +50,7 @@ import net.runelite.client.ui.overlay.OverlayUtil; public class FpsOverlay extends Overlay { private static final int Y_OFFSET = 1; - private static final int VALUE_X_OFFSET = 1; + private static final int X_OFFSET = 1; private static final String FPS_STRING = " FPS"; // Local dependencies @@ -91,13 +93,22 @@ public class FpsOverlay extends Overlay { return null; } + + // On resizable bottom line mode the logout button is at the top right, so offset the overlay + // to account for it + Widget logoutButton = client.getWidget(WidgetInfo.RESIZABLE_MINIMAP_LOGOUT_BUTTON); + int xOffset = X_OFFSET; + if (logoutButton != null && !logoutButton.isHidden()) + { + xOffset += logoutButton.getWidth(); + } final String text = client.getFPS() + FPS_STRING; final int textWidth = graphics.getFontMetrics().stringWidth(text); final int textHeight = graphics.getFontMetrics().getAscent() - graphics.getFontMetrics().getDescent(); final int width = (int) client.getRealDimensions().getWidth(); - final Point point = new Point(width - textWidth - VALUE_X_OFFSET, textHeight + Y_OFFSET); + final Point point = new Point(width - textWidth - xOffset, textHeight + Y_OFFSET); OverlayUtil.renderTextLocation(graphics, point, text, getFpsValueColor()); return null; From 8282742c1a12359d5aa291eabadae3e090fe8dba Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 27 Jul 2019 12:36:20 -0400 Subject: [PATCH 6/7] world hopper: change ping task to ping one world This will allow other tasks that are scheduled on the hopper executor to not be blocked for long periods of time due to the world pinger. This pings, at fixed delay, each world every 3 seconds, which for 200 worlds is at most as often as the previous mass-ping every 10 minutes. --- .../worldhopper/WorldHopperPlugin.java | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java index 31bc11a925..f68e2e0d05 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java @@ -96,7 +96,6 @@ import org.apache.commons.lang3.ArrayUtils; public class WorldHopperPlugin extends Plugin { private static final int WORLD_FETCH_TIMER = 10; - private static final int WORLD_PING_TIMER = 10; private static final int REFRESH_THROTTLE = 60_000; // ms private static final int TICK_THROTTLE = (int) Duration.ofMinutes(10).toMillis(); @@ -146,6 +145,7 @@ public class WorldHopperPlugin extends Plugin private ScheduledFuture worldResultFuture, pingFuture; private WorldResult worldResult; + private int currentWorld; private Instant lastFetch; private boolean firstRun; @@ -201,10 +201,14 @@ public class WorldHopperPlugin extends Plugin } panel.setFilterMode(config.subscriptionFilter()); + + // The plugin has its own executor for pings, as it blocks for a long time + hopperExecutorService = new ExecutorServiceExceptionLogger(Executors.newSingleThreadScheduledExecutor()); + // On first run this schedules an initial ping on hopperExecutorService worldResultFuture = executorService.scheduleAtFixedRate(this::tick, 0, WORLD_FETCH_TIMER, TimeUnit.MINUTES); - hopperExecutorService = new ExecutorServiceExceptionLogger(Executors.newSingleThreadScheduledExecutor()); - pingFuture = hopperExecutorService.scheduleAtFixedRate(this::pingWorlds, WORLD_PING_TIMER, WORLD_PING_TIMER, TimeUnit.MINUTES); + // Give some initial delay - this won't run until after pingInitialWorlds finishes from tick() anyway + pingFuture = hopperExecutorService.scheduleWithFixedDelay(this::pingNextWorld, 15, 3, TimeUnit.SECONDS); } @Override @@ -459,7 +463,8 @@ public class WorldHopperPlugin extends Plugin if (firstRun) { firstRun = false; - hopperExecutorService.execute(this::pingWorlds); + // On first run we ping all of the worlds at once to initialize the ping values + hopperExecutorService.execute(this::pingInitialWorlds); } } @@ -755,7 +760,10 @@ public class WorldHopperPlugin extends Plugin return null; } - private void pingWorlds() + /** + * Ping all worlds. This takes a long time and is only run on first run. + */ + private void pingInitialWorlds() { if (worldResult == null || !config.showSidebar() || !config.ping()) { @@ -774,4 +782,33 @@ public class WorldHopperPlugin extends Plugin log.debug("Done pinging worlds in {}", stopwatch.elapsed()); } + + /** + * Ping the next world + */ + private void pingNextWorld() + { + if (worldResult == null || !config.showSidebar() || !config.ping()) + { + return; + } + + List worlds = worldResult.getWorlds(); + if (worlds.isEmpty()) + { + return; + } + + if (currentWorld >= worlds.size()) + { + // Wrap back around + currentWorld = 0; + } + + World world = worlds.get(currentWorld++); + + int ping = Ping.ping(world); + log.trace("Ping for world {} is: {}", world.getId(), ping); + SwingUtilities.invokeLater(() -> panel.updatePing(world.getId(), ping)); + } } From c4ee95d6c7cb8fb45abd962df4edb218f2f1abb2 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 27 Jul 2019 12:36:31 -0400 Subject: [PATCH 7/7] world hopper: add option to show current world ping If enabled, the current world is pinged every second and the ping is drawn in an overlay Co-authored-by: gregg1494 --- .../worldhopper/WorldHopperConfig.java | 12 +++ .../worldhopper/WorldHopperPingOverlay.java | 93 +++++++++++++++++++ .../worldhopper/WorldHopperPlugin.java | 54 ++++++++++- 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPingOverlay.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperConfig.java index 8035af73fb..d21ed61e80 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperConfig.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Lotto + * Copyright (c) 2019, gregg1494 * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -123,4 +124,15 @@ public interface WorldHopperConfig extends Config { return SubscriptionFilterMode.BOTH; } + + @ConfigItem( + keyName = "displayPing", + name = "Display current ping", + description = "Displays ping to current game world", + position = 7 + ) + default boolean displayPing() + { + return false; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPingOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPingOverlay.java new file mode 100644 index 0000000000..cf4d1b924c --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPingOverlay.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2019, gregg1494 + * 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.worldhopper; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.api.Point; +import net.runelite.api.widgets.Widget; +import net.runelite.api.widgets.WidgetInfo; +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.OverlayPriority; +import net.runelite.client.ui.overlay.OverlayUtil; + +class WorldHopperPingOverlay extends Overlay +{ + private static final int Y_OFFSET = 11; + private static final int X_OFFSET = 1; + + private final Client client; + private final WorldHopperPlugin worldHopperPlugin; + private final WorldHopperConfig worldHopperConfig; + + @Inject + private WorldHopperPingOverlay(Client client, WorldHopperPlugin worldHopperPlugin, WorldHopperConfig worldHopperConfig) + { + this.client = client; + this.worldHopperPlugin = worldHopperPlugin; + this.worldHopperConfig = worldHopperConfig; + setLayer(OverlayLayer.ABOVE_WIDGETS); + setPriority(OverlayPriority.HIGH); + setPosition(OverlayPosition.DYNAMIC); + } + + @Override + public Dimension render(Graphics2D graphics) + { + if (!worldHopperConfig.displayPing()) + { + return null; + } + + final int ping = worldHopperPlugin.getCurrentPing(); + if (ping < 0) + { + return null; + } + + final String text = ping + " ms"; + final int textWidth = graphics.getFontMetrics().stringWidth(text); + final int textHeight = graphics.getFontMetrics().getAscent() - graphics.getFontMetrics().getDescent(); + + // Adjust ping offset for logout button + Widget logoutButton = client.getWidget(WidgetInfo.RESIZABLE_MINIMAP_LOGOUT_BUTTON); + int xOffset = X_OFFSET; + if (logoutButton != null && !logoutButton.isHidden()) + { + xOffset += logoutButton.getWidth(); + } + + final int width = (int) client.getRealDimensions().getWidth(); + final Point point = new Point(width - textWidth - xOffset, textHeight + Y_OFFSET); + OverlayUtil.renderTextLocation(graphics, point, text, Color.YELLOW); + + return null; + } +} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java index f68e2e0d05..a02401e795 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java @@ -1,6 +1,7 @@ /* * Copyright (c) 2017, Adam * Copyright (c) 2018, Lotto + * Copyright (c) 2019, gregg1494 * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -45,6 +46,7 @@ import java.util.concurrent.TimeUnit; import javax.imageio.ImageIO; import javax.inject.Inject; import javax.swing.SwingUtilities; +import lombok.AccessLevel; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import net.runelite.api.ChatMessageType; @@ -78,6 +80,7 @@ import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.worldhopper.ping.Ping; import net.runelite.client.ui.ClientToolbar; import net.runelite.client.ui.NavigationButton; +import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.util.ExecutorServiceExceptionLogger; import net.runelite.client.util.HotkeyListener; import net.runelite.client.util.Text; @@ -130,6 +133,12 @@ public class WorldHopperPlugin extends Plugin @Inject private WorldHopperConfig config; + @Inject + private OverlayManager overlayManager; + + @Inject + private WorldHopperPingOverlay worldHopperOverlay; + private ScheduledExecutorService hopperExecutorService; private NavigationButton navButton; @@ -143,12 +152,15 @@ public class WorldHopperPlugin extends Plugin private int favoriteWorld1, favoriteWorld2; - private ScheduledFuture worldResultFuture, pingFuture; + private ScheduledFuture worldResultFuture, pingFuture, currPingFuture; private WorldResult worldResult; private int currentWorld; private Instant lastFetch; private boolean firstRun; + @Getter(AccessLevel.PACKAGE) + private int currentPing; + private final HotkeyListener previousKeyListener = new HotkeyListener(() -> config.previousKey()) { @Override @@ -176,6 +188,7 @@ public class WorldHopperPlugin extends Plugin protected void startUp() throws Exception { firstRun = true; + currentPing = -1; keyManager.registerKeyListener(previousKeyListener); keyManager.registerKeyListener(nextKeyListener); @@ -200,6 +213,8 @@ public class WorldHopperPlugin extends Plugin clientToolbar.addNavigation(navButton); } + overlayManager.add(worldHopperOverlay); + panel.setFilterMode(config.subscriptionFilter()); // The plugin has its own executor for pings, as it blocks for a long time @@ -209,6 +224,7 @@ public class WorldHopperPlugin extends Plugin // Give some initial delay - this won't run until after pingInitialWorlds finishes from tick() anyway pingFuture = hopperExecutorService.scheduleWithFixedDelay(this::pingNextWorld, 15, 3, TimeUnit.SECONDS); + currPingFuture = hopperExecutorService.scheduleWithFixedDelay(this::pingCurrentWorld, 15, 1, TimeUnit.SECONDS); } @Override @@ -217,6 +233,11 @@ public class WorldHopperPlugin extends Plugin pingFuture.cancel(true); pingFuture = null; + currPingFuture.cancel(true); + currPingFuture = null; + + overlayManager.remove(worldHopperOverlay); + keyManager.unregisterKeyListener(previousKeyListener); keyManager.unregisterKeyListener(nextKeyListener); @@ -807,8 +828,39 @@ public class WorldHopperPlugin extends Plugin World world = worlds.get(currentWorld++); + // If we are displaying the ping overlay, there is a separate scheduled task for the current world + boolean displayPing = config.displayPing() && client.getGameState() == GameState.LOGGED_IN; + if (displayPing && client.getWorld() == world.getId()) + { + return; + } + int ping = Ping.ping(world); log.trace("Ping for world {} is: {}", world.getId(), ping); SwingUtilities.invokeLater(() -> panel.updatePing(world.getId(), ping)); } + + /** + * Ping the current world for the ping overlay + */ + private void pingCurrentWorld() + { + // There is no reason to ping the current world if not logged in, as the overlay doesn't draw + if (worldResult == null || !config.displayPing() || client.getGameState() != GameState.LOGGED_IN) + { + return; + } + + final World currentWorld = worldResult.findWorld(client.getWorld()); + if (currentWorld == null) + { + log.debug("unable to find current world: {}", client.getWorld()); + return; + } + + currentPing = Ping.ping(currentWorld); + log.trace("Ping for current world is: {}", currentPing); + + SwingUtilities.invokeLater(() -> panel.updatePing(currentWorld.getId(), currentPing)); + } }