http-api: run callback on clientthread

This commit is contained in:
Owain van Brakel
2019-07-19 02:20:54 +02:00
parent b228ac322b
commit c31dc24472
3 changed files with 73 additions and 58 deletions

View File

@@ -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();
})
);
}
}

View File

@@ -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())
);
}

View File

@@ -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)
);
});