http-api: Use observeOn to run code on the ClientThread

This commit is contained in:
Owain van Brakel
2019-07-19 04:18:28 +02:00
parent baa338e533
commit d2e99e23eb
3 changed files with 61 additions and 61 deletions

View File

@@ -828,44 +828,44 @@ public class ChatCommandsPlugin extends Plugin
ItemPrice item = retrieveFromList(results, search);
CLIENT.lookupItem(item.getId())
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.from(clientThread))
.subscribe(
(osbresult) ->
clientThread.invoke(() ->
{
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)
{
int itemId = item.getId();
int itemPrice = itemManager.getItemPrice(itemId);
int alchPrice = itemManager.getAlchValue(itemId);
builder
.append(ChatColorType.NORMAL)
.append(" HA value ")
.append(ChatColorType.HIGHLIGHT)
.append(StackFormatter.formatNumber(alchPrice));
}
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()));
String response = builder.build();
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();
})
log.debug("Setting response {}", response);
messageNode.setRuneLiteFormatMessage(response);
chatMessageManager.update(messageNode);
client.refreshChat();
}
);
}
}

View File

@@ -371,36 +371,36 @@ public class ExaminePlugin extends Plugin
int finalQuantity = quantity;
CLIENT.lookupItem(id)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.from(clientThread))
.subscribe(
(osbresult) ->
clientThread.invoke(() ->
{
message
.append(ChatColorType.NORMAL)
.append(" GE ")
.append(ChatColorType.HIGHLIGHT)
.append(StackFormatter.formatNumber(gePrice * finalQuantity));
if (osbresult != null)
{
message
.append(ChatColorType.NORMAL)
.append(" GE ")
.append(" OSB ")
.append(ChatColorType.HIGHLIGHT)
.append(StackFormatter.formatNumber(gePrice * finalQuantity));
.append(StackFormatter.formatNumber(osbresult.getOverall_average() * finalQuantity));
}
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)");
}
}),
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

@@ -552,13 +552,13 @@ public class GrandExchangePlugin extends Plugin
CLIENT.lookupItem(itemId)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.from(clientThread))
.subscribe(
(osbresult) ->
clientThread.invoke(() ->
{
final String text = geText.getText() + OSB_GE_TEXT + StackFormatter.formatNumber(osbresult.getOverall_average());
geText.setText(text);
}),
{
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)
);
});