NPC Whitelist and Blacklist options for Loot Filter (#709)

* Add blacklist and whitelist to Loot Tracker Plugin

* Fix imports

* style
This commit is contained in:
FrostyFridge
2019-06-24 01:13:35 -07:00
committed by James
parent 818a92bcc9
commit 307d0214fd
2 changed files with 89 additions and 10 deletions

View File

@@ -35,7 +35,9 @@ public interface LootTrackerConfig extends Config
@ConfigItem(
keyName = "ignoredItems",
name = "Ignored items",
description = "Configures which items should be ignored when calculating loot prices."
description = "Configures which items should be ignored when calculating loot prices.",
position = 0,
group = "Filters"
)
default String getIgnoredItems()
{
@@ -91,6 +93,7 @@ public interface LootTrackerConfig extends Config
{
return true;
}
@ConfigItem(
keyName = "sortType",
name = "Sorting",
@@ -101,4 +104,59 @@ public interface LootTrackerConfig extends Config
return LootRecordSortType.TIMESTAMP;
}
@ConfigItem(
keyName = "whitelistEnabled",
name = "NPC Whitelist",
description = "Only track drops from specific NPCs",
position = 1,
group = "Filters",
disabledBy = "blacklistEnabled"
)
default boolean whitelistEnabled()
{
return false;
}
@ConfigItem(
keyName = "getWhitelist",
name = "Whitelist",
description = "Comma-separated list of NPCs to track drops from",
position = 2,
group = "Filters",
hidden = true,
unhide = "whitelistEnabled"
)
default String getWhitelist()
{
return "";
}
@ConfigItem(
keyName = "blacklistEnabled",
name = "NPC Blacklist",
description = "Track drops from all NPCs except for specified ones",
position = 3,
group = "Filters",
disabledBy = "whitelistEnabled"
)
default boolean blacklistEnabled()
{
return false;
}
@ConfigItem(
keyName = "getBlacklist",
name = "Blacklist",
description = "Comma-separated list of NPCs to not track drops from",
position = 4,
group = "Filters",
hidden = true,
unhide = "blacklistEnabled"
)
default String getBlacklist()
{
return "";
}
}

View File

@@ -323,13 +323,14 @@ public class LootTrackerPlugin extends Plugin
log.debug("Loaded {} remote data entries", lootRecords.size());
}
if (config.localPersistence() )
if (config.localPersistence())
{
try
{
lootRecords.addAll(RuneLiteAPI.GSON.fromJson(new FileReader(LOOT_RECORDS_FILE),
new TypeToken<ArrayList<LootRecord>>()
{ }.getType()));
{
}.getType()));
}
catch (IOException | NullPointerException e)
{
@@ -370,8 +371,28 @@ public class LootTrackerPlugin extends Plugin
final int combat = npc.getCombatLevel();
final LootTrackerItem[] entries = buildEntries(stack(items));
String localUsername = client.getLocalPlayer().getName();
if (config.whitelistEnabled())
{
final String configNpcs = config.getWhitelist().toLowerCase();
List<String> whitelist = Text.fromCSV(configNpcs);
if (!whitelist.contains(name.toLowerCase()))
{
return;
}
}
else if (config.blacklistEnabled())
{
final String configNpcs = config.getBlacklist().toLowerCase();
List<String> blacklist = Text.fromCSV(configNpcs);
if (blacklist.contains(name.toLowerCase()))
{
return;
}
}
SwingUtilities.invokeLater(() -> panel.add(name, localUsername, combat, entries));
LootRecord lootRecord = new LootRecord( name, localUsername, LootRecordType.NPC,
LootRecord lootRecord = new LootRecord(name, localUsername, LootRecordType.NPC,
toGameItems(items), Instant.now());
if (lootTrackerClient != null && config.saveLoot())
@@ -404,7 +425,7 @@ public class LootTrackerPlugin extends Plugin
final LootTrackerItem[] entries = buildEntries(stack(items));
String localUsername = client.getLocalPlayer().getName();
SwingUtilities.invokeLater(() -> panel.add(name, localUsername, combat, entries));
LootRecord lootRecord = new LootRecord( name, localUsername, LootRecordType.PLAYER,
LootRecord lootRecord = new LootRecord(name, localUsername, LootRecordType.PLAYER,
toGameItems(items), Instant.now());
if (lootTrackerClient != null && config.saveLoot())
{
@@ -599,7 +620,7 @@ public class LootTrackerPlugin extends Plugin
SwingUtilities.invokeLater(() -> panel.add(name, client.getLocalPlayer().getName(),
client.getLocalPlayer().getCombatLevel(), entries));
LootRecord lootRecord = new LootRecord(name, client.getLocalPlayer().getName(), LootRecordType.DEATH,
toGameItems(itemsLost), Instant.now());
toGameItems(itemsLost), Instant.now());
if (lootTrackerClient != null && config.saveLoot())
{
lootTrackerClient.submit(lootRecord);
@@ -672,10 +693,10 @@ public class LootTrackerPlugin extends Plugin
.forEach(item -> inventorySnapshot.add(item.getId(), item.getQuantity()));
}
if (equipment != null)
{
Arrays.stream(equipment.getItems())
.forEach(item -> inventorySnapshot.add(item.getId(), item.getQuantity()));
if (equipment != null)
{
Arrays.stream(equipment.getItems())
.forEach(item -> inventorySnapshot.add(item.getId(), item.getQuantity()));
}
}