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 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_";
@@ -698,10 +699,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]))
@@ -709,21 +714,61 @@ 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 " + actions[actionIdx])
.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("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("The default left and shift click options for '").append(Text.removeTags(composition.getName())).append("' ")
.append("have been reset.")
.build();
chatMessageManager.queue(QueuedMessage.builder()
.type(ChatMessageType.CONSOLE)
.runeLiteFormattedMessage(message)
.build());
log.debug("Unset object swap for {}", composition.getId());
unsetObjectSwapConfig(true, composition.getId());
unsetObjectSwapConfig(false, 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();
@@ -734,19 +779,8 @@ public class MenuEntrySwapperPlugin extends Plugin
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());
}
});
}
}
}
setObjectSwapConfig(shift, composition.getId(), menuIdx);
};
}
private Consumer<MenuEntry> walkHereConsumer(boolean shift, NPCComposition composition)
@@ -827,25 +861,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
@@ -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)
{
if (!shiftModifier())
@@ -1170,7 +1216,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);
@@ -1490,9 +1536,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;
@@ -1501,14 +1547,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)

View File

@@ -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);
}
});