sorting is kinda bugged. need to wait until ground item glitch gets fixed

for easier testing

Signed-off-by: PKLite <stonewall@pklite.xyz>
This commit is contained in:
PKLite
2019-06-09 07:51:34 -04:00
parent 6828aae1e5
commit 7ece7ab796
3 changed files with 36 additions and 4 deletions

View File

@@ -3,10 +3,13 @@ package net.runelite.client.plugins.loottracker;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.stream.IntStream; import java.util.stream.IntStream;
import lombok.extern.slf4j.Slf4j;
import net.runelite.http.api.loottracker.LootRecordType;
/** /**
* *
*/ */
@Slf4j
public enum LootRecordSortType implements Comparator<LootTrackerRecord> public enum LootRecordSortType implements Comparator<LootTrackerRecord>
{ {
TIMESTAMP TIMESTAMP
@@ -22,9 +25,23 @@ public enum LootRecordSortType implements Comparator<LootTrackerRecord>
@Override @Override
public int compare(LootTrackerRecord o1, LootTrackerRecord o2) 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 -> int sum = Arrays.stream(o1.getItems()).flatMapToInt(lootTrackerItem ->
IntStream.of((int) lootTrackerItem.getPrice() * lootTrackerItem.getQuantity())).sum(); 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(); IntStream.of((int) lootTrackerItem.getPrice() * lootTrackerItem.getQuantity())).sum();
} }
}, },
@@ -33,7 +50,7 @@ public enum LootRecordSortType implements Comparator<LootTrackerRecord>
@Override @Override
public int compare(LootTrackerRecord o1, LootTrackerRecord o2) public int compare(LootTrackerRecord o1, LootTrackerRecord o2)
{ {
return o1.getItems().length - o2.getItems().length; return Integer.compare(o1.getItems().length, o2.getItems().length);
} }
} }
} }

View File

@@ -33,9 +33,11 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.IntStream;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
@@ -435,7 +437,17 @@ class LootTrackerPanel extends PluginPanel
} }
for (int i = start; i < records.size(); i++) 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)); 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); boxes.forEach(LootTrackerBox::rebuild);
updateOverall(); updateOverall();

View File

@@ -25,6 +25,7 @@
*/ */
package net.runelite.client.plugins.loottracker; package net.runelite.client.plugins.loottracker;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.HashMultiset; import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@@ -184,7 +185,8 @@ public class LootTrackerPlugin extends Plugin
private LootTrackerClient lootTrackerClient; private LootTrackerClient lootTrackerClient;
private BufferedReader bufferedReader; private BufferedReader bufferedReader;
private JsonStreamParser jsonStreamParser; private JsonStreamParser jsonStreamParser;
private Collection<LootRecord> lootRecords = new ArrayList<>(); @VisibleForTesting
public Collection<LootRecord> lootRecords = new ArrayList<>();
private static Collection<ItemStack> stack(Collection<ItemStack> items) private static Collection<ItemStack> stack(Collection<ItemStack> items)
{ {
@@ -736,6 +738,7 @@ public class LootTrackerPlugin extends Plugin
return ignoredItems.contains(name); return ignoredItems.contains(name);
} }
@VisibleForTesting
private LootTrackerItem buildLootTrackerItem(int itemId, int quantity) private LootTrackerItem buildLootTrackerItem(int itemId, int quantity)
{ {
final ItemDefinition itemComposition = itemManager.getItemDefinition(itemId); final ItemDefinition itemComposition = itemManager.getItemDefinition(itemId);
@@ -765,7 +768,7 @@ public class LootTrackerPlugin extends Plugin
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private Collection<LootTrackerRecord> convertToLootTrackerRecord(final Collection<LootRecord> records) public Collection<LootTrackerRecord> convertToLootTrackerRecord(final Collection<LootRecord> records)
{ {
Collection<LootTrackerRecord> trackerRecords = new ArrayList<>(); Collection<LootTrackerRecord> trackerRecords = new ArrayList<>();
for (LootRecord record : records) for (LootRecord record : records)