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; package net.runelite.client.plugins.loottracker;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.time.Duration; import java.time.Duration;
import lombok.Getter; import lombok.Getter;
public enum LootRecordDateFilter public enum LootRecordDateFilter
{ {
SESSION("Session", Duration.ofMillis(LootTrackerPlugin.SESSION_START_TIME.toEpochMilli())),
HOUR("Hour", Duration.ofHours(1)), HOUR("Hour", Duration.ofHours(1)),
DAY("Day", Duration.ofDays(1)), DAY("Day", Duration.ofDays(1)),
WEEK("Week", Duration.ofDays(7)), WEEK("Week", Duration.ofDays(7)),
@@ -27,7 +31,16 @@ public enum LootRecordDateFilter
private final String name; private final String name;
@Getter @Getter
private final Duration duration; 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) private LootRecordDateFilter(String name, Duration duration)
{ {
this.name = name; this.name = name;

View File

@@ -120,7 +120,8 @@ class LootTrackerPanel extends PluginPanel
private final LootTrackerConfig config; private final LootTrackerConfig config;
private boolean groupLoot; private boolean groupLoot;
private LootRecordDateFilter dateFilter = LootRecordDateFilter.ALL; // Set default date filter to session data
private LootRecordDateFilter dateFilter = LootRecordDateFilter.SESSION;
private boolean hideIgnoredItems; private boolean hideIgnoredItems;
private String currentView; 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.setToolTipText("Filter the displayed loot records by date");
dateFilterComboBox.setMaximumSize(new Dimension(15, 0)); dateFilterComboBox.setMaximumSize(new Dimension(15, 0));
dateFilterComboBox.setMaximumRowCount(3); dateFilterComboBox.setMaximumRowCount(3);
@@ -395,6 +396,7 @@ class LootTrackerPanel extends PluginPanel
// Add error pane // Add error pane
errorPanel.setContent("Loot tracker", "You have not received any loot yet."); errorPanel.setContent("Loot tracker", "You have not received any loot yet.");
add(errorPanel); add(errorPanel);
actionsContainer.setVisible(true);
} }
void loadHeaderIcon(BufferedImage img) void loadHeaderIcon(BufferedImage img)
@@ -463,10 +465,7 @@ class LootTrackerPanel extends PluginPanel
boxes.clear(); boxes.clear();
logsContainer.removeAll(); logsContainer.removeAll();
logsContainer.repaint(); logsContainer.repaint();
if (config.localPersistence()) plugin.deleteLocalRecords();
{
plugin.deleteLocalRecords();
}
} }
/** /**
@@ -528,10 +527,24 @@ class LootTrackerPanel extends PluginPanel
buildBox(records.get(i)); buildBox(records.get(i));
continue; 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); boxes.forEach(LootTrackerBox::rebuild);
@@ -686,10 +699,20 @@ class LootTrackerPanel extends PluginPanel
} }
if (!dateFilter.equals(LootRecordDateFilter.ALL)) if (!dateFilter.equals(LootRecordDateFilter.ALL))
{ {
if (Instant.now().toEpochMilli() - record.getTimestamp().toEpochMilli() if (dateFilter.equals(LootRecordDateFilter.SESSION))
> this.dateFilter.getDuration().toMillis())
{ {
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 12342, // Edgeville
11062 // Camelot 11062 // Camelot
); );
// Instant for showing session loot. this gets set on plugin startup
public static final Instant SESSION_START_TIME = Instant.now();
@Inject @Inject
public Client client; public Client client;
@VisibleForTesting @VisibleForTesting
@@ -289,6 +294,7 @@ public class LootTrackerPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
addSubscriptions(); addSubscriptions();
ignoredItems = Text.fromCSV(config.getIgnoredItems()); ignoredItems = Text.fromCSV(config.getIgnoredItems());
@@ -690,7 +696,7 @@ public class LootTrackerPlugin extends Plugin
{ {
lootTrackerClient.submit(lootRecord); lootTrackerClient.submit(lootRecord);
} }
if (this.localPersistence && lootTrackerClient == null) if (this.localPersistence)
{ {
saveLocalLootRecord(lootRecord); saveLocalLootRecord(lootRecord);
} }
@@ -752,8 +758,8 @@ public class LootTrackerPlugin extends Plugin
} }
catch (IOException e) catch (IOException e)
{ {
log.debug("Error deleting local loot records file."); log.error("Error deleting local loot records file.");
log.debug(Arrays.toString(e.getStackTrace())); log.error(Arrays.toString(e.getStackTrace()));
} }
} }