Adds Loot Tracker session filter and fixes reset button (#1066)

* Add Session filter and make it default

Signed-off-by: PKLite <stonewall@pklite.xyz>

* Fixes reset button functionality

Signed-off-by: PKLite <stonewall@pklite.xyz>

* Fixes Session filter

Signed-off-by: PKLite <stonewall@pklite.xyz>

* Adds missing tob loot record events (untested)

Signed-off-by: PKLite <stonewall@pklite.xyz>
This commit is contained in:
pklite
2019-07-20 17:52:33 -04:00
committed by Kyleeld
parent d3a17c16c6
commit 058aeb8da9
3 changed files with 56 additions and 14 deletions

View File

@@ -12,11 +12,15 @@
package net.runelite.client.plugins.loottracker;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.time.Duration;
import lombok.Getter;
public enum LootRecordDateFilter
{
SESSION("Session", Duration.ofMillis(LootTrackerPlugin.SESSION_START_TIME.toEpochMilli())),
HOUR("Hour", Duration.ofHours(1)),
DAY("Day", Duration.ofDays(1)),
WEEK("Week", Duration.ofDays(7)),
@@ -27,7 +31,16 @@ public enum LootRecordDateFilter
private final String name;
@Getter
private final Duration duration;
static RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
/**
* Constructor for a Loot Tracker filter that filters by date, more specifically Duration.
*
* @param name - String the name that represents the date filter. This is what will be displayed in the GUI
* @param duration - The duration the current time - the time of the loot record must be greater than to display if
* a date filter other than all or Session is enabled
*/
private LootRecordDateFilter(String name, Duration duration)
{
this.name = name;

View File

@@ -120,7 +120,8 @@ class LootTrackerPanel extends PluginPanel
private final LootTrackerConfig config;
private boolean groupLoot;
private LootRecordDateFilter dateFilter = LootRecordDateFilter.ALL;
// Set default date filter to session data
private LootRecordDateFilter dateFilter = LootRecordDateFilter.SESSION;
private boolean hideIgnoredItems;
private String currentView;
@@ -276,7 +277,7 @@ class LootTrackerPanel extends PluginPanel
}
});
dateFilterComboBox.setSelectedItem(LootRecordDateFilter.ALL);
dateFilterComboBox.setSelectedItem(this.dateFilter);
dateFilterComboBox.setToolTipText("Filter the displayed loot records by date");
dateFilterComboBox.setMaximumSize(new Dimension(15, 0));
dateFilterComboBox.setMaximumRowCount(3);
@@ -395,6 +396,7 @@ class LootTrackerPanel extends PluginPanel
// Add error pane
errorPanel.setContent("Loot tracker", "You have not received any loot yet.");
add(errorPanel);
actionsContainer.setVisible(true);
}
void loadHeaderIcon(BufferedImage img)
@@ -463,10 +465,7 @@ class LootTrackerPanel extends PluginPanel
boxes.clear();
logsContainer.removeAll();
logsContainer.repaint();
if (config.localPersistence())
{
plugin.deleteLocalRecords();
}
plugin.deleteLocalRecords();
}
/**
@@ -528,10 +527,24 @@ class LootTrackerPanel extends PluginPanel
buildBox(records.get(i));
continue;
}
if (Instant.now().toEpochMilli() - records.get(i).getTimestamp().toEpochMilli() <= this.dateFilter.getDuration().toMillis())
if (dateFilter.equals(LootRecordDateFilter.SESSION))
{
buildBox(records.get(i));
if (records.get(i).getTimestamp().toEpochMilli() > dateFilter.getDuration().toMillis())
{
buildBox(records.get(i));
continue;
}
}
else
{
if (Instant.now().toEpochMilli() - records.get(i).getTimestamp().toEpochMilli() <= this.dateFilter.getDuration().toMillis())
{
buildBox(records.get(i));
}
}
}
boxes.forEach(LootTrackerBox::rebuild);
@@ -686,10 +699,20 @@ class LootTrackerPanel extends PluginPanel
}
if (!dateFilter.equals(LootRecordDateFilter.ALL))
{
if (Instant.now().toEpochMilli() - record.getTimestamp().toEpochMilli()
> this.dateFilter.getDuration().toMillis())
if (dateFilter.equals(LootRecordDateFilter.SESSION))
{
continue;
if (!(record.getTimestamp().toEpochMilli() > dateFilter.getDuration().toMillis()))
{
continue;
}
}
else
{
if (Instant.now().toEpochMilli() - record.getTimestamp().toEpochMilli()
> this.dateFilter.getDuration().toMillis())
{
continue;
}
}
}

View File

@@ -146,6 +146,11 @@ public class LootTrackerPlugin extends Plugin
12342, // Edgeville
11062 // Camelot
);
// Instant for showing session loot. this gets set on plugin startup
public static final Instant SESSION_START_TIME = Instant.now();
@Inject
public Client client;
@VisibleForTesting
@@ -289,6 +294,7 @@ public class LootTrackerPlugin extends Plugin
@Override
protected void startUp() throws Exception
{
addSubscriptions();
ignoredItems = Text.fromCSV(config.getIgnoredItems());
@@ -690,7 +696,7 @@ public class LootTrackerPlugin extends Plugin
{
lootTrackerClient.submit(lootRecord);
}
if (this.localPersistence && lootTrackerClient == null)
if (this.localPersistence)
{
saveLocalLootRecord(lootRecord);
}
@@ -752,8 +758,8 @@ public class LootTrackerPlugin extends Plugin
}
catch (IOException e)
{
log.debug("Error deleting local loot records file.");
log.debug(Arrays.toString(e.getStackTrace()));
log.error("Error deleting local loot records file.");
log.error(Arrays.toString(e.getStackTrace()));
}
}