Automatically filters loot tracker loot to only show loot that the currently
logged in account has received and to show all loot from all accounts on login screen Signed-off-by: PKLite <stonewall@pklite.xyz>
This commit is contained in:
@@ -28,6 +28,7 @@ import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@@ -36,6 +37,8 @@ import lombok.NoArgsConstructor;
|
||||
public class LootRecord
|
||||
{
|
||||
private String eventId;
|
||||
@Getter
|
||||
private String username;
|
||||
private LootRecordType type;
|
||||
private Collection<GameItem> drops;
|
||||
private Instant time;
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.ImageIcon;
|
||||
@@ -43,6 +44,8 @@ import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.GameState;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
@@ -53,6 +56,7 @@ import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.StackFormatter;
|
||||
import net.runelite.http.api.loottracker.LootTrackerClient;
|
||||
|
||||
@Slf4j
|
||||
class LootTrackerPanel extends PluginPanel
|
||||
{
|
||||
private static final int MAX_LOOT_BOXES = 500;
|
||||
@@ -131,6 +135,8 @@ class LootTrackerPanel extends PluginPanel
|
||||
INVISIBLE_ICON_HOVER = new ImageIcon(ImageUtil.alphaOffset(invisibleImg, -220));
|
||||
}
|
||||
|
||||
private final JPanel displaySelector;
|
||||
|
||||
LootTrackerPanel(final LootTrackerPlugin plugin, final ItemManager itemManager, final LootTrackerConfig config)
|
||||
{
|
||||
this.itemManager = itemManager;
|
||||
@@ -289,6 +295,11 @@ class LootTrackerPanel extends PluginPanel
|
||||
overallPanel.add(overallIcon, BorderLayout.WEST);
|
||||
overallPanel.add(overallInfo, BorderLayout.CENTER);
|
||||
|
||||
displaySelector = new JPanel();
|
||||
displaySelector.setLayout(new GridLayout(1, 1));
|
||||
displaySelector.setBorder(new EmptyBorder(2, 10, 10, 10));
|
||||
displaySelector.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||
|
||||
// Create reset all menu
|
||||
final JMenuItem reset = new JMenuItem("Reset All");
|
||||
reset.addActionListener(e ->
|
||||
@@ -318,6 +329,7 @@ class LootTrackerPanel extends PluginPanel
|
||||
logsContainer.setLayout(new BoxLayout(logsContainer, BoxLayout.Y_AXIS));
|
||||
layoutPanel.add(actionsContainer);
|
||||
layoutPanel.add(overallPanel);
|
||||
layoutPanel.add(displaySelector);
|
||||
layoutPanel.add(logsContainer);
|
||||
|
||||
// Add error pane
|
||||
@@ -335,10 +347,10 @@ class LootTrackerPanel extends PluginPanel
|
||||
* Creates a subtitle, adds a new entry and then passes off to the render methods, that will decide
|
||||
* how to display this new data.
|
||||
*/
|
||||
void add(final String eventName, final int actorLevel, LootTrackerItem[] items)
|
||||
void add(final String eventName, final String localUsername, final int actorLevel, LootTrackerItem[] items)
|
||||
{
|
||||
final String subTitle = actorLevel > -1 ? "(lvl-" + actorLevel + ")" : "";
|
||||
final LootTrackerRecord record = new LootTrackerRecord(eventName, subTitle, items, System.currentTimeMillis());
|
||||
final LootTrackerRecord record = new LootTrackerRecord( eventName, localUsername, subTitle, items, System.currentTimeMillis());
|
||||
records.add(record);
|
||||
LootTrackerBox box = buildBox(record);
|
||||
if (box != null)
|
||||
@@ -405,8 +417,9 @@ class LootTrackerPanel extends PluginPanel
|
||||
/**
|
||||
* Rebuilds all the boxes from scratch using existing listed records, depending on the grouping mode.
|
||||
*/
|
||||
private void rebuild()
|
||||
public void rebuild()
|
||||
{
|
||||
|
||||
logsContainer.removeAll();
|
||||
boxes.clear();
|
||||
int start = 0;
|
||||
@@ -422,6 +435,8 @@ class LootTrackerPanel extends PluginPanel
|
||||
updateOverall();
|
||||
logsContainer.revalidate();
|
||||
logsContainer.repaint();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -431,12 +446,21 @@ class LootTrackerPanel extends PluginPanel
|
||||
*/
|
||||
private LootTrackerBox buildBox(LootTrackerRecord record)
|
||||
{
|
||||
|
||||
// If this record is not part of current view, return
|
||||
if (!record.matches(currentView))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.plugin.client.getGameState().equals(GameState.LOGGED_IN))
|
||||
{
|
||||
if (!(this.plugin.client.getLocalPlayer().getName().equals(record.getLocalUsername())))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Group all similar loot together
|
||||
if (groupLoot)
|
||||
{
|
||||
@@ -456,7 +480,8 @@ class LootTrackerPanel extends PluginPanel
|
||||
overallPanel.setVisible(true);
|
||||
|
||||
// Create box
|
||||
final LootTrackerBox box = new LootTrackerBox(itemManager, record.getTitle(), record.getSubTitle(), hideIgnoredItems, plugin::toggleItem);
|
||||
final LootTrackerBox box = new LootTrackerBox(itemManager, record.getTitle(), record.getSubTitle(),
|
||||
hideIgnoredItems, plugin::toggleItem);
|
||||
box.combine(record);
|
||||
|
||||
// Create popup menu
|
||||
@@ -519,6 +544,14 @@ class LootTrackerPanel extends PluginPanel
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (Objects.nonNull(record.getLocalUsername()) && Objects.nonNull(plugin.client.getLocalPlayer()))
|
||||
{
|
||||
if (!record.getLocalUsername().equals(plugin.client.getLocalPlayer().getName()))
|
||||
{
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int present = record.getItems().length;
|
||||
|
||||
@@ -542,7 +575,6 @@ class LootTrackerPanel extends PluginPanel
|
||||
overallKillsLabel.setText(htmlLabel("Total count: ", overallKills));
|
||||
overallGpLabel.setText(htmlLabel("Total value: ", overallGp));
|
||||
}
|
||||
|
||||
private static String htmlLabel(String key, long value)
|
||||
{
|
||||
final String valueStr = StackFormatter.quantityToStackSize(value);
|
||||
|
||||
@@ -64,8 +64,8 @@ import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.InventoryID;
|
||||
import net.runelite.api.Item;
|
||||
import net.runelite.api.ItemDefinition;
|
||||
import net.runelite.api.ItemContainer;
|
||||
import net.runelite.api.ItemDefinition;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.SpriteID;
|
||||
@@ -76,6 +76,7 @@ import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.ItemContainerChanged;
|
||||
import net.runelite.api.events.LocalPlayerDeath;
|
||||
import net.runelite.api.events.PlayerSpawned;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
import net.runelite.client.RuneLite;
|
||||
@@ -133,7 +134,8 @@ public class LootTrackerPlugin extends Plugin
|
||||
);
|
||||
|
||||
// Player deaths
|
||||
private static final String PLAYER_DEATH_MESSAGE = "Oh dear, you are dead!";
|
||||
public static HashSet<String> usernameSet = new HashSet<String>(Arrays.stream(new String[]{"All Records"}).collect(Collectors.toList()));
|
||||
|
||||
private static final File LOOT_RECORDS_FILE = new File(RuneLite.RUNELITE_DIR, "lootRecords.json");
|
||||
private static final Set<Integer> RESPAWN_REGIONS = ImmutableSet.of(
|
||||
12850, // Lumbridge
|
||||
@@ -159,7 +161,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
private LootTrackerConfig config;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
public Client client;
|
||||
|
||||
@Inject
|
||||
private ClientThread clientThread;
|
||||
@@ -178,7 +180,6 @@ public class LootTrackerPlugin extends Plugin
|
||||
|
||||
private Multiset<Integer> inventorySnapshot;
|
||||
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private LootTrackerClient lootTrackerClient;
|
||||
private BufferedReader bufferedReader;
|
||||
@@ -318,6 +319,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
lootRecords.addAll(RuneLiteAPI.GSON.fromJson(new FileReader(LOOT_RECORDS_FILE),
|
||||
new TypeToken<ArrayList<LootRecord>>()
|
||||
{ }.getType()));
|
||||
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@@ -343,6 +345,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
{
|
||||
clientToolbar.removeNavigation(navButton);
|
||||
lootTrackerClient = null;
|
||||
lootRecords = new ArrayList<LootRecord>();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -353,8 +356,10 @@ public class LootTrackerPlugin extends Plugin
|
||||
final String name = npc.getName();
|
||||
final int combat = npc.getCombatLevel();
|
||||
final LootTrackerItem[] entries = buildEntries(stack(items));
|
||||
SwingUtilities.invokeLater(() -> panel.add(name, combat, entries));
|
||||
LootRecord lootRecord = new LootRecord(name, LootRecordType.NPC, toGameItems(items), Instant.now());
|
||||
String localUsername = client.getLocalPlayer().getName();
|
||||
SwingUtilities.invokeLater(() -> panel.add(name, localUsername, combat, entries));
|
||||
LootRecord lootRecord = new LootRecord( name, localUsername, LootRecordType.NPC,
|
||||
toGameItems(items), Instant.now());
|
||||
|
||||
if (lootTrackerClient != null && config.saveLoot())
|
||||
{
|
||||
@@ -366,6 +371,16 @@ public class LootTrackerPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onPlayerSpawned(PlayerSpawned event)
|
||||
{
|
||||
if (event.getPlayer().equals(client.getLocalPlayer()))
|
||||
{
|
||||
SwingUtilities.invokeLater(() -> panel.rebuild());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPlayerLootReceived(final PlayerLootReceived playerLootReceived)
|
||||
{
|
||||
@@ -374,9 +389,10 @@ public class LootTrackerPlugin extends Plugin
|
||||
final String name = player.getName();
|
||||
final int combat = player.getCombatLevel();
|
||||
final LootTrackerItem[] entries = buildEntries(stack(items));
|
||||
SwingUtilities.invokeLater(() -> panel.add(name, combat, entries));
|
||||
LootRecord lootRecord = new LootRecord(name, LootRecordType.PLAYER, toGameItems(items), Instant.now());
|
||||
|
||||
String localUsername = client.getLocalPlayer().getName();
|
||||
SwingUtilities.invokeLater(() -> panel.add(name, localUsername, combat, entries));
|
||||
LootRecord lootRecord = new LootRecord(localUsername, name, LootRecordType.PLAYER,
|
||||
toGameItems(items), Instant.now());
|
||||
if (lootTrackerClient != null && config.saveLoot())
|
||||
{
|
||||
lootTrackerClient.submit(lootRecord);
|
||||
@@ -447,6 +463,11 @@ public class LootTrackerPlugin extends Plugin
|
||||
.build());
|
||||
}
|
||||
|
||||
if (event.getGroupId() == WidgetID.CHATBOX_GROUP_ID)
|
||||
{
|
||||
panel.rebuild();
|
||||
}
|
||||
|
||||
// Convert container items to array of ItemStack
|
||||
final Collection<ItemStack> items = Arrays.stream(container.getItems())
|
||||
.filter(item -> item.getId() > 0)
|
||||
@@ -460,11 +481,12 @@ public class LootTrackerPlugin extends Plugin
|
||||
}
|
||||
|
||||
final LootTrackerItem[] entries = buildEntries(stack(items));
|
||||
SwingUtilities.invokeLater(() -> panel.add(eventType, -1, entries));
|
||||
SwingUtilities.invokeLater(() -> panel.add(client.getLocalPlayer().getName(), eventType, -1, entries));
|
||||
|
||||
if (lootTrackerClient != null && config.saveLoot())
|
||||
{
|
||||
LootRecord lootRecord = new LootRecord(eventType, LootRecordType.EVENT, toGameItems(items), Instant.now());
|
||||
LootRecord lootRecord = new LootRecord(client.getLocalPlayer().getName(), eventType, LootRecordType.EVENT,
|
||||
toGameItems(items), Instant.now());
|
||||
lootTrackerClient.submit(lootRecord);
|
||||
}
|
||||
}
|
||||
@@ -479,34 +501,6 @@ public class LootTrackerPlugin extends Plugin
|
||||
|
||||
final String message = event.getMessage();
|
||||
|
||||
if (message.equals(PLAYER_DEATH_MESSAGE))
|
||||
{
|
||||
ItemContainer inventory = client.getItemContainer(InventoryID.INVENTORY);
|
||||
if (inventorySnapshot != null)
|
||||
{
|
||||
Multiset<Integer> currentInventory = HashMultiset.create();
|
||||
if (inventory != null)
|
||||
{
|
||||
Arrays.stream(client.getItemContainer(InventoryID.INVENTORY).getItems())
|
||||
.forEach(item -> currentInventory.add(item.getId(), item.getQuantity()));
|
||||
}
|
||||
|
||||
final Multiset<Integer> diff = Multisets.difference(inventorySnapshot, currentInventory);
|
||||
|
||||
log.info(inventorySnapshot.toString());
|
||||
log.info(currentInventory.toString());
|
||||
log.info(diff.toString());
|
||||
|
||||
List<ItemStack> itemsLost = diff.entrySet().stream()
|
||||
.map(e -> new ItemStack(e.getElement(), (-1 * e.getCount()), client.getLocalPlayer().getLocalLocation()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final LootTrackerItem[] entries = buildEntries(stack(itemsLost));
|
||||
SwingUtilities.invokeLater(() -> panel.add("Death: " + client.getLocalPlayer().getName(),
|
||||
client.getLocalPlayer().getCombatLevel(), entries));
|
||||
}
|
||||
}
|
||||
|
||||
if (message.equals(CHEST_LOOTED_MESSAGE))
|
||||
{
|
||||
final int regionID = client.getLocalPlayer().getWorldLocation().getRegionID();
|
||||
@@ -589,11 +583,10 @@ public class LootTrackerPlugin extends Plugin
|
||||
|
||||
final LootTrackerItem[] entries = buildEntries(stack(itemsLost));
|
||||
String name = "Death: " + client.getLocalPlayer().getName();
|
||||
SwingUtilities.invokeLater(() -> panel.add(name,
|
||||
SwingUtilities.invokeLater(() -> panel.add(name, client.getLocalPlayer().getName(),
|
||||
client.getLocalPlayer().getCombatLevel(), entries));
|
||||
LootRecord lootRecord = new LootRecord(name, LootRecordType.DEATH, toGameItems(itemsLost),
|
||||
Instant.now());
|
||||
|
||||
LootRecord lootRecord = new LootRecord(name, client.getLocalPlayer().getName(), LootRecordType.DEATH,
|
||||
toGameItems(itemsLost), Instant.now());
|
||||
if (lootTrackerClient != null && config.saveLoot())
|
||||
{
|
||||
lootTrackerClient.submit(lootRecord);
|
||||
@@ -699,11 +692,12 @@ public class LootTrackerPlugin extends Plugin
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final LootTrackerItem[] entries = buildEntries(stack(items));
|
||||
SwingUtilities.invokeLater(() -> panel.add(chestType, -1, entries));
|
||||
SwingUtilities.invokeLater(() -> panel.add(client.getLocalPlayer().getName(), chestType, -1, entries));
|
||||
|
||||
if (lootTrackerClient != null && config.saveLoot())
|
||||
{
|
||||
LootRecord lootRecord = new LootRecord(chestType, LootRecordType.EVENT, toGameItems(items), Instant.now());
|
||||
LootRecord lootRecord = new LootRecord(client.getLocalPlayer().getName(), chestType,
|
||||
LootRecordType.EVENT, toGameItems(items), Instant.now());
|
||||
lootTrackerClient.submit(lootRecord);
|
||||
}
|
||||
|
||||
@@ -771,7 +765,8 @@ public class LootTrackerPlugin extends Plugin
|
||||
buildLootTrackerItem(itemStack.getId(), itemStack.getQty())
|
||||
).toArray(LootTrackerItem[]::new);
|
||||
|
||||
trackerRecords.add(new LootTrackerRecord(record.getEventId(), "", drops, -1));
|
||||
trackerRecords.add(new LootTrackerRecord(record.getEventId(), record.getUsername(),
|
||||
"", drops, -1));
|
||||
}
|
||||
|
||||
return trackerRecords;
|
||||
|
||||
@@ -31,6 +31,7 @@ import lombok.Value;
|
||||
class LootTrackerRecord
|
||||
{
|
||||
private final String title;
|
||||
private String localUsername;
|
||||
private final String subTitle;
|
||||
@SerializedName("item_records")
|
||||
private final LootTrackerItem[] items;
|
||||
|
||||
Reference in New Issue
Block a user