world hopper: move hop() to client thread

This commit is contained in:
Adam
2021-01-28 23:28:14 -05:00
parent d01073506b
commit e3b0755385
2 changed files with 10 additions and 7 deletions

View File

@@ -64,6 +64,7 @@ import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.VarbitChanged; import net.runelite.api.events.VarbitChanged;
import net.runelite.api.events.WorldListLoad; import net.runelite.api.events.WorldListLoad;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatColorType;
import net.runelite.client.chat.ChatMessageBuilder; import net.runelite.client.chat.ChatMessageBuilder;
import net.runelite.client.chat.ChatMessageManager; import net.runelite.client.chat.ChatMessageManager;
@@ -111,6 +112,9 @@ public class WorldHopperPlugin extends Plugin
@Inject @Inject
private Client client; private Client client;
@Inject
private ClientThread clientThread;
@Inject @Inject
private ConfigManager configManager; private ConfigManager configManager;
@@ -162,7 +166,7 @@ public class WorldHopperPlugin extends Plugin
@Override @Override
public void hotkeyPressed() public void hotkeyPressed()
{ {
hop(true); clientThread.invoke(() -> hop(true));
} }
}; };
private final HotkeyListener nextKeyListener = new HotkeyListener(() -> config.nextKey()) private final HotkeyListener nextKeyListener = new HotkeyListener(() -> config.nextKey())
@@ -170,7 +174,7 @@ public class WorldHopperPlugin extends Plugin
@Override @Override
public void hotkeyPressed() public void hotkeyPressed()
{ {
hop(false); clientThread.invoke(() -> hop(false));
} }
}; };
@@ -304,7 +308,7 @@ public class WorldHopperPlugin extends Plugin
void hopTo(World world) void hopTo(World world)
{ {
hop(world.getId()); clientThread.invoke(() -> hop(world.getId()));
} }
void addToFavorites(World world) void addToFavorites(World world)
@@ -613,6 +617,8 @@ public class WorldHopperPlugin extends Plugin
private void hop(int worldId) private void hop(int worldId)
{ {
assert client.isClientThread();
WorldResult worldResult = worldService.getWorlds(); WorldResult worldResult = worldService.getWorlds();
// Don't try to hop if the world doesn't exist // Don't try to hop if the world doesn't exist
World world = worldResult.findWorld(worldId); World world = worldResult.findWorld(worldId);

View File

@@ -370,10 +370,7 @@ class WorldSwitcherPanel extends PluginPanel
private WorldTableRow buildRow(World world, boolean stripe, boolean current, boolean favorite) private WorldTableRow buildRow(World world, boolean stripe, boolean current, boolean favorite)
{ {
WorldTableRow row = new WorldTableRow(world, current, favorite, plugin.getStoredPing(world), WorldTableRow row = new WorldTableRow(world, current, favorite, plugin.getStoredPing(world),
world1 -> plugin::hopTo,
{
plugin.hopTo(world1);
},
(world12, add) -> (world12, add) ->
{ {
if (add) if (add)