From 665b021c858eccc4459d76b7769845d1cd7b76c1 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 28 Nov 2019 09:00:56 -0500 Subject: [PATCH] client: fix world hopper not populating worlds on startup and when refreshed --- .../runelite/client/events/WorldsFetch.java | 37 +++++++++++++++++++ .../runelite/client/game/WorldService.java | 8 +++- .../worldhopper/WorldHopperPlugin.java | 10 +++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/events/WorldsFetch.java diff --git a/runelite-client/src/main/java/net/runelite/client/events/WorldsFetch.java b/runelite-client/src/main/java/net/runelite/client/events/WorldsFetch.java new file mode 100644 index 0000000000..cc07aa5a23 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/events/WorldsFetch.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019, 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.events; + +import lombok.Value; +import net.runelite.http.api.worlds.WorldResult; + +/** + * Fired when the @{link net.runelite.client.game.WorldService} refreshes the world list + */ +@Value +public class WorldsFetch +{ + private final WorldResult worldResult; +} diff --git a/runelite-client/src/main/java/net/runelite/client/game/WorldService.java b/runelite-client/src/main/java/net/runelite/client/game/WorldService.java index 0740c59c07..263f712a25 100644 --- a/runelite-client/src/main/java/net/runelite/client/game/WorldService.java +++ b/runelite-client/src/main/java/net/runelite/client/game/WorldService.java @@ -37,6 +37,8 @@ import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; import net.runelite.api.Client; import net.runelite.api.GameState; +import net.runelite.client.eventbus.EventBus; +import net.runelite.client.events.WorldsFetch; import net.runelite.client.util.RunnableExceptionLogger; import net.runelite.http.api.worlds.World; import net.runelite.http.api.worlds.WorldClient; @@ -51,16 +53,19 @@ public class WorldService private final Client client; private final ScheduledExecutorService scheduledExecutorService; private final WorldClient worldClient; + private final EventBus eventBus; private final CompletableFuture firstRunFuture = new CompletableFuture<>(); private WorldResult worlds; @Inject - private WorldService(Client client, ScheduledExecutorService scheduledExecutorService, WorldClient worldClient) + private WorldService(Client client, ScheduledExecutorService scheduledExecutorService, WorldClient worldClient, + EventBus eventBus) { this.client = client; this.scheduledExecutorService = scheduledExecutorService; this.worldClient = worldClient; + this.eventBus = eventBus; scheduledExecutorService.scheduleWithFixedDelay(RunnableExceptionLogger.wrap(this::tick), 0, WORLD_FETCH_TIMER, TimeUnit.MINUTES); } @@ -89,6 +94,7 @@ public class WorldService WorldResult worldResult = worldClient.lookupWorlds(); worldResult.getWorlds().sort(Comparator.comparingInt(World::getId)); worlds = worldResult; + eventBus.post(new WorldsFetch(worldResult)); } catch (IOException ex) { 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 fa3b61fd33..e46ab2ec4c 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 @@ -74,6 +74,7 @@ import net.runelite.client.chat.QueuedMessage; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.events.ConfigChanged; +import net.runelite.client.events.WorldsFetch; import net.runelite.client.game.WorldService; import net.runelite.client.input.KeyManager; import net.runelite.client.plugins.Plugin; @@ -222,6 +223,9 @@ 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); + + // populate initial world list + updateList(); } @Override @@ -475,6 +479,12 @@ public class WorldHopperPlugin extends Plugin worldService.refresh(); } + @Subscribe + public void onWorldsFetch(WorldsFetch worldsFetch) + { + updateList(); + } + /** * This method ONLY updates the list's UI, not the actual world list and data it displays. */