From 9d69c84653fee0eabe7c7686c3124be8d4b0bb56 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 21 Jun 2022 13:10:27 -0400 Subject: [PATCH 1/3] menu swapper: add custom shift-click npc swap --- .../MenuEntrySwapperPlugin.java | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java index b7b3488d1c..0e0142d384 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java @@ -817,25 +817,16 @@ public class MenuEntrySwapperPlugin extends Plugin } client.createMenuEntry(idx) - .setOption("Swap " + actions[actionIdx]) + .setOption("Swap left click " + actions[actionIdx]) .setTarget(entry.getTarget()) .setType(MenuAction.RUNELITE) - .onClick(e -> - { - final String message = new ChatMessageBuilder() - .append("The default left click option for '").append(Text.removeTags(composition.getName())).append("' ") - .append("has been set to '").append(actions[menuIdx]).append("'.") - .build(); + .onClick(npcConsumer(composition, actions, menuIdx, menuAction, false)); - chatMessageManager.queue(QueuedMessage.builder() - .type(ChatMessageType.CONSOLE) - .runeLiteFormattedMessage(message) - .build()); - - log.debug("Set npc swap for {} to {}", composition.getId(), menuAction); - - setNpcSwapConfig(false, composition.getId(), menuIdx); - }); + client.createMenuEntry(idx) + .setOption("Swap shift click " + actions[actionIdx]) + .setTarget(entry.getTarget()) + .setType(MenuAction.RUNELITE) + .onClick(npcConsumer(composition, actions, menuIdx, menuAction, true)); } // Walk here swap @@ -879,6 +870,27 @@ public class MenuEntrySwapperPlugin extends Plugin } } + private Consumer npcConsumer(NPCComposition composition, String[] actions, int menuIdx, + MenuAction menuAction, boolean shift) + { + return e -> + { + final String message = new ChatMessageBuilder() + .append("The default ").append(shift ? "shift" : "left").append(" click option for '").append(Text.removeTags(composition.getName())).append("' ") + .append("has been set to '").append(actions[menuIdx]).append("'.") + .build(); + + chatMessageManager.queue(QueuedMessage.builder() + .type(ChatMessageType.CONSOLE) + .runeLiteFormattedMessage(message) + .build()); + + log.debug("Set npc {} swap for {} to {}", shift ? "shift" : "left", composition.getId(), menuAction); + + setNpcSwapConfig(shift, composition.getId(), menuIdx); + }; + } + private void configureWornItems(MenuOpened event) { if (!shiftModifier()) From a9d89f058b73f03bbf4b60b9cbfb85db383d716f Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 21 Jun 2022 15:19:19 -0400 Subject: [PATCH 2/3] menu swapper: add custom shift-click object swap --- .../MenuEntrySwapperPlugin.java | 84 +++++++++++++------ 1 file changed, 59 insertions(+), 25 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java index 0e0142d384..e970bf20eb 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java @@ -102,6 +102,7 @@ public class MenuEntrySwapperPlugin extends Plugin private static final String SHIFTCLICK_CONFIG_GROUP = "shiftclick"; private static final String ITEM_KEY_PREFIX = "item_"; private static final String OBJECT_KEY_PREFIX = "object_"; + private static final String OBJECT_SHIFT_KEY_PREFIX = "object_shift_"; private static final String NPC_KEY_PREFIX = "npc_"; private static final String NPC_SHIFT_KEY_PREFIX = "npc_shift_"; private static final String WORN_ITEM_KEY_PREFIX = "wornitem_"; @@ -688,10 +689,14 @@ public class MenuEntrySwapperPlugin extends Plugin final ObjectComposition composition = client.getObjectDefinition(entry.getIdentifier()); final String[] actions = composition.getActions(); - final Integer swapConfig = getObjectSwapConfig(composition.getId()); + final Integer swapConfig = getObjectSwapConfig(false, composition.getId()); final MenuAction currentAction = swapConfig != null ? OBJECT_MENU_TYPES.get(swapConfig) : defaultAction(composition); + final Integer shiftSwapConfig = getObjectSwapConfig(true, composition.getId()); + final MenuAction currentShiftAction = shiftSwapConfig != null ? OBJECT_MENU_TYPES.get(shiftSwapConfig) : + defaultAction(composition); + for (int actionIdx = 0; actionIdx < OBJECT_MENU_TYPES.size(); ++actionIdx) { if (Strings.isNullOrEmpty(actions[actionIdx])) @@ -699,22 +704,38 @@ public class MenuEntrySwapperPlugin extends Plugin continue; } - final int menuIdx = actionIdx; final MenuAction menuAction = OBJECT_MENU_TYPES.get(actionIdx); - if (currentAction == menuAction) + if (menuAction != currentAction) { - continue; + client.createMenuEntry(idx) + .setOption("Swap left click " + actions[actionIdx]) + .setTarget(entry.getTarget()) + .setType(MenuAction.RUNELITE) + .onClick(objectConsumer(composition, actions, actionIdx, menuAction, false)); } + if (menuAction != currentShiftAction && menuAction != currentAction) + { + client.createMenuEntry(idx) + .setOption("Swap shift click " + actions[actionIdx]) + .setTarget(entry.getTarget()) + .setType(MenuAction.RUNELITE) + .onClick(objectConsumer(composition, actions, actionIdx, menuAction, true)); + } + } + + if (swapConfig != null || shiftSwapConfig != null) + { + // Reset client.createMenuEntry(idx) - .setOption("Swap " + actions[actionIdx]) + .setOption("Reset swap") .setTarget(entry.getTarget()) .setType(MenuAction.RUNELITE) .onClick(e -> { final String message = new ChatMessageBuilder() - .append("The default left click option for '").append(Text.removeTags(composition.getName())).append("' ") - .append("has been set to '").append(actions[menuIdx]).append("'.") + .append("The default left and shift click options for '").append(Text.removeTags(composition.getName())).append("' ") + .append("have been reset.") .build(); chatMessageManager.queue(QueuedMessage.builder() @@ -722,23 +743,36 @@ public class MenuEntrySwapperPlugin extends Plugin .runeLiteFormattedMessage(message) .build()); - log.debug("Set object swap for {} to {}", composition.getId(), menuAction); - - final MenuAction defaultAction = defaultAction(composition); - if (defaultAction != menuAction) - { - setObjectSwapConfig(composition.getId(), menuIdx); - } - else - { - unsetObjectSwapConfig(composition.getId()); - } + log.debug("Unset object swap for {}", composition.getId()); + unsetObjectSwapConfig(true, composition.getId()); + unsetObjectSwapConfig(false, composition.getId()); }); } } } } + private Consumer objectConsumer(ObjectComposition composition, String[] actions, int menuIdx, + MenuAction menuAction, boolean shift) + { + return e -> + { + final String message = new ChatMessageBuilder() + .append("The default ").append(shift ? "shift" : "left").append(" click option for '").append(Text.removeTags(composition.getName())).append("' ") + .append("has been set to '").append(actions[menuIdx]).append("'.") + .build(); + + chatMessageManager.queue(QueuedMessage.builder() + .type(ChatMessageType.CONSOLE) + .runeLiteFormattedMessage(message) + .build()); + + log.debug("Set object swap for {} to {}", composition.getId(), menuAction); + + setObjectSwapConfig(shift, composition.getId(), menuIdx); + }; + } + private Consumer walkHereConsumer(boolean shift, NPCComposition composition) { return e -> @@ -1172,7 +1206,7 @@ public class MenuEntrySwapperPlugin extends Plugin objectId = objectComposition.getId(); } - Integer customOption = getObjectSwapConfig(objectId); + Integer customOption = getObjectSwapConfig(shiftModifier(), objectId); if (customOption != null) { MenuAction swapAction = OBJECT_MENU_TYPES.get(customOption); @@ -1492,9 +1526,9 @@ public class MenuEntrySwapperPlugin extends Plugin rebuildCustomizationMenus(); } - private Integer getObjectSwapConfig(int objectId) + private Integer getObjectSwapConfig(boolean shift, int objectId) { - String config = configManager.getConfiguration(MenuEntrySwapperConfig.GROUP, OBJECT_KEY_PREFIX + objectId); + String config = configManager.getConfiguration(MenuEntrySwapperConfig.GROUP, (shift ? OBJECT_SHIFT_KEY_PREFIX : OBJECT_KEY_PREFIX) + objectId); if (config == null || config.isEmpty()) { return null; @@ -1503,14 +1537,14 @@ public class MenuEntrySwapperPlugin extends Plugin return Integer.parseInt(config); } - private void setObjectSwapConfig(int objectId, int index) + private void setObjectSwapConfig(boolean shift, int objectId, int index) { - configManager.setConfiguration(MenuEntrySwapperConfig.GROUP, OBJECT_KEY_PREFIX + objectId, index); + configManager.setConfiguration(MenuEntrySwapperConfig.GROUP, (shift ? OBJECT_SHIFT_KEY_PREFIX : OBJECT_KEY_PREFIX) + objectId, index); } - private void unsetObjectSwapConfig(int objectId) + private void unsetObjectSwapConfig(boolean shift, int objectId) { - configManager.unsetConfiguration(MenuEntrySwapperConfig.GROUP, OBJECT_KEY_PREFIX + objectId); + configManager.unsetConfiguration(MenuEntrySwapperConfig.GROUP, (shift ? OBJECT_SHIFT_KEY_PREFIX : OBJECT_KEY_PREFIX) + objectId); } private static MenuAction defaultAction(ObjectComposition objectComposition) From 73116f35f39304f61e8870d6b29ab00f9a8319fe Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 21 Jun 2022 19:05:58 -0400 Subject: [PATCH 3/3] party: sanitize passphrase inputs --- .../runelite/client/plugins/party/PartyPanel.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/party/PartyPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/party/PartyPanel.java index 5b110e33fd..b199d7141f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/party/PartyPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/party/PartyPanel.java @@ -165,6 +165,19 @@ class PartyPanel extends PluginPanel return; } + for (int i = 0; i < s.length(); ++i) + { + char ch = s.charAt(i); + if (!Character.isLetter(ch) && !Character.isDigit(ch) && ch != '-') + { + JOptionPane.showMessageDialog(joinPartyButton, + "Party passphrase must be a combination of alphanumeric or hyphen characters.", + "Invalid party passphrase", + JOptionPane.ERROR_MESSAGE); + return; + } + } + party.changeParty(s); } });