Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2022-06-22 02:59:19 +02:00
2 changed files with 100 additions and 41 deletions

View File

@@ -103,6 +103,7 @@ public class MenuEntrySwapperPlugin extends Plugin
private static final String SHIFTCLICK_CONFIG_GROUP = "shiftclick"; private static final String SHIFTCLICK_CONFIG_GROUP = "shiftclick";
private static final String ITEM_KEY_PREFIX = "item_"; private static final String ITEM_KEY_PREFIX = "item_";
private static final String OBJECT_KEY_PREFIX = "object_"; 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_KEY_PREFIX = "npc_";
private static final String NPC_SHIFT_KEY_PREFIX = "npc_shift_"; private static final String NPC_SHIFT_KEY_PREFIX = "npc_shift_";
private static final String WORN_ITEM_KEY_PREFIX = "wornitem_"; private static final String WORN_ITEM_KEY_PREFIX = "wornitem_";
@@ -698,10 +699,14 @@ public class MenuEntrySwapperPlugin extends Plugin
final ObjectComposition composition = client.getObjectDefinition(entry.getIdentifier()); final ObjectComposition composition = client.getObjectDefinition(entry.getIdentifier());
final String[] actions = composition.getActions(); 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) : final MenuAction currentAction = swapConfig != null ? OBJECT_MENU_TYPES.get(swapConfig) :
defaultAction(composition); 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) for (int actionIdx = 0; actionIdx < OBJECT_MENU_TYPES.size(); ++actionIdx)
{ {
if (Strings.isNullOrEmpty(actions[actionIdx])) if (Strings.isNullOrEmpty(actions[actionIdx]))
@@ -709,22 +714,38 @@ public class MenuEntrySwapperPlugin extends Plugin
continue; continue;
} }
final int menuIdx = actionIdx;
final MenuAction menuAction = OBJECT_MENU_TYPES.get(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) client.createMenuEntry(idx)
.setOption("Swap " + actions[actionIdx]) .setOption("Reset swap")
.setTarget(entry.getTarget()) .setTarget(entry.getTarget())
.setType(MenuAction.RUNELITE) .setType(MenuAction.RUNELITE)
.onClick(e -> .onClick(e ->
{ {
final String message = new ChatMessageBuilder() final String message = new ChatMessageBuilder()
.append("The default left click option for '").append(Text.removeTags(composition.getName())).append("' ") .append("The default left and shift click options for '").append(Text.removeTags(composition.getName())).append("' ")
.append("has been set to '").append(actions[menuIdx]).append("'.") .append("have been reset.")
.build(); .build();
chatMessageManager.queue(QueuedMessage.builder() chatMessageManager.queue(QueuedMessage.builder()
@@ -732,23 +753,36 @@ public class MenuEntrySwapperPlugin extends Plugin
.runeLiteFormattedMessage(message) .runeLiteFormattedMessage(message)
.build()); .build());
log.debug("Set object swap for {} to {}", composition.getId(), menuAction); log.debug("Unset object swap for {}", composition.getId());
unsetObjectSwapConfig(true, composition.getId());
final MenuAction defaultAction = defaultAction(composition); unsetObjectSwapConfig(false, composition.getId());
if (defaultAction != menuAction)
{
setObjectSwapConfig(composition.getId(), menuIdx);
}
else
{
unsetObjectSwapConfig(composition.getId());
}
}); });
} }
} }
} }
} }
private Consumer<MenuEntry> 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<MenuEntry> walkHereConsumer(boolean shift, NPCComposition composition) private Consumer<MenuEntry> walkHereConsumer(boolean shift, NPCComposition composition)
{ {
return e -> return e ->
@@ -827,25 +861,16 @@ public class MenuEntrySwapperPlugin extends Plugin
} }
client.createMenuEntry(idx) client.createMenuEntry(idx)
.setOption("Swap " + actions[actionIdx]) .setOption("Swap left click " + actions[actionIdx])
.setTarget(entry.getTarget()) .setTarget(entry.getTarget())
.setType(MenuAction.RUNELITE) .setType(MenuAction.RUNELITE)
.onClick(e -> .onClick(npcConsumer(composition, actions, menuIdx, menuAction, false));
{
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();
chatMessageManager.queue(QueuedMessage.builder() client.createMenuEntry(idx)
.type(ChatMessageType.CONSOLE) .setOption("Swap shift click " + actions[actionIdx])
.runeLiteFormattedMessage(message) .setTarget(entry.getTarget())
.build()); .setType(MenuAction.RUNELITE)
.onClick(npcConsumer(composition, actions, menuIdx, menuAction, true));
log.debug("Set npc swap for {} to {}", composition.getId(), menuAction);
setNpcSwapConfig(false, composition.getId(), menuIdx);
});
} }
// Walk here swap // Walk here swap
@@ -889,6 +914,27 @@ public class MenuEntrySwapperPlugin extends Plugin
} }
} }
private Consumer<MenuEntry> 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) private void configureWornItems(MenuOpened event)
{ {
if (!shiftModifier()) if (!shiftModifier())
@@ -1170,7 +1216,7 @@ public class MenuEntrySwapperPlugin extends Plugin
objectId = objectComposition.getId(); objectId = objectComposition.getId();
} }
Integer customOption = getObjectSwapConfig(objectId); Integer customOption = getObjectSwapConfig(shiftModifier(), objectId);
if (customOption != null) if (customOption != null)
{ {
MenuAction swapAction = OBJECT_MENU_TYPES.get(customOption); MenuAction swapAction = OBJECT_MENU_TYPES.get(customOption);
@@ -1490,9 +1536,9 @@ public class MenuEntrySwapperPlugin extends Plugin
rebuildCustomizationMenus(); 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()) if (config == null || config.isEmpty())
{ {
return null; return null;
@@ -1501,14 +1547,14 @@ public class MenuEntrySwapperPlugin extends Plugin
return Integer.parseInt(config); 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) private static MenuAction defaultAction(ObjectComposition objectComposition)

View File

@@ -165,6 +165,19 @@ class PartyPanel extends PluginPanel
return; 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); party.changeParty(s);
} }
}); });