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); ItemPrice item = retrieveFromList(results, search);
CLIENT.lookupItem(item.getId()) CLIENT.lookupItem(item.getId())
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(Schedulers.from(clientThread))
.subscribe( .subscribe(
(osbresult) -> (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 alchPrice = itemManager.getAlchValue(itemId);
int itemPrice = itemManager.getItemPrice(itemId); builder
.append(ChatColorType.NORMAL)
.append(" HA value ")
.append(ChatColorType.HIGHLIGHT)
.append(StackFormatter.formatNumber(alchPrice));
}
final ChatMessageBuilder builder = new ChatMessageBuilder(); String response = builder.build();
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); log.debug("Setting response {}", response);
if (itemComposition != null) messageNode.setRuneLiteFormatMessage(response);
{ chatMessageManager.update(messageNode);
int alchPrice = itemManager.getAlchValue(itemId); client.refreshChat();
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

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

View File

@@ -552,13 +552,13 @@ public class GrandExchangePlugin extends Plugin
CLIENT.lookupItem(itemId) CLIENT.lookupItem(itemId)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(Schedulers.from(clientThread))
.subscribe( .subscribe(
(osbresult) -> (osbresult) ->
clientThread.invoke(() -> {
{ final String text = geText.getText() + OSB_GE_TEXT + StackFormatter.formatNumber(osbresult.getOverall_average());
final String text = geText.getText() + OSB_GE_TEXT + StackFormatter.formatNumber(osbresult.getOverall_average()); geText.setText(text);
geText.setText(text); },
}),
(e) -> log.debug("Error getting price of item {}", itemId, e) (e) -> log.debug("Error getting price of item {}", itemId, e)
); );
}); });