menu entry swapper: refactor configure shift click menu code to use menu types and ids
This fixes an issue where if the action at the configured shift click action index was null, which can happen due to item variations, the option.equals() check would npe, and prevent configuring shift click on the item.
This commit is contained in:
@@ -105,6 +105,16 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
private static final WidgetMenuOption RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE = new WidgetMenuOption(SAVE,
|
||||
MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB);
|
||||
|
||||
private static final Set<MenuAction> ITEM_MENU_TYPES = ImmutableSet.of(
|
||||
MenuAction.ITEM_FIRST_OPTION,
|
||||
MenuAction.ITEM_SECOND_OPTION,
|
||||
MenuAction.ITEM_THIRD_OPTION,
|
||||
MenuAction.ITEM_FOURTH_OPTION,
|
||||
MenuAction.ITEM_FIFTH_OPTION,
|
||||
MenuAction.EXAMINE_ITEM,
|
||||
MenuAction.ITEM_USE
|
||||
);
|
||||
|
||||
private static final Set<MenuAction> NPC_MENU_TYPES = ImmutableSet.of(
|
||||
MenuAction.NPC_FIRST_OPTION,
|
||||
MenuAction.NPC_SECOND_OPTION,
|
||||
@@ -477,27 +487,27 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
}
|
||||
|
||||
ItemComposition itemComposition = itemManager.getItemComposition(itemId);
|
||||
String itemName = itemComposition.getName();
|
||||
String option = "Use";
|
||||
int shiftClickActionIndex = itemComposition.getShiftClickActionIndex();
|
||||
String[] inventoryActions = itemComposition.getInventoryActions();
|
||||
MenuAction shiftClickAction = MenuAction.ITEM_USE;
|
||||
final int shiftClickActionIndex = itemComposition.getShiftClickActionIndex();
|
||||
|
||||
if (shiftClickActionIndex >= 0 && shiftClickActionIndex < inventoryActions.length)
|
||||
if (shiftClickActionIndex >= 0)
|
||||
{
|
||||
option = inventoryActions[shiftClickActionIndex];
|
||||
shiftClickAction = MenuAction.of(MenuAction.ITEM_FIRST_OPTION.getId() + shiftClickActionIndex);
|
||||
}
|
||||
|
||||
MenuEntry[] entries = event.getMenuEntries();
|
||||
|
||||
for (MenuEntry entry : entries)
|
||||
{
|
||||
if (itemName.equals(Text.removeTags(entry.getTarget())))
|
||||
final MenuAction menuAction = MenuAction.of(entry.getType());
|
||||
|
||||
if (ITEM_MENU_TYPES.contains(menuAction) && entry.getIdentifier() == itemId)
|
||||
{
|
||||
entry.setType(MenuAction.RUNELITE.getId());
|
||||
|
||||
if (option.equals(entry.getOption()))
|
||||
if (shiftClickAction == menuAction)
|
||||
{
|
||||
entry.setOption("* " + option);
|
||||
entry.setOption("* " + entry.getOption());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user