From 7ece7ab7965b1816e0789505737495a84eecfec4 Mon Sep 17 00:00:00 2001 From: PKLite Date: Sun, 9 Jun 2019 07:51:34 -0400 Subject: [PATCH] sorting is kinda bugged. need to wait until ground item glitch gets fixed for easier testing Signed-off-by: PKLite --- .../loottracker/LootRecordSortType.java | 21 +++++++++++++++++-- .../plugins/loottracker/LootTrackerPanel.java | 12 +++++++++++ .../loottracker/LootTrackerPlugin.java | 7 +++++-- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java index 88696b94bd..61050d2552 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java @@ -3,10 +3,13 @@ package net.runelite.client.plugins.loottracker; import java.util.Arrays; import java.util.Comparator; import java.util.stream.IntStream; +import lombok.extern.slf4j.Slf4j; +import net.runelite.http.api.loottracker.LootRecordType; /** * */ +@Slf4j public enum LootRecordSortType implements Comparator { TIMESTAMP @@ -22,9 +25,23 @@ public enum LootRecordSortType implements Comparator @Override public int compare(LootTrackerRecord o1, LootTrackerRecord o2) { + + // We want deaths at the bottom of the list + if (o1.getSubTitle().equals(LootRecordType.DEATH.name())) + { + return Arrays.stream(o1.getItems()).flatMapToInt(lootTrackerItem -> + IntStream.of((int) lootTrackerItem.getPrice() * lootTrackerItem.getQuantity())).sum(); + } + if (o2.getSubTitle().equals(LootRecordType.DEATH.name())) + { + return Arrays.stream(o1.getItems()).flatMapToInt(lootTrackerItem -> + IntStream.of((int) lootTrackerItem.getPrice() * lootTrackerItem.getQuantity())).sum(); + } int sum = Arrays.stream(o1.getItems()).flatMapToInt(lootTrackerItem -> IntStream.of((int) lootTrackerItem.getPrice() * lootTrackerItem.getQuantity())).sum(); - return sum - Arrays.stream(o2.getItems()).flatMapToInt(lootTrackerItem -> + log.info(String.valueOf(sum + Arrays.stream(o2.getItems()).flatMapToInt(lootTrackerItem -> + IntStream.of((int) lootTrackerItem.getPrice() * lootTrackerItem.getQuantity())).sum())); + return sum + Arrays.stream(o2.getItems()).flatMapToInt(lootTrackerItem -> IntStream.of((int) lootTrackerItem.getPrice() * lootTrackerItem.getQuantity())).sum(); } }, @@ -33,7 +50,7 @@ public enum LootRecordSortType implements Comparator @Override public int compare(LootTrackerRecord o1, LootTrackerRecord o2) { - return o1.getItems().length - o2.getItems().length; + return Integer.compare(o1.getItems().length, o2.getItems().length); } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java index 51cfaf3e3c..b26f83f0ff 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java @@ -33,9 +33,11 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.stream.IntStream; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.ImageIcon; @@ -435,7 +437,17 @@ class LootTrackerPanel extends PluginPanel } for (int i = start; i < records.size(); i++) { + + if (this.plugin.client.getGameState().equals(GameState.LOGGED_IN)) + { + if (!(this.plugin.client.getLocalPlayer().getName().equals(records.get(i).getLocalUsername()))) + { + continue; + } + } buildBox(records.get(i)); + log.info(String.valueOf(Arrays.stream(records.get(i).getItems()).flatMapToInt(a -> IntStream.of(a.getQuantity() * (int) a.getPrice())).sum())); + } boxes.forEach(LootTrackerBox::rebuild); updateOverall(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java index b0d1d0c90c..2f572275eb 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java @@ -25,6 +25,7 @@ */ package net.runelite.client.plugins.loottracker; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.HashMultiset; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -184,7 +185,8 @@ public class LootTrackerPlugin extends Plugin private LootTrackerClient lootTrackerClient; private BufferedReader bufferedReader; private JsonStreamParser jsonStreamParser; - private Collection lootRecords = new ArrayList<>(); + @VisibleForTesting + public Collection lootRecords = new ArrayList<>(); private static Collection stack(Collection items) { @@ -736,6 +738,7 @@ public class LootTrackerPlugin extends Plugin return ignoredItems.contains(name); } + @VisibleForTesting private LootTrackerItem buildLootTrackerItem(int itemId, int quantity) { final ItemDefinition itemComposition = itemManager.getItemDefinition(itemId); @@ -765,7 +768,7 @@ public class LootTrackerPlugin extends Plugin .collect(Collectors.toList()); } - private Collection convertToLootTrackerRecord(final Collection records) + public Collection convertToLootTrackerRecord(final Collection records) { Collection trackerRecords = new ArrayList<>(); for (LootRecord record : records)