loottracker: replace getTotalPrice with stream

This commit is contained in:
Adam
2022-03-05 18:58:29 -05:00
parent 7864a10135
commit 17f6890b69

View File

@@ -1131,26 +1131,18 @@ public class LootTrackerPlugin extends Plugin
return false;
}
private long getTotalPrice(Collection<ItemStack> items)
{
long totalPrice = 0;
for (final ItemStack itemStack : items)
{
totalPrice += (long) itemManager.getItemPrice(itemStack.getId()) * itemStack.getQuantity();
}
return totalPrice;
}
private void lootReceivedChatMessage(final Collection<ItemStack> items, final String name)
{
long totalPrice = items.stream()
.mapToLong(is -> (long) itemManager.getItemPrice(is.getId()) * is.getQuantity())
.sum();
final String message = new ChatMessageBuilder()
.append(ChatColorType.HIGHLIGHT)
.append("You've killed ")
.append(name)
.append(" for ")
.append(QuantityFormatter.quantityToStackSize(getTotalPrice(items)))
.append(QuantityFormatter.quantityToStackSize(totalPrice))
.append(" loot.")
.build();