Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds functionality to hide specific items from the discord loot logger. #86

Open
wants to merge 2 commits into
base: discord-loot-logger
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ default boolean sendScreenshot()
)
String lootNpcs();

@ConfigItem(
keyName = "hiddenItems",
name = "Hidden items",
description = "Items that should not trigger a notification, comma separated. Accepts wildcards."
)
default String hiddenItems() {return "";};

@ConfigItem(
keyName = "includeLowValueItems",
name = "Include Low Value Items",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.inject.Provides;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
Expand All @@ -10,6 +13,8 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -31,7 +36,6 @@
import net.runelite.client.util.QuantityFormatter;
import net.runelite.client.util.Text;
import net.runelite.client.util.WildcardMatcher;
import static net.runelite.http.api.RuneLiteAPI.GSON;
import net.runelite.http.api.loottracker.LootRecordType;
import okhttp3.Call;
import okhttp3.Callback;
Expand All @@ -43,6 +47,8 @@
import okhttp3.RequestBody;
import okhttp3.Response;

import static net.runelite.http.api.RuneLiteAPI.GSON;

@Slf4j
@PluginDescriptor(
name = "Discord Loot Logger"
Expand All @@ -66,6 +72,9 @@ public class DiscordLootLoggerPlugin extends Plugin

private List<String> lootNpcs;

private LoadingCache<Integer, Boolean> hiddenItemsCache;
private Collection<String> hiddenItemNames;

private static String itemImageUrl(int itemId)
{
return "https://static.runelite.net/cache/item/icon/" + itemId + ".png";
Expand All @@ -78,11 +87,25 @@ private static String itemImageUrl(int itemId)
protected void startUp()
{
lootNpcs = Collections.emptyList();
String s = config.hiddenItems();
hiddenItemNames = s != null ? Text.fromCSV(s) : Collections.emptyList();
hiddenItemsCache = CacheBuilder.newBuilder()
.maximumSize(512L)
.expireAfterAccess(10, TimeUnit.MINUTES)
.build(new CacheLoader<Integer, Boolean>() {
@Override
public Boolean load(Integer itemId) throws Exception {
ItemComposition itemComp = itemManager.getItemComposition(itemId);
return hiddenItemNames.stream()
.noneMatch(hiddenItem -> WildcardMatcher.matches(hiddenItem, itemComp.getName()));
}
});
}

@Override
protected void shutDown()
{
hiddenItemsCache.invalidateAll();
}

@Provides
Expand All @@ -98,6 +121,9 @@ public void onConfigChanged(ConfigChanged configChanged)
{
String s = config.lootNpcs();
lootNpcs = s != null ? Text.fromCSV(s) : Collections.emptyList();
s = config.hiddenItems();
hiddenItemNames = s != null ? Text.fromCSV(s) : Collections.emptyList();
hiddenItemsCache.invalidateAll();
}
}

Expand Down Expand Up @@ -147,8 +173,16 @@ private String getPlayerName()
return client.getLocalPlayer().getName();
}

private Collection<ItemStack> filterHiddenItems(Collection<ItemStack> items){
return items.stream()
.filter(item -> hiddenItemsCache.getUnchecked(item.getId()))
.collect(Collectors.toList());
}

private void processLoot(String name, Collection<ItemStack> items)
{
items = filterHiddenItems(items);

WebhookBody webhookBody = new WebhookBody();

boolean sendMessage = false;
Expand Down