menuentryswapper: remove shift click customisation for a better alternative. (#1391)

* menuentryswapper: remove shift click customisation for a better alternative.

* menuentryswapper: add proper syntax validation, and convert to priority entries.

* menuentryswapper: Migrate old swaps to the new format

* menuentryswapper: finalize

* menuentryswapper: remove redundant splitter.

* runecraft: fix camelCase on Lavas

* runecraft: disable lavas by default
This commit is contained in:
Ganom
2019-08-18 20:11:48 -04:00
committed by GitHub
parent 3cf4491435
commit 45fd48d01d
6 changed files with 136 additions and 356 deletions

View File

@@ -352,7 +352,8 @@ public interface MenuEntrySwapperConfig extends Config
@ConfigItem( @ConfigItem(
keyName = "customSwaps", keyName = "customSwaps",
name = "Custom Swaps", name = "Custom Swaps",
description = "Add custom swaps here, 1 per line. Syntax: option, target : option, target<br>Note that the first entry should be the left click one!", description = "Add custom swaps here, 1 per line. Syntax: option, target : option, target" +
"<br>Note that the first entry should be the left click one!",
position = 0, position = 0,
group = "Miscellaneous", group = "Miscellaneous",
parse = true, parse = true,
@@ -365,15 +366,20 @@ public interface MenuEntrySwapperConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "shiftClickCustomization", keyName = "shiftCustomSwaps",
name = "Customizable Shift-click", name = "Shift Swaps",
description = "Allows customization of shift-clicks on items.", description = "Add custom swaps here that will only be activated when you press shift" +
"<br>, 1 per line. Syntax: option, target : option, target" +
"<br>Note that the first entry should be the left click one!",
position = 1, position = 1,
group = "Miscellaneous" group = "Miscellaneous",
parse = true,
clazz = Parse.class,
method = "parse"
) )
default boolean shiftClickCustomization() default String shiftCustomSwaps()
{ {
return true; return "";
} }
@ConfigItem( @ConfigItem(

View File

@@ -35,21 +35,16 @@ import com.google.common.collect.Sets;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameState; import net.runelite.api.GameState;
import net.runelite.api.InventoryID; import net.runelite.api.InventoryID;
import net.runelite.api.Item; import net.runelite.api.Item;
import net.runelite.api.ItemDefinition;
import net.runelite.api.MenuAction; import net.runelite.api.MenuAction;
import static net.runelite.api.MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET; import static net.runelite.api.MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
import static net.runelite.api.MenuAction.WALK; import static net.runelite.api.MenuAction.WALK;
@@ -61,26 +56,18 @@ import static net.runelite.api.Varbits.BUILDING_MODE;
import net.runelite.api.WorldType; import net.runelite.api.WorldType;
import net.runelite.api.coords.WorldPoint; import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.FocusChanged;
import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOpened; import net.runelite.api.events.MenuOpened;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.PostItemDefinition;
import net.runelite.api.events.VarbitChanged; import net.runelite.api.events.VarbitChanged;
import net.runelite.api.events.WidgetMenuOptionClicked;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread; import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.EventBus;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.ItemVariationMapping;
import net.runelite.client.input.KeyManager; import net.runelite.client.input.KeyManager;
import net.runelite.client.menus.AbstractComparableEntry; import net.runelite.client.menus.AbstractComparableEntry;
import static net.runelite.client.menus.ComparableEntries.newBankComparableEntry; import static net.runelite.client.menus.ComparableEntries.newBankComparableEntry;
import static net.runelite.client.menus.ComparableEntries.newBaseComparableEntry; import static net.runelite.client.menus.ComparableEntries.newBaseComparableEntry;
import net.runelite.client.menus.MenuManager; import net.runelite.client.menus.MenuManager;
import net.runelite.client.menus.WidgetMenuOption;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDependency; import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
@@ -124,25 +111,8 @@ import org.apache.commons.lang3.ArrayUtils;
@PluginDependency(PvpToolsPlugin.class) @PluginDependency(PvpToolsPlugin.class)
public class MenuEntrySwapperPlugin extends Plugin public class MenuEntrySwapperPlugin extends Plugin
{ {
private static final String CONFIGURE = "Configure";
private static final String SAVE = "Save";
private static final String RESET = "Reset";
private static final String MENU_TARGET = "Shift-click";
private static final String CONFIG_GROUP = "shiftclick"; private static final String CONFIG_GROUP = "shiftclick";
private static final String ITEM_KEY_PREFIX = "item_";
private static final int PURO_PURO_REGION_ID = 10307; private static final int PURO_PURO_REGION_ID = 10307;
private static final WidgetMenuOption FIXED_INVENTORY_TAB_CONFIGURE = new WidgetMenuOption(CONFIGURE,
MENU_TARGET, WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB);
private static final WidgetMenuOption FIXED_INVENTORY_TAB_SAVE = new WidgetMenuOption(SAVE,
MENU_TARGET, WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB);
private static final WidgetMenuOption RESIZABLE_INVENTORY_TAB_CONFIGURE = new WidgetMenuOption(CONFIGURE,
MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB);
private static final WidgetMenuOption RESIZABLE_INVENTORY_TAB_SAVE = new WidgetMenuOption(SAVE,
MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB);
private static final WidgetMenuOption RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE = new WidgetMenuOption(CONFIGURE,
MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB);
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> NPC_MENU_TYPES = ImmutableSet.of( private static final Set<MenuAction> NPC_MENU_TYPES = ImmutableSet.of(
MenuAction.NPC_FIRST_OPTION, MenuAction.NPC_SECOND_OPTION, MenuAction.NPC_THIRD_OPTION, MenuAction.NPC_FIRST_OPTION, MenuAction.NPC_SECOND_OPTION, MenuAction.NPC_THIRD_OPTION,
MenuAction.NPC_FOURTH_OPTION, MenuAction.NPC_FIFTH_OPTION, MenuAction.EXAMINE_NPC MenuAction.NPC_FOURTH_OPTION, MenuAction.NPC_FIFTH_OPTION, MenuAction.EXAMINE_NPC
@@ -159,35 +129,32 @@ public class MenuEntrySwapperPlugin extends Plugin
@Inject @Inject
private MenuEntrySwapperConfig config; private MenuEntrySwapperConfig config;
@Inject @Inject
private ShiftClickInputListener inputListener;
@Inject
private ConfigManager configManager;
@Inject
private PluginManager pluginManager; private PluginManager pluginManager;
@Inject @Inject
private KeyManager keyManager;
@Inject
private MenuManager menuManager; private MenuManager menuManager;
@Inject @Inject
private ItemManager itemManager; private KeyManager keyManager;
@Inject
private ShiftClickInputListener inputListener;
@Inject @Inject
private EventBus eventBus; private EventBus eventBus;
@Inject @Inject
private PvpToolsPlugin pvpTools; private PvpToolsPlugin pvpTools;
@Inject @Inject
private PvpToolsConfig pvpToolsConfig; private PvpToolsConfig pvpToolsConfig;
/**
* Migrates old custom swaps config
* This should be removed after a reasonable amount of time.
*/
@Inject
private ConfigManager configManager;
private MenuEntry[] entries; private MenuEntry[] entries;
private final Set<String> leftClickConstructionItems = new HashSet<>();
private boolean buildingMode; private boolean buildingMode;
private boolean inTobRaid = false; private boolean inTobRaid = false;
private boolean inCoxRaid = false; private boolean inCoxRaid = false;
private final Map<AbstractComparableEntry, AbstractComparableEntry> customSwaps = new HashMap<>(); private final Map<AbstractComparableEntry, Integer> customSwaps = new HashMap<>();
private final Map<AbstractComparableEntry, Integer> customShiftSwaps = new HashMap<>();
private List<String> bankItemNames = new ArrayList<>(); private List<String> bankItemNames = new ArrayList<>();
@Getter(AccessLevel.PACKAGE)
private boolean configuringShiftClick = false;
@Setter(AccessLevel.PACKAGE)
private boolean shiftModifier = false;
private ConstructionMode getConstructionMode; private ConstructionMode getConstructionMode;
private BurningAmuletMode getBurningAmuletMode; private BurningAmuletMode getBurningAmuletMode;
private CharterOption charterOption; private CharterOption charterOption;
@@ -210,6 +177,7 @@ public class MenuEntrySwapperPlugin extends Plugin
private SkillsNecklaceMode getSkillsNecklaceMode; private SkillsNecklaceMode getSkillsNecklaceMode;
private SlayerRingMode getSlayerRingMode; private SlayerRingMode getSlayerRingMode;
private String configCustomSwaps; private String configCustomSwaps;
private String configCustomShiftSwaps;
private String getBuyFiftyItems; private String getBuyFiftyItems;
private String getBuyFiveItems; private String getBuyFiveItems;
private String getBuyOneItems; private String getBuyOneItems;
@@ -277,7 +245,6 @@ public class MenuEntrySwapperPlugin extends Plugin
private boolean hideReport; private boolean hideReport;
private boolean hideTradeWith; private boolean hideTradeWith;
private boolean rockCake; private boolean rockCake;
private boolean shiftClickCustomization;
private boolean swapAbyssTeleport; private boolean swapAbyssTeleport;
private boolean swapAdmire; private boolean swapAdmire;
private boolean swapAssignment; private boolean swapAssignment;
@@ -322,18 +289,13 @@ public class MenuEntrySwapperPlugin extends Plugin
@Override @Override
public void startUp() public void startUp()
{ {
migrateConfig();
updateConfig(); updateConfig();
addSubscriptions(); addSubscriptions();
addSwaps(); addSwaps();
loadConstructionItems(); loadConstructionItems();
loadCustomSwaps(config.customSwaps(), customSwaps);
if (config.shiftClickCustomization()) keyManager.registerKeyListener(inputListener);
{
enableCustomization();
}
loadCustomSwaps(config.customSwaps());
if (client.getGameState() == GameState.LOGGED_IN) if (client.getGameState() == GameState.LOGGED_IN)
{ {
setCastOptions(true); setCastOptions(true);
@@ -345,10 +307,9 @@ public class MenuEntrySwapperPlugin extends Plugin
{ {
eventBus.unregister(this); eventBus.unregister(this);
disableCustomization(); loadCustomSwaps("", customSwaps); // Removes all custom swaps
loadCustomSwaps(""); // Removes all custom swaps
removeSwaps(); removeSwaps();
keyManager.unregisterKeyListener(inputListener);
if (client.getGameState() == GameState.LOGGED_IN) if (client.getGameState() == GameState.LOGGED_IN)
{ {
resetCastOptions(); resetCastOptions();
@@ -358,14 +319,10 @@ public class MenuEntrySwapperPlugin extends Plugin
private void addSubscriptions() private void addSubscriptions()
{ {
eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged); eventBus.subscribe(ConfigChanged.class, this, this::onConfigChanged);
eventBus.subscribe(WidgetMenuOptionClicked.class, this, this::onWidgetMenuOptionClicked);
eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged); eventBus.subscribe(GameStateChanged.class, this, this::onGameStateChanged);
eventBus.subscribe(VarbitChanged.class, this, this::onVarbitChanged); eventBus.subscribe(VarbitChanged.class, this, this::onVarbitChanged);
eventBus.subscribe(MenuOpened.class, this, this::onMenuOpened); eventBus.subscribe(MenuOpened.class, this, this::onMenuOpened);
eventBus.subscribe(MenuOptionClicked.class, this, this::onMenuOptionClicked);
eventBus.subscribe(MenuEntryAdded.class, this, this::onMenuEntryAdded); eventBus.subscribe(MenuEntryAdded.class, this, this::onMenuEntryAdded);
eventBus.subscribe(PostItemDefinition.class, this, this::onPostItemDefinition);
eventBus.subscribe(FocusChanged.class, this, this::onFocusChanged);
} }
private void onConfigChanged(ConfigChanged event) private void onConfigChanged(ConfigChanged event)
@@ -384,26 +341,10 @@ public class MenuEntrySwapperPlugin extends Plugin
{ {
if (event.getKey().equals("customSwaps")) if (event.getKey().equals("customSwaps"))
{ {
loadCustomSwaps(this.configCustomSwaps); loadCustomSwaps(this.configCustomSwaps, customSwaps);
} }
} }
if (event.getKey().equals("shiftClickCustomization"))
{
if (this.shiftClickCustomization)
{
enableCustomization();
}
else
{
disableCustomization();
}
}
else if (event.getKey().startsWith(ITEM_KEY_PREFIX))
{
clientThread.invoke(this::resetItemDefinitionCache);
}
else if ((event.getKey().equals("hideCastToB") || event.getKey().equals("hideCastIgnoredToB"))) else if ((event.getKey().equals("hideCastToB") || event.getKey().equals("hideCastIgnoredToB")))
{ {
if (this.hideCastToB) if (this.hideCastToB)
@@ -429,62 +370,6 @@ public class MenuEntrySwapperPlugin extends Plugin
} }
} }
private void resetItemDefinitionCache()
{
itemManager.invalidateItemDefinitionCache();
client.getItemDefinitionCache().reset();
}
private Integer getSwapConfig(int itemId)
{
itemId = ItemVariationMapping.map(itemId);
String config = configManager.getConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId);
if (config == null || config.isEmpty())
{
return null;
}
return Integer.parseInt(config);
}
private void setSwapConfig(int itemId, int index)
{
itemId = ItemVariationMapping.map(itemId);
configManager.setConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId, index);
}
private void unsetSwapConfig(int itemId)
{
itemId = ItemVariationMapping.map(itemId);
configManager.unsetConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId);
}
private void enableCustomization()
{
keyManager.registerKeyListener(inputListener);
refreshShiftClickCustomizationMenus();
clientThread.invoke(this::resetItemDefinitionCache);
}
private void disableCustomization()
{
keyManager.unregisterKeyListener(inputListener);
removeShiftClickCustomizationMenus();
configuringShiftClick = false;
clientThread.invoke(this::resetItemDefinitionCache);
}
private void onWidgetMenuOptionClicked(WidgetMenuOptionClicked event)
{
if (event.getWidget() == WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB
|| event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB
|| event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB)
{
configuringShiftClick = event.getMenuOption().equals(CONFIGURE) && Text.removeTags(event.getMenuTarget()).equals(MENU_TARGET);
refreshShiftClickCustomizationMenus();
}
}
private void onGameStateChanged(GameStateChanged event) private void onGameStateChanged(GameStateChanged event)
{ {
if (client.getGameState() != GameState.LOGGED_IN) if (client.getGameState() != GameState.LOGGED_IN)
@@ -597,121 +482,7 @@ public class MenuEntrySwapperPlugin extends Plugin
MenuEntry[] updated_menu_entries = new MenuEntry[menu_entries.size()]; MenuEntry[] updated_menu_entries = new MenuEntry[menu_entries.size()];
updated_menu_entries = menu_entries.toArray(updated_menu_entries); updated_menu_entries = menu_entries.toArray(updated_menu_entries);
client.setMenuEntries(updated_menu_entries); client.setMenuEntries(updated_menu_entries);
if (!configuringShiftClick)
{
return;
}
MenuEntry firstEntry = event.getFirstEntry();
if (firstEntry == null)
{
return;
}
int widgetId = firstEntry.getParam1();
if (widgetId != WidgetInfo.INVENTORY.getId())
{
return;
}
int itemId = firstEntry.getIdentifier();
if (itemId == -1)
{
return;
}
ItemDefinition itemComposition = client.getItemDefinition(itemId);
String itemName = itemComposition.getName();
String option = "Use";
int shiftClickActionIndex = itemComposition.getShiftClickActionIndex();
String[] inventoryActions = itemComposition.getInventoryActions();
if (shiftClickActionIndex >= 0 && shiftClickActionIndex < inventoryActions.length)
{
option = inventoryActions[shiftClickActionIndex];
}
MenuEntry[] entries = event.getMenuEntries();
for (MenuEntry entry : entries)
{
if (itemName.equals(Text.removeTags(entry.getTarget())))
{
entry.setType(MenuAction.RUNELITE.getId());
if (option.equals(entry.getOption()))
{
entry.setOption("* " + option);
}
}
}
final MenuEntry resetShiftClickEntry = new MenuEntry();
resetShiftClickEntry.setOption(RESET);
resetShiftClickEntry.setTarget(MENU_TARGET);
resetShiftClickEntry.setIdentifier(itemId);
resetShiftClickEntry.setParam1(widgetId);
resetShiftClickEntry.setType(MenuAction.RUNELITE.getId());
client.setMenuEntries(ArrayUtils.addAll(entries, resetShiftClickEntry));
}
private void onMenuOptionClicked(MenuOptionClicked event)
{
if (event.getMenuAction() != MenuAction.RUNELITE || event.getActionParam1() != WidgetInfo.INVENTORY.getId())
{
return;
}
int itemId = event.getIdentifier();
if (itemId == -1)
{
return;
}
String option = event.getOption();
String target = event.getTarget();
ItemDefinition itemComposition = client.getItemDefinition(itemId);
if (option.equals(RESET) && target.equals(MENU_TARGET))
{
unsetSwapConfig(itemId);
return;
}
if (!itemComposition.getName().equals(Text.removeTags(target)))
{
return;
}
int index = -1;
boolean valid = false;
if (option.equals("Use")) //because "Use" is not in inventoryActions
{
valid = true;
}
else
{
String[] inventoryActions = itemComposition.getInventoryActions();
for (index = 0; index < inventoryActions.length; index++)
{
if (option.equals(inventoryActions[index]))
{
valid = true;
break;
}
}
}
if (valid)
{
setSwapConfig(itemId, index);
}
} }
public void onMenuEntryAdded(MenuEntryAdded event) public void onMenuEntryAdded(MenuEntryAdded event)
@@ -867,71 +638,15 @@ public class MenuEntrySwapperPlugin extends Plugin
break; break;
} }
} }
if (this.shiftClickCustomization && shiftModifier && !option.equals("use"))
{
final Integer customOption = getSwapConfig(eventId);
if (customOption != null && customOption == -1)
{
swap(client, "use", option, target, true);
}
}
} }
private void onPostItemDefinition(PostItemDefinition event) private void loadCustomSwaps(String config, Map<AbstractComparableEntry, Integer> map)
{ {
ItemDefinition itemComposition = event.getItemDefinition(); final Map<AbstractComparableEntry, Integer> tmp = new HashMap<>();
Integer option = getSwapConfig(itemComposition.getId());
if (option != null)
{
itemComposition.setShiftClickActionIndex(option);
}
}
private void onFocusChanged(FocusChanged event)
{
if (!event.isFocused())
{
shiftModifier = false;
}
}
private void removeShiftClickCustomizationMenus()
{
menuManager.removeManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE);
menuManager.removeManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE);
menuManager.removeManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE);
menuManager.removeManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE);
menuManager.removeManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE);
menuManager.removeManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE);
}
private void refreshShiftClickCustomizationMenus()
{
removeShiftClickCustomizationMenus();
if (configuringShiftClick)
{
menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE);
menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE);
menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE);
}
else
{
menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE);
menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE);
menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE);
}
}
private void loadCustomSwaps(String config)
{
Map<AbstractComparableEntry, AbstractComparableEntry> tmp = new HashMap<>();
if (!Strings.isNullOrEmpty(config)) if (!Strings.isNullOrEmpty(config))
{ {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for (String str : config.split("\n")) for (String str : config.split("\n"))
{ {
@@ -941,15 +656,23 @@ public class MenuEntrySwapperPlugin extends Plugin
} }
} }
Map<String, String> split = NEWLINE_SPLITTER.withKeyValueSeparator(':').split(sb); final Map<String, String> split = NEWLINE_SPLITTER.withKeyValueSeparator(':').split(sb);
for (Map.Entry<String, String> entry : split.entrySet()) for (Map.Entry<String, String> entry : split.entrySet())
{ {
String from = entry.getKey(); final String prio = entry.getKey();
String to = entry.getValue(); int priority;
String[] splitFrom = Text.standardize(from).split(","); try
String optionFrom = splitFrom[0].trim(); {
String targetFrom; priority = Integer.parseInt(entry.getValue().trim());
}
catch (NumberFormatException e)
{
priority = 0;
}
final String[] splitFrom = Text.standardize(prio).split(",");
final String optionFrom = splitFrom[0].trim();
final String targetFrom;
if (splitFrom.length == 1) if (splitFrom.length == 1)
{ {
targetFrom = ""; targetFrom = "";
@@ -959,41 +682,26 @@ public class MenuEntrySwapperPlugin extends Plugin
targetFrom = splitFrom[1].trim(); targetFrom = splitFrom[1].trim();
} }
AbstractComparableEntry fromEntry = newBaseComparableEntry(optionFrom, targetFrom); final AbstractComparableEntry prioEntry = newBaseComparableEntry(optionFrom, targetFrom);
String[] splitTo = Text.standardize(to).split(","); tmp.put(prioEntry, priority);
String optionTo = splitTo[0].trim();
String targetTo;
if (splitTo.length == 1)
{
targetTo = "";
}
else
{
targetTo = splitTo[1].trim();
}
AbstractComparableEntry toEntry = newBaseComparableEntry(optionTo, targetTo);
tmp.put(fromEntry, toEntry);
} }
} }
for (Map.Entry<AbstractComparableEntry, AbstractComparableEntry> e : customSwaps.entrySet()) for (Map.Entry<AbstractComparableEntry, Integer> e : map.entrySet())
{ {
AbstractComparableEntry key = e.getKey(); final AbstractComparableEntry key = e.getKey();
AbstractComparableEntry value = e.getValue(); menuManager.removePriorityEntry(key);
menuManager.removeSwap(key, value);
} }
customSwaps.clear(); map.clear();
customSwaps.putAll(tmp); map.putAll(tmp);
for (Map.Entry<AbstractComparableEntry, AbstractComparableEntry> entry : customSwaps.entrySet()) for (Map.Entry<AbstractComparableEntry, Integer> entry : map.entrySet())
{ {
AbstractComparableEntry a1 = entry.getKey(); AbstractComparableEntry a1 = entry.getKey();
AbstractComparableEntry a2 = entry.getValue(); int a2 = entry.getValue();
menuManager.addSwap(a1, a2); menuManager.addPriorityEntry(a1).setPriority(a2);
} }
} }
@@ -1707,6 +1415,8 @@ public class MenuEntrySwapperPlugin extends Plugin
void startShift() void startShift()
{ {
loadCustomSwaps(this.configCustomShiftSwaps, customShiftSwaps);
if (!this.swapClimbUpDown) if (!this.swapClimbUpDown)
{ {
return; return;
@@ -1718,6 +1428,7 @@ public class MenuEntrySwapperPlugin extends Plugin
void stopShift() void stopShift()
{ {
menuManager.removePriorityEntry("climb-up"); menuManager.removePriorityEntry("climb-up");
loadCustomSwaps("", customShiftSwaps);
} }
void startControl() void startControl()
@@ -1813,7 +1524,7 @@ public class MenuEntrySwapperPlugin extends Plugin
this.swapQuestCape = config.swapQuestCape(); this.swapQuestCape = config.swapQuestCape();
this.questCapeMode = config.questCapeMode(); this.questCapeMode = config.questCapeMode();
this.configCustomSwaps = config.customSwaps(); this.configCustomSwaps = config.customSwaps();
this.shiftClickCustomization = config.shiftClickCustomization(); this.configCustomShiftSwaps = config.shiftCustomSwaps();
this.swapCoalBag = config.swapCoalBag(); this.swapCoalBag = config.swapCoalBag();
this.swapBirdhouseEmpty = config.swapBirdhouseEmpty(); this.swapBirdhouseEmpty = config.swapBirdhouseEmpty();
this.swapBones = config.swapBones(); this.swapBones = config.swapBones();
@@ -1915,4 +1626,64 @@ public class MenuEntrySwapperPlugin extends Plugin
this.hideCastCoX = config.hideCastCoX(); this.hideCastCoX = config.hideCastCoX();
this.hideCastIgnoredCoX = Sets.newHashSet(Text.fromCSV(config.hideCastIgnoredCoX().toLowerCase())); this.hideCastIgnoredCoX = Sets.newHashSet(Text.fromCSV(config.hideCastIgnoredCoX().toLowerCase()));
} }
/**
* Migrates old custom swaps config
* This should be removed after a reasonable amount of time.
*/
private static boolean oldParse(String value)
{
try
{
final StringBuilder sb = new StringBuilder();
for (String str : value.split("\n"))
{
if (!str.startsWith("//"))
{
sb.append(str).append("\n");
}
}
NEWLINE_SPLITTER.withKeyValueSeparator(':').split(sb);
return true;
}
catch (IllegalArgumentException ex)
{
return false;
}
}
/**
* Migrates old custom swaps config
* This should be removed after a reasonable amount of time.
*/
private void migrateConfig()
{
final String customSwaps = config.customSwaps();
if (!Parse.parse(customSwaps) && oldParse(customSwaps))
{
final StringBuilder sb = new StringBuilder();
for (String str : customSwaps.split("\n"))
{
if (!str.startsWith("//"))
{
sb.append(str).append("\n");
}
}
final Map<String, String> split = NEWLINE_SPLITTER.withKeyValueSeparator(':').split(sb);
sb.setLength(0);
for (Map.Entry<String, String> entry : split.entrySet())
{
sb.append(entry.getValue()).append(":0\n");
}
configManager.setConfiguration("menuentryswapper", "customSwaps", sb.toString());
}
}
} }

