loot tracker: batch loot submissions
This commit is contained in:
@@ -34,6 +34,7 @@ import com.google.inject.Provides;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -81,6 +82,7 @@ import net.runelite.client.game.ItemStack;
|
||||
import net.runelite.client.game.SpriteManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.task.Schedule;
|
||||
import net.runelite.client.ui.ClientToolbar;
|
||||
import net.runelite.client.ui.NavigationButton;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
@@ -167,6 +169,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
|
||||
@Getter(AccessLevel.PACKAGE)
|
||||
private LootTrackerClient lootTrackerClient;
|
||||
private final List<LootRecord> queuedLoots = new ArrayList<>();
|
||||
|
||||
private static Collection<ItemStack> stack(Collection<ItemStack> items)
|
||||
{
|
||||
@@ -220,6 +223,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
@Subscribe
|
||||
public void onSessionClose(SessionClose sessionClose)
|
||||
{
|
||||
submitLoot();
|
||||
lootTrackerClient = null;
|
||||
}
|
||||
|
||||
@@ -300,6 +304,7 @@ public class LootTrackerPlugin extends Plugin
|
||||
@Override
|
||||
protected void shutDown()
|
||||
{
|
||||
submitLoot();
|
||||
clientToolbar.removeNavigation(navButton);
|
||||
lootTrackerClient = null;
|
||||
chestLooted = false;
|
||||
@@ -324,10 +329,13 @@ public class LootTrackerPlugin extends Plugin
|
||||
final LootTrackerItem[] entries = buildEntries(stack(items));
|
||||
SwingUtilities.invokeLater(() -> panel.add(name, combat, entries));
|
||||
|
||||
if (lootTrackerClient != null && config.saveLoot())
|
||||
if (config.saveLoot())
|
||||
{
|
||||
LootRecord lootRecord = new LootRecord(name, LootRecordType.NPC, toGameItems(items), Instant.now());
|
||||
lootTrackerClient.submit(lootRecord);
|
||||
synchronized (queuedLoots)
|
||||
{
|
||||
queuedLoots.add(lootRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,10 +355,13 @@ public class LootTrackerPlugin extends Plugin
|
||||
final LootTrackerItem[] entries = buildEntries(stack(items));
|
||||
SwingUtilities.invokeLater(() -> panel.add(name, combat, entries));
|
||||
|
||||
if (lootTrackerClient != null && config.saveLoot())
|
||||
if (config.saveLoot())
|
||||
{
|
||||
LootRecord lootRecord = new LootRecord(name, LootRecordType.PLAYER, toGameItems(items), Instant.now());
|
||||
lootTrackerClient.submit(lootRecord);
|
||||
synchronized (queuedLoots)
|
||||
{
|
||||
queuedLoots.add(lootRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,10 +431,13 @@ public class LootTrackerPlugin extends Plugin
|
||||
final LootTrackerItem[] entries = buildEntries(stack(items));
|
||||
SwingUtilities.invokeLater(() -> panel.add(eventType, -1, entries));
|
||||
|
||||
if (lootTrackerClient != null && config.saveLoot())
|
||||
if (config.saveLoot())
|
||||
{
|
||||
LootRecord lootRecord = new LootRecord(eventType, LootRecordType.EVENT, toGameItems(items), Instant.now());
|
||||
lootTrackerClient.submit(lootRecord);
|
||||
synchronized (queuedLoots)
|
||||
{
|
||||
queuedLoots.add(lootRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,6 +535,40 @@ public class LootTrackerPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Schedule(
|
||||
period = 5,
|
||||
unit = ChronoUnit.MINUTES,
|
||||
asynchronous = true
|
||||
)
|
||||
public void submitLootTask()
|
||||
{
|
||||
submitLoot();
|
||||
}
|
||||
|
||||
private void submitLoot()
|
||||
{
|
||||
List<LootRecord> copy;
|
||||
synchronized (queuedLoots)
|
||||
{
|
||||
if (queuedLoots.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
copy = new ArrayList<>(queuedLoots);
|
||||
queuedLoots.clear();
|
||||
}
|
||||
|
||||
if (lootTrackerClient == null || !config.saveLoot())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
log.debug("Submitting {} loot records", copy.size());
|
||||
|
||||
lootTrackerClient.submit(copy);
|
||||
}
|
||||
|
||||
private void takeInventorySnapshot()
|
||||
{
|
||||
final ItemContainer itemContainer = client.getItemContainer(InventoryID.INVENTORY);
|
||||
@@ -549,10 +597,13 @@ public class LootTrackerPlugin extends Plugin
|
||||
final LootTrackerItem[] entries = buildEntries(stack(items));
|
||||
SwingUtilities.invokeLater(() -> panel.add(chestType, -1, entries));
|
||||
|
||||
if (lootTrackerClient != null && config.saveLoot())
|
||||
if (config.saveLoot())
|
||||
{
|
||||
LootRecord lootRecord = new LootRecord(chestType, LootRecordType.EVENT, toGameItems(items), Instant.now());
|
||||
lootTrackerClient.submit(lootRecord);
|
||||
synchronized (queuedLoots)
|
||||
{
|
||||
queuedLoots.add(lootRecord);
|
||||
}
|
||||
}
|
||||
|
||||
inventorySnapshot = null;
|
||||
|
||||
Reference in New Issue
Block a user