import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * RuneLite-style Menu Entry Swapper Plugin. * Allows left-click swapping for NPCs, objects, ground items, and custom rules. */ public class MenuEntrySwapperPlugin extends ClientPlugin { private boolean swapBank = true; private boolean swapTrade = true; private boolean swapPickpocket = true; private boolean swapTravel = true; private boolean chatCommands = true; private String customRules = ""; @Override public String getName() { return "Menu Entry Swapper"; } @Override public String getDescription() { return "Swaps default left-click actions for Bank, Pickpocket, Trade, and custom rules."; } @Override public String getAuthor() { return "2006Scape"; } @Override public boolean isEnabledByDefault() { return true; } @Override public List getConfigItems() { List list = new ArrayList<>(); list.add(new PluginConfigItem("swapBank", "Swap Bank", "Promote 'Bank' over 'Talk-to' on bankers", swapBank)); list.add(new PluginConfigItem("swapTrade", "Swap Trade", "Promote 'Trade' over 'Talk-to' on shopkeepers", swapTrade)); list.add(new PluginConfigItem("swapPickpocket", "Swap Pickpocket", "Promote 'Pickpocket' on NPCs", swapPickpocket)); list.add(new PluginConfigItem("swapTravel", "Swap Travel", "Promote 'Travel'/'Pay-fare' on captains", swapTravel)); list.add(new PluginConfigItem("customRules", "Custom Rules", "Comma-separated Option:Target pairs (e.g. Bury:Bones)", customRules)); list.add(new PluginConfigItem("chatCommands", "Chat Commands", "Allow ::swap / ::swapper in chat", chatCommands)); return list; } @Override public void onConfigChanged(String key, Object value) { if ("swapBank".equals(key)) swapBank = (Boolean) value; else if ("swapTrade".equals(key)) swapTrade = (Boolean) value; else if ("swapPickpocket".equals(key)) swapPickpocket = (Boolean) value; else if ("swapTravel".equals(key)) swapTravel = (Boolean) value; else if ("chatCommands".equals(key)) chatCommands = (Boolean) value; else if ("customRules".equals(key)) customRules = (String) value; } @Override public void onPreMenuRender(List entries) { if (entries == null || entries.size() <= 1) { return; } // Apply custom swap rules first if (customRules != null && !customRules.trim().isEmpty()) { String[] rules = customRules.split(","); for (String rule : rules) { String[] parts = rule.trim().split(":"); if (parts.length >= 2) { String action = parts[0].trim(); String target = parts[1].trim(); if (promoteEntry(entries, action, target)) { return; } } } } // Built-in Bank swap (Banker, Bank booth, Bank chest) if (swapBank) { if (promoteEntry(entries, "Bank", "*") || promoteEntry(entries, "Open", "Bank")) { return; } } // Built-in Pickpocket swap if (swapPickpocket) { if (promoteEntry(entries, "Pickpocket", "*")) { return; } } // Built-in Trade swap if (swapTrade) { if (promoteEntry(entries, "Trade", "*")) { return; } } // Built-in Travel / Pay-fare swap if (swapTravel) { if (promoteEntry(entries, "Pay-fare", "*") || promoteEntry(entries, "Travel", "*") || promoteEntry(entries, "Charter", "*") || promoteEntry(entries, "Teleport", "*")) { return; } } } private boolean promoteEntry(List entries, String action, String target) { int foundIdx = -1; for (int i = 0; i < entries.size(); i++) { MenuEntry e = entries.get(i); if (e.matches(action, target)) { foundIdx = i; break; } } if (foundIdx != -1 && foundIdx != entries.size() - 1) { MenuEntry targetEntry = entries.remove(foundIdx); entries.add(targetEntry); // Top of menu (left-click) return true; } return false; } @Override public boolean onCommand(String command, String[] args) { if ("swap".equalsIgnoreCase(command) || "swapper".equalsIgnoreCase(command)) { if (args.length >= 2 && "add".equalsIgnoreCase(args[0])) { String newRule = args[1].trim(); customRules = (customRules != null && !customRules.isEmpty()) ? customRules + "," + newRule : newRule; if (ctx != null) { ctx.sendClientMessage("Added swap rule: " + newRule); } return true; } else if (args.length >= 1 && "clear".equalsIgnoreCase(args[0])) { customRules = ""; if (ctx != null) { ctx.sendClientMessage("Custom swap rules cleared."); } return true; } else { if (ctx != null) { ctx.sendClientMessage("Menu Swapper Rules: " + customRules); ctx.sendClientMessage("Usage: ::swap add : or ::swap clear"); } return true; } } return false; } }