View File

@@ -25,6 +25,7 @@
package net.runelite.client.plugins.menuentryswapper; package net.runelite.client.plugins.menuentryswapper;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import java.util.Map;
public class Parse public class Parse
{ {
@@ -32,7 +33,7 @@ public class Parse
{ {
try try
{ {
StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
for (String str : value.split("\n")) for (String str : value.split("\n"))
{ {
@@ -42,15 +43,20 @@ public class Parse
} }
} }
Splitter NEWLINE_SPLITTER = Splitter final Splitter NEWLINE_SPLITTER = Splitter
.on("\n") .on("\n")
.omitEmptyStrings() .omitEmptyStrings()
.trimResults(); .trimResults();
NEWLINE_SPLITTER.withKeyValueSeparator(':').split(sb); final Map<String, String> tmp = NEWLINE_SPLITTER.withKeyValueSeparator(':').split(sb);
for (String str : tmp.values())
{
Integer.parseInt(str.trim());
}
return true; return true;
} }
catch (IllegalArgumentException ex) catch (Exception ex)
{ {
return false; return false;
} }

View File

@@ -38,7 +38,6 @@ class ShiftClickInputListener implements KeyListener
@Override @Override
public void keyTyped(KeyEvent event) public void keyTyped(KeyEvent event)
{ {
} }
@Override @Override
@@ -46,7 +45,6 @@ class ShiftClickInputListener implements KeyListener
{ {
if (event.getKeyCode() == KeyEvent.VK_SHIFT) if (event.getKeyCode() == KeyEvent.VK_SHIFT)
{ {
plugin.setShiftModifier(true);
plugin.startShift(); plugin.startShift();
} }
if (event.getKeyCode() == KeyEvent.VK_CONTROL) if (event.getKeyCode() == KeyEvent.VK_CONTROL)
@@ -60,7 +58,6 @@ class ShiftClickInputListener implements KeyListener
{ {
if (event.getKeyCode() == KeyEvent.VK_SHIFT) if (event.getKeyCode() == KeyEvent.VK_SHIFT)
{ {
plugin.setShiftModifier(false);
plugin.stopShift(); plugin.stopShift();
} }
if (event.getKeyCode() == KeyEvent.VK_CONTROL) if (event.getKeyCode() == KeyEvent.VK_CONTROL)

View File

@@ -45,7 +45,7 @@ public interface RunecraftConfig extends Config
} }
@ConfigItem( @ConfigItem(
keyName = "Lavas", keyName = "lavas",
name = "Lavas", name = "Lavas",
description = "Swaps Ring of dueling menu entry depending on location, requires fire tiara or RC cape to be worn.", description = "Swaps Ring of dueling menu entry depending on location, requires fire tiara or RC cape to be worn.",
parent = "utilStub", parent = "utilStub",
@@ -53,9 +53,9 @@ public interface RunecraftConfig extends Config
"<br>Expect bugs if you use them together.</html></center>", "<br>Expect bugs if you use them together.</html></center>",
position = 2 position = 2
) )
default boolean Lavas() default boolean lavas()
{ {
return true; return false;
} }
@ConfigItem( @ConfigItem(

View File

@@ -319,7 +319,7 @@ public class RunecraftPlugin extends Plugin
private void updateConfig() private void updateConfig()
{ {
this.lavas = config.Lavas(); this.lavas = config.lavas();
this.essPouch = config.essPouch(); this.essPouch = config.essPouch();
this.hightlightDarkMage = config.hightlightDarkMage(); this.hightlightDarkMage = config.hightlightDarkMage();
this.degradingNotification = config.degradingNotification(); this.degradingNotification = config.degradingNotification();