From c31dc24472663d1057e27fb4225333bbb3f22a08 Mon Sep 17 00:00:00 2001 From: Owain van Brakel Date: Fri, 19 Jul 2019 02:20:54 +0200 Subject: [PATCH] http-api: run callback on clientthread --- .../chatcommands/ChatCommandsPlugin.java | 69 ++++++++++--------- .../client/plugins/examine/ExaminePlugin.java | 49 +++++++------ .../grandexchange/GrandExchangePlugin.java | 13 ++-- 3 files changed, 73 insertions(+), 58 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index 521da25b34..4c411000a4 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -52,6 +52,7 @@ import net.runelite.api.vars.AccountType; import net.runelite.api.widgets.Widget; import static net.runelite.api.widgets.WidgetID.KILL_LOGS_GROUP_ID; import net.runelite.api.widgets.WidgetInfo; +import net.runelite.client.callback.ClientThread; import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatCommandManager; import net.runelite.client.chat.ChatMessageBuilder; @@ -116,6 +117,9 @@ public class ChatCommandsPlugin extends Plugin @Inject private Client client; + @Inject + private ClientThread clientThread; + @Inject private ChatCommandsConfig config; @@ -826,41 +830,42 @@ public class ChatCommandsPlugin extends Plugin .subscribeOn(Schedulers.single()) .subscribe( (osbresult) -> - { - int itemId = item.getId(); - int itemPrice = itemManager.getItemPrice(itemId); - - final ChatMessageBuilder builder = new ChatMessageBuilder(); - builder.append(ChatColorType.NORMAL); - builder.append(ChatColorType.HIGHLIGHT); - builder.append(item.getName()); - builder.append(ChatColorType.NORMAL); - builder.append(": GE "); - builder.append(ChatColorType.HIGHLIGHT); - builder.append(StackFormatter.formatNumber(itemPrice)); - builder.append(ChatColorType.NORMAL); - builder.append(": OSB "); - builder.append(ChatColorType.HIGHLIGHT); - builder.append(StackFormatter.formatNumber(osbresult.getOverall_average())); - - ItemDefinition itemComposition = itemManager.getItemDefinition(itemId); - if (itemComposition != null) + clientThread.invoke(() -> { - int alchPrice = itemManager.getAlchValue(itemId); - builder - .append(ChatColorType.NORMAL) - .append(" HA value ") - .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(alchPrice)); - } + int itemId = item.getId(); + int itemPrice = itemManager.getItemPrice(itemId); - String response = builder.build(); + final ChatMessageBuilder builder = new ChatMessageBuilder(); + builder.append(ChatColorType.NORMAL); + builder.append(ChatColorType.HIGHLIGHT); + builder.append(item.getName()); + builder.append(ChatColorType.NORMAL); + builder.append(": GE "); + builder.append(ChatColorType.HIGHLIGHT); + builder.append(StackFormatter.formatNumber(itemPrice)); + builder.append(ChatColorType.NORMAL); + builder.append(": OSB "); + builder.append(ChatColorType.HIGHLIGHT); + builder.append(StackFormatter.formatNumber(osbresult.getOverall_average())); - log.debug("Setting response {}", response); - messageNode.setRuneLiteFormatMessage(response); - chatMessageManager.update(messageNode); - client.refreshChat(); - } + ItemDefinition itemComposition = itemManager.getItemDefinition(itemId); + if (itemComposition != null) + { + int alchPrice = itemManager.getAlchValue(itemId); + builder + .append(ChatColorType.NORMAL) + .append(" HA value ") + .append(ChatColorType.HIGHLIGHT) + .append(StackFormatter.formatNumber(alchPrice)); + } + + String response = builder.build(); + + log.debug("Setting response {}", response); + messageNode.setRuneLiteFormatMessage(response); + chatMessageManager.update(messageNode); + client.refreshChat(); + }) ); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java index f277e18464..3cdf71dff4 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/examine/ExaminePlugin.java @@ -46,6 +46,7 @@ import net.runelite.api.widgets.WidgetInfo; import static net.runelite.api.widgets.WidgetInfo.TO_CHILD; import static net.runelite.api.widgets.WidgetInfo.TO_GROUP; import net.runelite.api.widgets.WidgetItem; +import net.runelite.client.callback.ClientThread; import net.runelite.client.chat.ChatColorType; import net.runelite.client.chat.ChatMessageBuilder; import net.runelite.client.chat.ChatMessageManager; @@ -86,6 +87,9 @@ public class ExaminePlugin extends Plugin @Inject private Client client; + @Inject + private ClientThread clientThread; + @Inject private ItemManager itemManager; @@ -369,33 +373,34 @@ public class ExaminePlugin extends Plugin .subscribeOn(Schedulers.single()) .subscribe( (osbresult) -> - { - message - .append(ChatColorType.NORMAL) - .append(" GE ") - .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(gePrice * finalQuantity)); - - if (osbresult != null) + clientThread.invoke(() -> { message .append(ChatColorType.NORMAL) - .append(" OSB ") + .append(" GE ") .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(osbresult.getOverall_average() * finalQuantity)); - } + .append(StackFormatter.formatNumber(gePrice * finalQuantity)); - if (finalQuantity > 1) - { - message - .append(ChatColorType.NORMAL) - .append(" (") - .append(ChatColorType.HIGHLIGHT) - .append(StackFormatter.formatNumber(gePrice)) - .append(ChatColorType.NORMAL) - .append("ea)"); - } - }, + if (osbresult != null) + { + message + .append(ChatColorType.NORMAL) + .append(" OSB ") + .append(ChatColorType.HIGHLIGHT) + .append(StackFormatter.formatNumber(osbresult.getOverall_average() * finalQuantity)); + } + + if (finalQuantity > 1) + { + message + .append(ChatColorType.NORMAL) + .append(" (") + .append(ChatColorType.HIGHLIGHT) + .append(StackFormatter.formatNumber(gePrice)) + .append(ChatColorType.NORMAL) + .append("ea)"); + } + }), (e) -> log.error(e.toString()) ); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java index 5fa2e77a21..9fc24c8bab 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java @@ -66,6 +66,7 @@ import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.Notifier; import net.runelite.client.account.AccountSession; import net.runelite.client.account.SessionManager; +import net.runelite.client.callback.ClientThread; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.EventBus; import net.runelite.client.events.SessionClose; @@ -131,6 +132,9 @@ public class GrandExchangePlugin extends Plugin @Inject private Client client; + @Inject + private ClientThread clientThread; + @Inject private ClientToolbar clientToolbar; @@ -550,10 +554,11 @@ public class GrandExchangePlugin extends Plugin .subscribeOn(Schedulers.single()) .subscribe( (osbresult) -> - { - final String text = geText.getText() + OSB_GE_TEXT + StackFormatter.formatNumber(osbresult.getOverall_average()); - geText.setText(text); - }, + clientThread.invoke(() -> + { + final String text = geText.getText() + OSB_GE_TEXT + StackFormatter.formatNumber(osbresult.getOverall_average()); + geText.setText(text); + }), (e) -> log.debug("Error getting price of item {}", itemId, e) ); });