import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /** * RuneLite-style Ground Items Plugin for Revision 377 client. * Features: * - Highlighted items with custom magenta/cyan colors and wildcard matching. * - Hidden items filter (omitted from overlay). * - Tile collapsing (merges identical items on the same ground tile). * - Vertical stacked offsets per tile (prevents overlapping labels). * - Price & value tiers: Common, Low, Medium, High, and Insane value coloring. * - Radiant 3D lootbeams for high-value and highlighted drops. * - Deprioritizes left-click 'Take' for hidden ground items below 'Walk here'. * - Chat commands (::highlight, ::hide, ::unhighlight, ::unhide, ::grounditems). */ public class GroundItemsOverlayPlugin extends ClientPlugin { // Configurable Settings private boolean showNames = true; private boolean showQuantities = true; private boolean showValues = true; private boolean collapseEntries = true; private boolean showLootbeam = true; private boolean deprioritizeHidden = true; private String highlightedItems = "clue scroll*, *whip, rune *, dragon *, dark bow"; private String hiddenItems = "vial, empty vial, ashes, pot, jug, bucket, bones"; private int lowValueThreshold = 1000; private int mediumValueThreshold = 10000; private int highValueThreshold = 100000; private int insaneValueThreshold = 1000000; // Opacity & Transparency settings (0 = transparent, 255 = solid) private int boxOpacity = 100; private int textOpacity = 200; // Color Palette (RuneLite Authentic) public static final int COLOR_HIGHLIGHT = 0xdc00ff; // Magenta public static final int COLOR_INSANE = 0xff9810; // Orange/Amber public static final int COLOR_HIGH = 0xffd700; // Gold/Yellow public static final int COLOR_MEDIUM = 0x00ffff; // Cyan public static final int COLOR_LOW = 0x66ff66; // Light Green public static final int COLOR_COMMON = 0xffffff; // White @Override public String getName() { return "Ground Items"; } @Override public String getDescription() { return "RuneLite-style ground item labels, price tiers, lootbeams, and tile collapsing."; } @Override public String getAuthor() { return "2006Scape"; } @Override public boolean isEnabledByDefault() { return true; } @Override public List getConfigItems() { List list = new ArrayList<>(); list.add(new PluginConfigItem("showNames", "Show Ground Items", "Render names and values over ground items", showNames)); list.add(new PluginConfigItem("highlightedItems", "Highlighted Items", "Comma-separated items or wildcards to highlight (e.g. rune *, whip)", highlightedItems)); list.add(new PluginConfigItem("hiddenItems", "Hidden Items", "Comma-separated items or wildcards to hide (e.g. ashes, vial)", hiddenItems)); list.add(new PluginConfigItem("collapseEntries", "Collapse Duplicates", "Collapse identical ground items on the same tile", collapseEntries)); list.add(new PluginConfigItem("showQuantities", "Show Quantities", "Display quantity stack size next to item names", showQuantities)); list.add(new PluginConfigItem("showValues", "Show Values", "Display store/alch value in gold next to items", showValues)); list.add(new PluginConfigItem("showLootbeam", "Show Lootbeams", "Display radiant vertical light beams on valuable drops", showLootbeam)); list.add(new PluginConfigItem("deprioritizeHidden", "Deprioritize Hidden", "Move left-click 'Take' below 'Walk here' for hidden items", deprioritizeHidden)); list.add(new PluginConfigItem("lowValueThreshold", "Low Value (Green)", "Threshold for low value items (gp)", lowValueThreshold, 0, 1000000)); list.add(new PluginConfigItem("mediumValueThreshold", "Medium Value (Cyan)", "Threshold for medium value items (gp)", mediumValueThreshold, 0, 10000000)); list.add(new PluginConfigItem("highValueThreshold", "High Value (Gold)", "Threshold for high value items (gp)", highValueThreshold, 0, 100000000)); list.add(new PluginConfigItem("insaneValueThreshold", "Insane Value (Orange)", "Threshold for insane value items (gp)", insaneValueThreshold, 0, 2000000000)); list.add(new PluginConfigItem("boxOpacity", "Box Opacity", "Background pill box opacity (0 = transparent, 255 = solid)", boxOpacity, 0, 255)); list.add(new PluginConfigItem("textOpacity", "Text Opacity", "Font transparency for item labels (50 = faint, 255 = solid)", textOpacity, 50, 255)); list.add(new PluginConfigItem("chatCommands", "Chat Commands", "Allow ::highlight / ::unhighlight / ::hide in chat", true)); return list; } @Override public void onConfigChanged(String key, Object value) { if ("showNames".equals(key)) showNames = (Boolean) value; else if ("highlightedItems".equals(key)) highlightedItems = (String) value; else if ("hiddenItems".equals(key)) hiddenItems = (String) value; else if ("collapseEntries".equals(key)) collapseEntries = (Boolean) value; else if ("showQuantities".equals(key)) showQuantities = (Boolean) value; else if ("showValues".equals(key)) showValues = (Boolean) value; else if ("showLootbeam".equals(key)) showLootbeam = (Boolean) value; else if ("deprioritizeHidden".equals(key)) deprioritizeHidden = (Boolean) value; else if ("lowValueThreshold".equals(key)) lowValueThreshold = ((Number) value).intValue(); else if ("mediumValueThreshold".equals(key)) mediumValueThreshold = ((Number) value).intValue(); else if ("highValueThreshold".equals(key)) highValueThreshold = ((Number) value).intValue(); else if ("insaneValueThreshold".equals(key)) insaneValueThreshold = ((Number) value).intValue(); else if ("boxOpacity".equals(key)) boxOpacity = ((Number) value).intValue(); else if ("textOpacity".equals(key)) textOpacity = ((Number) value).intValue(); } /** * Grouped item entry for rendering vertically stacked on a tile. */ private static class DisplayItem { final int id; final String name; int amount; final int singleValue; long totalValue; final boolean isHighlighted; final int color; DisplayItem(PluginContext.GroundItemWrapper item, boolean isHighlighted, int color) { this.id = item.id; this.name = item.name; this.amount = item.amount; this.singleValue = item.value; this.totalValue = item.totalValue; this.isHighlighted = isHighlighted; this.color = color; } void addAmount(int add) { this.amount += add; this.totalValue = (long) this.singleValue * this.amount; } } @Override public void onRenderOverlay(PluginGraphics g) { if (!showNames || ctx == null || !ctx.isLoggedIn()) return; List rawItems = ctx.getGroundItems(); if (rawItems == null || rawItems.isEmpty()) return; // Group items by tile: key = (worldX << 16) | (worldY & 0xffff) Map> tileMap = new LinkedHashMap<>(); Map tileCoords = new HashMap<>(); for (PluginContext.GroundItemWrapper raw : rawItems) { if (raw.getDistance() > 20) continue; // Check hidden filter if (isItemHidden(raw.name)) { continue; } boolean isHl = isItemHighlighted(raw.name); int color = getItemColor(raw.name, raw.totalValue, isHl); long tileKey = (((long) raw.worldX) << 32) | (raw.worldY & 0xffffffffL); List list = tileMap.computeIfAbsent(tileKey, k -> new ArrayList<>()); tileCoords.putIfAbsent(tileKey, new int[]{raw.worldX, raw.worldY}); if (collapseEntries) { // Check if identical item already on tile DisplayItem existing = null; for (DisplayItem d : list) { if (d.id == raw.id) { existing = d; break; } } if (existing != null) { existing.addAmount(raw.amount); continue; } } list.add(new DisplayItem(raw, isHl, color)); } // Render each tile's stacked items for (Map.Entry> entry : tileMap.entrySet()) { long tileKey = entry.getKey(); List itemsOnTile = entry.getValue(); if (itemsOnTile.isEmpty()) continue; int[] coords = tileCoords.get(tileKey); int tileX = coords[0]; int tileY = coords[1]; // Sort so most valuable / highlighted items are on top Collections.sort(itemsOnTile, (a, b) -> { if (a.isHighlighted != b.isHighlighted) { return a.isHighlighted ? 1 : -1; } return Long.compare(a.totalValue, b.totalValue); }); // Check if tile qualifies for a lootbeam if (showLootbeam) { DisplayItem bestItem = itemsOnTile.get(itemsOnTile.size() - 1); if (bestItem.isHighlighted || bestItem.totalValue >= highValueThreshold) { g.drawLootbeam(tileX, tileY, bestItem.color); } } // Project ground coordinates int[] screen = g.worldToScreen(tileX, tileY, 20); if (screen == null) continue; int baseX = screen[0]; int baseY = screen[1]; // Render items vertically stacked with offset for (int i = 0; i < itemsOnTile.size(); i++) { DisplayItem item = itemsOnTile.get(i); int rowY = baseY - (i * 14); String label = buildItemLabel(item); int textW = g.getTextWidth(label); int boxX = baseX - (textW / 2) - 3; int boxY = rowY - 11; int boxW = textW + 6; int boxH = 13; // Soft translucent background pill box if (boxOpacity > 0) { g.fillRect(boxX, boxY, boxW, boxH, 0x000000, boxOpacity); } // Highlighted / Insane items get colored borders if (item.isHighlighted || item.totalValue >= insaneValueThreshold) { g.drawRect(boxX, boxY, boxW, boxH, item.color); } else if (item.totalValue >= highValueThreshold) { g.drawRect(boxX, boxY, boxW, boxH, 0x4a4338); } // Render text with configured alpha transparency g.drawCenteredString(label, baseX, rowY - 1, item.color, textOpacity); } } } /** * Deprioritizes left-click Take for hidden items below 'Walk here'. */ @Override public void onPreMenuRender(List entries) { if (!deprioritizeHidden || entries == null || entries.size() <= 1) return; // Default left-click action is at the end of the entries list int topIdx = entries.size() - 1; MenuEntry top = entries.get(topIdx); if ("Take".equalsIgnoreCase(top.getAction())) { String targetName = MenuEntry.stripColorTags(top.getTarget()); if (isItemHidden(targetName)) { // Find Walk here entry int walkIdx = -1; for (int i = 0; i < entries.size(); i++) { String clean = MenuEntry.stripColorTags(entries.get(i).getRawText()).toLowerCase(); if (clean.startsWith("walk here") || clean.startsWith("walk")) { walkIdx = i; break; } } if (walkIdx != -1 && walkIdx != topIdx) { // Promote Walk here to the top (default left click) MenuEntry walk = entries.remove(walkIdx); entries.add(walk); } } } } private String buildItemLabel(DisplayItem item) { StringBuilder sb = new StringBuilder(item.name); if (showQuantities && item.amount > 1) { sb.append(" (").append(formatQuantity(item.amount)).append(")"); } if (showValues && item.totalValue > 0) { sb.append(" [").append(formatValue(item.totalValue)).append("]"); } return sb.toString(); } private int getItemColor(String name, long totalValue, boolean isHighlighted) { if (isHighlighted) return COLOR_HIGHLIGHT; if (totalValue >= insaneValueThreshold) return COLOR_INSANE; if (totalValue >= highValueThreshold) return COLOR_HIGH; if (totalValue >= mediumValueThreshold) return COLOR_MEDIUM; if (totalValue >= lowValueThreshold) return COLOR_LOW; return COLOR_COMMON; } public boolean isItemHighlighted(String name) { return matchesAnyPattern(name, highlightedItems); } public boolean isItemHidden(String name) { return matchesAnyPattern(name, hiddenItems); } private static boolean matchesAnyPattern(String text, String commaSeparatedPatterns) { if (text == null || commaSeparatedPatterns == null || commaSeparatedPatterns.trim().isEmpty()) { return false; } String cleanText = text.trim().toLowerCase(); String[] patterns = commaSeparatedPatterns.split(","); for (String p : patterns) { String pat = p.trim().toLowerCase(); if (pat.isEmpty()) continue; if (matchesWildcard(cleanText, pat)) { return true; } } return false; } private static boolean matchesWildcard(String text, String pattern) { if ("*".equals(pattern)) return true; if (pattern.startsWith("*") && pattern.endsWith("*")) { String mid = pattern.substring(1, pattern.length() - 1); return text.contains(mid); } if (pattern.startsWith("*")) { return text.endsWith(pattern.substring(1)); } if (pattern.endsWith("*")) { return text.startsWith(pattern.substring(0, pattern.length() - 1)); } return text.equals(pattern); } private static String formatQuantity(int amount) { if (amount >= 10000000) return (amount / 1000000) + "m"; if (amount >= 100000) return (amount / 1000) + "k"; if (amount >= 1000) { DecimalFormat df = new DecimalFormat("#,###"); return df.format(amount); } return String.valueOf(amount); } private static String formatValue(long value) { if (value >= 10000000) return (value / 1000000) + "M gp"; if (value >= 1000000) return String.format("%.1fM gp", value / 1000000.0); if (value >= 1000) return (value / 1000) + "k gp"; return value + " gp"; } @Override public boolean onCommand(String command, String[] args) { String cmd = command.toLowerCase(); if ("highlight".equals(cmd) || "hl".equals(cmd)) { if (args.length > 0) { String item = joinArgs(args); highlightedItems = (highlightedItems != null && !highlightedItems.isEmpty()) ? highlightedItems + ", " + item : item; if (ctx != null) ctx.sendClientMessage("Added to ground item highlights: " + item); } else if (ctx != null) { ctx.sendClientMessage("Usage: ::highlight "); } return true; } if ("unhighlight".equals(cmd) || "unhl".equals(cmd)) { if (args.length > 0) { String item = joinArgs(args); highlightedItems = removePattern(highlightedItems, item); if (ctx != null) ctx.sendClientMessage("Removed from ground item highlights: " + item); } return true; } if ("hide".equals(cmd)) { if (args.length > 0) { String item = joinArgs(args); hiddenItems = (hiddenItems != null && !hiddenItems.isEmpty()) ? hiddenItems + ", " + item : item; if (ctx != null) ctx.sendClientMessage("Added to hidden ground items: " + item); } else if (ctx != null) { ctx.sendClientMessage("Usage: ::hide "); } return true; } if ("unhide".equals(cmd)) { if (args.length > 0) { String item = joinArgs(args); hiddenItems = removePattern(hiddenItems, item); if (ctx != null) ctx.sendClientMessage("Removed from hidden ground items: " + item); } return true; } if ("grounditems".equals(cmd) || "gi".equals(cmd)) { if (ctx != null) { ctx.sendClientMessage("Ground Items Config: [Highlighted: " + highlightedItems + "]"); ctx.sendClientMessage("Hidden: [" + hiddenItems + "]"); ctx.sendClientMessage("Tiers: Low=" + lowValueThreshold + "gp, Med=" + mediumValueThreshold + "gp, High=" + highValueThreshold + "gp, Insane=" + insaneValueThreshold + "gp"); } return true; } return false; } private static String joinArgs(String[] args) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < args.length; i++) { if (i > 0) sb.append(" "); sb.append(args[i]); } return sb.toString().trim(); } private static String removePattern(String csv, String target) { if (csv == null || target == null) return csv; String[] parts = csv.split(","); StringBuilder sb = new StringBuilder(); for (String p : parts) { String trimmed = p.trim(); if (!trimmed.equalsIgnoreCase(target.trim()) && !trimmed.isEmpty()) { if (sb.length() > 0) sb.append(", "); sb.append(trimmed); } } return sb.toString(); } public int getBoxOpacity() { return boxOpacity; } public void setBoxOpacity(int boxOpacity) { this.boxOpacity = Math.max(0, Math.min(255, boxOpacity)); } public int getTextOpacity() { return textOpacity; } public void setTextOpacity(int textOpacity) { this.textOpacity = Math.max(50, Math.min(255, textOpacity)); } }