diff --git a/src/main/java/net/dv8tion/jda/api/components/Component.java b/src/main/java/net/dv8tion/jda/api/components/Component.java index ab0f8baaa7..a800266290 100644 --- a/src/main/java/net/dv8tion/jda/api/components/Component.java +++ b/src/main/java/net/dv8tion/jda/api/components/Component.java @@ -122,15 +122,15 @@ enum Type /** A text input field */ TEXT_INPUT(4, false, true), /** A select menu of users */ - USER_SELECT(5, true, false), + USER_SELECT(5, true, true), /** A select menu of roles */ - ROLE_SELECT(6, true, false), + ROLE_SELECT(6, true, true), /** A select menu of users and roles */ - MENTIONABLE_SELECT(7, true, false), + MENTIONABLE_SELECT(7, true, true), /** A select menu of channels */ - CHANNEL_SELECT(8, true, false), + CHANNEL_SELECT(8, true, true), SECTION(9, true, false), - TEXT_DISPLAY(10, true, false), + TEXT_DISPLAY(10, true, true), THUMBNAIL(11, true, false), MEDIA_GALLERY(12, true, false), FILE_DISPLAY(13, true, false), @@ -197,6 +197,16 @@ public boolean isModalCompatible() return modalCompatible; } + /** + * Whether this component is an {@link net.dv8tion.jda.api.components.selections.EntitySelectMenu EntitySelectMenu} + * + * @return {@code true} is this is a type of {@link net.dv8tion.jda.api.components.selections.EntitySelectMenu EntitySelectMenu} + */ + public boolean isEntitySelectMenu() + { + return this == MENTIONABLE_SELECT || this == CHANNEL_SELECT || this == USER_SELECT || this == ROLE_SELECT; + } + /** * Maps the provided type id to the respective enum instance. * diff --git a/src/main/java/net/dv8tion/jda/api/components/ModalTopLevelComponent.java b/src/main/java/net/dv8tion/jda/api/components/ModalTopLevelComponent.java index ee00ee1b74..e84984ec06 100644 --- a/src/main/java/net/dv8tion/jda/api/components/ModalTopLevelComponent.java +++ b/src/main/java/net/dv8tion/jda/api/components/ModalTopLevelComponent.java @@ -22,6 +22,7 @@ * Represents a component that can be added directly to a modal, this includes: * */ public interface ModalTopLevelComponent extends Component diff --git a/src/main/java/net/dv8tion/jda/api/components/ModalTopLevelComponentUnion.java b/src/main/java/net/dv8tion/jda/api/components/ModalTopLevelComponentUnion.java index 804b1328f7..dfbab7f463 100644 --- a/src/main/java/net/dv8tion/jda/api/components/ModalTopLevelComponentUnion.java +++ b/src/main/java/net/dv8tion/jda/api/components/ModalTopLevelComponentUnion.java @@ -17,6 +17,7 @@ package net.dv8tion.jda.api.components; import net.dv8tion.jda.api.components.label.Label; +import net.dv8tion.jda.api.components.textdisplay.TextDisplay; import javax.annotation.Nonnull; @@ -24,6 +25,7 @@ * Represents a union of {@link ModalTopLevelComponent ModalTopLevelComponents} that can be one of: * */ @@ -51,6 +53,28 @@ public interface ModalTopLevelComponentUnion extends ModalTopLevelComponent, ICo @Nonnull Label asLabel(); + /** + * Casts this union to a {@link TextDisplay}. + * This method exists for developer discoverability. + * + *

Note: This is effectively equivalent to using the cast operator: + *


+     * //These are the same!
+     * TextDisplay textDisplay = union.asTextDisplay();
+     * TextDisplay textDisplay2 = (TextDisplay) union;
+     * 
+ * + * You can use {@link #getType()} to see if the component is of type {@link net.dv8tion.jda.api.components.Component.Type#TEXT_DISPLAY TEXT_DISPLAY} to validate + * whether you can call this method in addition to normal instanceof checks: component instanceof TextDisplay + * + * @throws IllegalStateException + * If the component represented by this union is not actually a {@link TextDisplay}. + * + * @return The component as a {@link TextDisplay} + */ + @Nonnull + TextDisplay asTextDisplay(); + @Nonnull @Override ModalTopLevelComponentUnion withUniqueId(int uniqueId); diff --git a/src/main/java/net/dv8tion/jda/api/components/label/LabelChildComponent.java b/src/main/java/net/dv8tion/jda/api/components/label/LabelChildComponent.java index 6d174d6fe1..208b7cdd70 100644 --- a/src/main/java/net/dv8tion/jda/api/components/label/LabelChildComponent.java +++ b/src/main/java/net/dv8tion/jda/api/components/label/LabelChildComponent.java @@ -25,6 +25,7 @@ * */ public interface LabelChildComponent extends Component diff --git a/src/main/java/net/dv8tion/jda/api/components/label/LabelChildComponentUnion.java b/src/main/java/net/dv8tion/jda/api/components/label/LabelChildComponentUnion.java index c5945d92c7..677da873be 100644 --- a/src/main/java/net/dv8tion/jda/api/components/label/LabelChildComponentUnion.java +++ b/src/main/java/net/dv8tion/jda/api/components/label/LabelChildComponentUnion.java @@ -18,6 +18,7 @@ import net.dv8tion.jda.api.components.Component; import net.dv8tion.jda.api.components.IComponentUnion; +import net.dv8tion.jda.api.components.selections.EntitySelectMenu; import net.dv8tion.jda.api.components.selections.StringSelectMenu; import net.dv8tion.jda.api.components.textinput.TextInput; @@ -28,6 +29,7 @@ * */ public interface LabelChildComponentUnion extends LabelChildComponent, IComponentUnion @@ -76,6 +78,34 @@ public interface LabelChildComponentUnion extends LabelChildComponent, IComponen @Nonnull StringSelectMenu asStringSelectMenu(); + /** + * Casts this union to a {@link EntitySelectMenu}. + * This method exists for developer discoverability. + * + *

Note: This is effectively equivalent to using the cast operator: + *


+     * //These are the same!
+     * EntitySelectMenu menu = union.asEntitySelectMenu();
+     * EntitySelectMenu menu2 = (EntitySelectMenu) union;
+     * 
+ * + * You can use {@link #getType()} to see if the component is one of: + * + * to validate whether you can call this method in addition to normal instanceof checks: component instanceof EntitySelectMenu + * + * @throws IllegalStateException + * If the component represented by this union is not actually a {@link EntitySelectMenu}. + * + * @return The component as a {@link EntitySelectMenu} + */ + @Nonnull + EntitySelectMenu asEntitySelectMenu(); + @Nonnull @Override LabelChildComponentUnion withUniqueId(int uniqueId); diff --git a/src/main/java/net/dv8tion/jda/api/components/selections/EntitySelectMenu.java b/src/main/java/net/dv8tion/jda/api/components/selections/EntitySelectMenu.java index ab9aafdc3c..647481391c 100644 --- a/src/main/java/net/dv8tion/jda/api/components/selections/EntitySelectMenu.java +++ b/src/main/java/net/dv8tion/jda/api/components/selections/EntitySelectMenu.java @@ -655,7 +655,7 @@ public EntitySelectMenu build() Checks.check(minValues <= maxValues, "Min values cannot be greater than max values!"); EnumSet channelTypes = componentType == Type.CHANNEL_SELECT ? this.channelTypes : EnumSet.noneOf(ChannelType.class); List defaultValues = new ArrayList<>(this.defaultValues); - return new EntitySelectMenuImpl(customId, uniqueId, placeholder, minValues, maxValues, disabled, componentType, channelTypes, defaultValues); + return new EntitySelectMenuImpl(customId, uniqueId, placeholder, minValues, maxValues, disabled, componentType, channelTypes, defaultValues, required); } } } diff --git a/src/main/java/net/dv8tion/jda/api/components/selections/SelectMenu.java b/src/main/java/net/dv8tion/jda/api/components/selections/SelectMenu.java index c44dbf969e..e3b72681e2 100644 --- a/src/main/java/net/dv8tion/jda/api/components/selections/SelectMenu.java +++ b/src/main/java/net/dv8tion/jda/api/components/selections/SelectMenu.java @@ -21,6 +21,7 @@ import net.dv8tion.jda.api.components.ActionComponent; import net.dv8tion.jda.api.components.actionrow.ActionRow; import net.dv8tion.jda.api.components.actionrow.ActionRowChildComponent; +import net.dv8tion.jda.api.components.label.LabelChildComponent; import net.dv8tion.jda.api.interactions.components.selections.SelectMenuInteraction; import net.dv8tion.jda.internal.utils.Checks; @@ -45,7 +46,7 @@ * @see EntitySelectMenu * @see SelectMenuInteraction */ -public interface SelectMenu extends ActionComponent, ActionRowChildComponent +public interface SelectMenu extends ActionComponent, ActionRowChildComponent, LabelChildComponent { /** * The maximum length a select menu id can have @@ -110,6 +111,14 @@ default SelectMenu asEnabled() */ int getMaxValues(); + /** + * Whether the user must populate this select menu in Modals, or {@code null} if not set. + * + * @return Whether this menu must be populated, or null + */ + @Nullable + Boolean isRequired(); + /** * Creates a new preconfigured {@link SelectMenu.Builder} with the same settings used for this select menu. *
This can be useful to create an updated version of this menu without needing to rebuild it from scratch. @@ -136,6 +145,7 @@ abstract class Builder> protected String placeholder; protected int minValues = 1, maxValues = 1; protected boolean disabled = false; + protected Boolean required = null; protected Builder(@Nonnull String customId) { @@ -311,6 +321,24 @@ public B setDisabled(boolean disabled) return (B) this; } + /** + * Configure whether the user must populate this select menu if inside a Modal. + *
This defaults to {@code true} in Modals when unset. + * + *

This only has an effect in Modals! + * + * @param required + * Whether this menu is required + * + * @return The same builder instance for chaining + */ + @Nonnull + public B setRequired(@Nullable Boolean required) + { + this.required = required; + return (B) this; + } + /** * The custom id used to identify the select menu. * @@ -390,6 +418,17 @@ public boolean isDisabled() return disabled; } + /** + * Whether the user must populate this select menu in Modals, or {@code null} if not set. + * + * @return Whether this menu must be populated, or null + */ + @Nullable + public Boolean isRequired() + { + return required; + } + /** * Creates a new {@link SelectMenu} instance if all requirements are satisfied. * diff --git a/src/main/java/net/dv8tion/jda/api/components/selections/StringSelectMenu.java b/src/main/java/net/dv8tion/jda/api/components/selections/StringSelectMenu.java index 3c8deb7805..acfdb9c15e 100644 --- a/src/main/java/net/dv8tion/jda/api/components/selections/StringSelectMenu.java +++ b/src/main/java/net/dv8tion/jda/api/components/selections/StringSelectMenu.java @@ -18,7 +18,6 @@ import net.dv8tion.jda.api.components.ActionComponent; import net.dv8tion.jda.api.components.actionrow.ActionRow; -import net.dv8tion.jda.api.components.label.LabelChildComponent; import net.dv8tion.jda.api.entities.emoji.Emoji; import net.dv8tion.jda.api.interactions.components.selections.SelectMenuInteraction; import net.dv8tion.jda.api.interactions.components.selections.StringSelectInteraction; @@ -63,7 +62,7 @@ * @see StringSelectInteraction * @see EntitySelectMenu */ -public interface StringSelectMenu extends SelectMenu, LabelChildComponent +public interface StringSelectMenu extends SelectMenu { @Nonnull @Override @@ -100,14 +99,6 @@ default StringSelectMenu withDisabled(boolean disabled) @Nonnull List getOptions(); - /** - * Whether the user must populate this select menu in Modals, or {@code null} if not set. - * - * @return Whether this menu must be populated, or null - */ - @Nullable - Boolean isRequired(); - /** * Creates a new preconfigured {@link Builder} with the same settings used for this select menu. *
This can be useful to create an updated version of this menu without needing to rebuild it from scratch. @@ -153,7 +144,6 @@ static Builder create(@Nonnull String customId) class Builder extends SelectMenu.Builder { private final List options = new ArrayList<>(); - private Boolean required = null; protected Builder(@Nonnull String customId) { @@ -306,17 +296,6 @@ public List getOptions() return options; } - /** - * Whether the user must populate this select menu in Modals, or {@code null} if not set. - * - * @return Whether this menu must be populated, or null - */ - @Nullable - public Boolean isRequired() - { - return required; - } - /** * Configures which of the currently applied {@link #getOptions() options} should be selected by default. * @@ -395,24 +374,6 @@ public Builder setDefaultOptions(@Nonnull SelectOption... values) return setDefaultOptions(Arrays.asList(values)); } - /** - * Configure whether the user must populate this select menu if inside a Modal. - *
This defaults to {@code true} in Modals when unset. - * - *

This only has an effect in Modals! - * - * @param required - * Whether this menu is required - * - * @return The same builder instance for chaining - */ - @Nonnull - public Builder setRequired(@Nullable Boolean required) - { - this.required = required; - return this; - } - /** * Creates a new {@link StringSelectMenu} instance if all requirements are satisfied. *
A select menu may not have more than {@value #OPTIONS_MAX_AMOUNT} options at once. diff --git a/src/main/java/net/dv8tion/jda/api/components/textdisplay/TextDisplay.java b/src/main/java/net/dv8tion/jda/api/components/textdisplay/TextDisplay.java index 79db4a319a..cd7520b3bf 100644 --- a/src/main/java/net/dv8tion/jda/api/components/textdisplay/TextDisplay.java +++ b/src/main/java/net/dv8tion/jda/api/components/textdisplay/TextDisplay.java @@ -18,6 +18,7 @@ import net.dv8tion.jda.api.components.Component; import net.dv8tion.jda.api.components.MessageTopLevelComponent; +import net.dv8tion.jda.api.components.ModalTopLevelComponent; import net.dv8tion.jda.api.components.container.ContainerChildComponent; import net.dv8tion.jda.api.components.section.SectionContentComponent; import net.dv8tion.jda.api.entities.Message; @@ -37,7 +38,9 @@ * *

Requirements: {@linkplain MessageRequest#useComponentsV2() Components V2} needs to be enabled! */ -public interface TextDisplay extends Component, MessageTopLevelComponent, ContainerChildComponent, SectionContentComponent +public interface TextDisplay + extends Component, MessageTopLevelComponent, ModalTopLevelComponent, + ContainerChildComponent, SectionContentComponent { /** * Constructs a new {@link TextDisplay} from the given content. diff --git a/src/main/java/net/dv8tion/jda/api/interactions/modals/ModalMapping.java b/src/main/java/net/dv8tion/jda/api/interactions/modals/ModalMapping.java index d92f395a9c..a3793d7543 100644 --- a/src/main/java/net/dv8tion/jda/api/interactions/modals/ModalMapping.java +++ b/src/main/java/net/dv8tion/jda/api/interactions/modals/ModalMapping.java @@ -19,9 +19,12 @@ import net.dv8tion.jda.annotations.ForRemoval; import net.dv8tion.jda.annotations.ReplaceWith; import net.dv8tion.jda.api.components.Component; +import net.dv8tion.jda.api.entities.Mentions; import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.utils.data.DataArray; import net.dv8tion.jda.api.utils.data.DataObject; +import net.dv8tion.jda.internal.entities.SelectMenuMentions; +import net.dv8tion.jda.internal.interactions.InteractionImpl; import net.dv8tion.jda.internal.utils.EntityString; import net.dv8tion.jda.internal.utils.Helpers; @@ -37,16 +40,20 @@ */ public class ModalMapping { + private final InteractionImpl interaction; private final String customId; private final int uniqueId; + private final DataObject resolved; private final DataObject value; private final Component.Type type; - public ModalMapping(DataObject object) + public ModalMapping(InteractionImpl interaction, DataObject resolved, DataObject object) { + this.interaction = interaction; this.uniqueId = object.getInt("id"); this.customId = object.getString("custom_id"); this.type = Component.Type.fromKey(object.getInt("type")); + this.resolved = resolved; this.value = object; } @@ -123,8 +130,18 @@ public String getAsString() /** * The String list representation of this component. * - *

For {@link net.dv8tion.jda.api.components.selections.StringSelectMenu StringSelectMenus}, this returns - * the values chosen by the User. + *

Return values include: + *

    + *
  • + * For {@link net.dv8tion.jda.api.components.selections.StringSelectMenu StringSelectMenus}, + * this returns the values chosen by the User. + *
  • + *
  • + * For {@link net.dv8tion.jda.api.components.selections.EntitySelectMenu EntitySelectMenus}, + * this returns the entity IDs chosen by the User. + *
  • + *
+ *

* *

Use {@link #getType()} to check if this method can be used safely! * @@ -136,7 +153,7 @@ public String getAsString() @Nonnull public List getAsStringList() { - if (type != Component.Type.STRING_SELECT) + if (type != Component.Type.STRING_SELECT && !type.isEntitySelectMenu()) typeError("List"); return value.getArray("values") @@ -144,6 +161,50 @@ public List getAsStringList() .collect(Helpers.toUnmodifiableList()); } + /** + * Returns this component's value as a list of Longs. + * + *

This is available if the component was an {@link net.dv8tion.jda.api.components.selections.EntitySelectMenu EntitySelectMenu}. + * + *

You can use {@link #getType()} and {@link Component.Type#isEntitySelectMenu()} to check if this method can be used safely. + * + * @throws IllegalStateException + * If this ModalMapping cannot be represented as such + * + * @return This component's value as a list of Longs. + */ + @Nonnull + public List getAsLongList() + { + if (!type.isEntitySelectMenu()) + typeError("List"); + + return value.getArray("values") + .stream(DataArray::getLong) + .collect(Helpers.toUnmodifiableList()); + } + + /** + * Returns this component's value as a {@link Mentions} object. + * + *

This is available if the component was an {@link net.dv8tion.jda.api.components.selections.EntitySelectMenu EntitySelectMenu}. + * + *

You can use {@link #getType()} and {@link Component.Type#isEntitySelectMenu()} to check if this method can be used safely. + * + * @throws IllegalStateException + * If this ModalMapping cannot be represented as such + * + * @return This component's value as a {@link Mentions} object. + */ + @Nonnull + public Mentions getAsMentions() + { + if (!type.isEntitySelectMenu()) + typeError("Mentions"); + + return new SelectMenuMentions(interaction.getJDA(), interaction.getInteractionEntityBuilder(), interaction.getGuild(), resolved, value.getArray("values")); + } + @Override public String toString() { diff --git a/src/main/java/net/dv8tion/jda/internal/components/selections/EntitySelectMenuImpl.java b/src/main/java/net/dv8tion/jda/internal/components/selections/EntitySelectMenuImpl.java index a6bd5d94be..4663f8b5b0 100644 --- a/src/main/java/net/dv8tion/jda/internal/components/selections/EntitySelectMenuImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/components/selections/EntitySelectMenuImpl.java @@ -17,6 +17,7 @@ package net.dv8tion.jda.internal.components.selections; import net.dv8tion.jda.api.components.Component; +import net.dv8tion.jda.api.components.label.LabelChildComponentUnion; import net.dv8tion.jda.api.components.selections.EntitySelectMenu; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.utils.data.DataArray; @@ -30,7 +31,7 @@ import java.util.Objects; import java.util.stream.Collectors; -public class EntitySelectMenuImpl extends SelectMenuImpl implements EntitySelectMenu +public class EntitySelectMenuImpl extends SelectMenuImpl implements EntitySelectMenu, LabelChildComponentUnion { protected final Component.Type type; protected final EnumSet channelTypes; @@ -50,9 +51,9 @@ public EntitySelectMenuImpl(DataObject data) ).orElse(Collections.emptyList()); } - public EntitySelectMenuImpl(String id, int uniqueId, String placeholder, int minValues, int maxValues, boolean disabled, Type type, EnumSet channelTypes, List defaultValues) + public EntitySelectMenuImpl(String id, int uniqueId, String placeholder, int minValues, int maxValues, boolean disabled, Type type, EnumSet channelTypes, List defaultValues, Boolean required) { - super(id, uniqueId, placeholder, minValues, maxValues, disabled); + super(id, uniqueId, placeholder, minValues, maxValues, disabled, required); this.type = type; this.channelTypes = channelTypes; this.defaultValues = defaultValues; diff --git a/src/main/java/net/dv8tion/jda/internal/components/selections/SelectMenuImpl.java b/src/main/java/net/dv8tion/jda/internal/components/selections/SelectMenuImpl.java index ed5a24347d..7d5f2d855d 100644 --- a/src/main/java/net/dv8tion/jda/internal/components/selections/SelectMenuImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/components/selections/SelectMenuImpl.java @@ -33,6 +33,7 @@ public abstract class SelectMenuImpl protected final int uniqueId; protected final int minValues, maxValues; protected final boolean disabled; + protected final Boolean required; public SelectMenuImpl(DataObject data) { @@ -42,11 +43,12 @@ public SelectMenuImpl(DataObject data) data.getString("placeholder", null), data.getInt("min_values", 1), data.getInt("max_values", 1), - data.getBoolean("disabled") + data.getBoolean("disabled"), + data.isNull("required") ? null : data.getBoolean("required") ); } - public SelectMenuImpl(String id, int uniqueId, String placeholder, int minValues, int maxValues, boolean disabled) + public SelectMenuImpl(String id, int uniqueId, String placeholder, int minValues, int maxValues, boolean disabled, Boolean required) { this.id = id; this.uniqueId = uniqueId; @@ -54,6 +56,7 @@ public SelectMenuImpl(String id, int uniqueId, String placeholder, int minValues this.minValues = minValues; this.maxValues = maxValues; this.disabled = disabled; + this.required = required; } @Nonnull @@ -98,6 +101,12 @@ public boolean isDisabled() return disabled; } + @Override + public Boolean isRequired() + { + return required; + } + @Nonnull @Override public DataObject toData() @@ -111,6 +120,8 @@ public DataObject toData() data.put("disabled", disabled); if (placeholder != null) data.put("placeholder", placeholder); + if (required != null) + data.put("required", required); return data; } diff --git a/src/main/java/net/dv8tion/jda/internal/components/selections/StringSelectMenuImpl.java b/src/main/java/net/dv8tion/jda/internal/components/selections/StringSelectMenuImpl.java index 6147ef2e12..a547da02fd 100644 --- a/src/main/java/net/dv8tion/jda/internal/components/selections/StringSelectMenuImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/components/selections/StringSelectMenuImpl.java @@ -31,20 +31,17 @@ public class StringSelectMenuImpl extends SelectMenuImpl implements StringSelectMenu, LabelChildComponentUnion { private final List options; - private final Boolean required; public StringSelectMenuImpl(DataObject data) { super(data); this.options = parseOptions(data.getArray("options")); - this.required = (Boolean) data.opt("required").orElse(null); } public StringSelectMenuImpl(String id, int uniqueId, String placeholder, int minValues, int maxValues, boolean disabled, List options, Boolean required) { - super(id, uniqueId, placeholder, minValues, maxValues, disabled); + super(id, uniqueId, placeholder, minValues, maxValues, disabled, required); this.options = options; - this.required = required; } private static List parseOptions(DataArray array) @@ -77,24 +74,13 @@ public List getOptions() return Collections.unmodifiableList(options); } - @Override - public Boolean isRequired() - { - return required; - } - @Nonnull @Override public DataObject toData() { - DataObject obj = super.toData() + return super.toData() .put("type", Type.STRING_SELECT.getKey()) .put("options", DataArray.fromCollection(options)); - - if (required != null) - obj.put("required", required); - - return obj; } @Override diff --git a/src/main/java/net/dv8tion/jda/internal/components/textdisplay/TextDisplayImpl.java b/src/main/java/net/dv8tion/jda/internal/components/textdisplay/TextDisplayImpl.java index ffcf17e98b..eeba3d9cb7 100644 --- a/src/main/java/net/dv8tion/jda/internal/components/textdisplay/TextDisplayImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/components/textdisplay/TextDisplayImpl.java @@ -17,6 +17,7 @@ package net.dv8tion.jda.internal.components.textdisplay; import net.dv8tion.jda.api.components.MessageTopLevelComponentUnion; +import net.dv8tion.jda.api.components.ModalTopLevelComponentUnion; import net.dv8tion.jda.api.components.container.ContainerChildComponentUnion; import net.dv8tion.jda.api.components.section.SectionContentComponentUnion; import net.dv8tion.jda.api.components.textdisplay.TextDisplay; @@ -30,7 +31,8 @@ public class TextDisplayImpl extends AbstractComponentImpl - implements TextDisplay, MessageTopLevelComponentUnion, ContainerChildComponentUnion, SectionContentComponentUnion + implements TextDisplay, MessageTopLevelComponentUnion, ModalTopLevelComponentUnion, + ContainerChildComponentUnion, SectionContentComponentUnion { private final int uniqueId; private final String content; diff --git a/src/main/java/net/dv8tion/jda/internal/interactions/InteractionImpl.java b/src/main/java/net/dv8tion/jda/internal/interactions/InteractionImpl.java index 44ededa531..5cf52b2289 100644 --- a/src/main/java/net/dv8tion/jda/internal/interactions/InteractionImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/interactions/InteractionImpl.java @@ -16,7 +16,6 @@ package net.dv8tion.jda.internal.interactions; -import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Entitlement; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; @@ -234,8 +233,14 @@ public List getEntitlements() @Nonnull @Override - public JDA getJDA() + public JDAImpl getJDA() { return api; } + + @Nonnull + public InteractionEntityBuilder getInteractionEntityBuilder() + { + return interactionEntityBuilder; + } } diff --git a/src/main/java/net/dv8tion/jda/internal/interactions/modal/ModalInteractionImpl.java b/src/main/java/net/dv8tion/jda/internal/interactions/modal/ModalInteractionImpl.java index c76437ad4f..22bcc26dc9 100644 --- a/src/main/java/net/dv8tion/jda/internal/interactions/modal/ModalInteractionImpl.java +++ b/src/main/java/net/dv8tion/jda/internal/interactions/modal/ModalInteractionImpl.java @@ -47,9 +47,10 @@ public ModalInteractionImpl(JDAImpl api, DataObject object) DataObject data = object.getObject("data"); this.modalId = data.getString("custom_id"); + DataObject resolved = data.optObject("resolved").orElseGet(DataObject::empty); this.mappings = data.optArray("components").orElseGet(DataArray::empty) .stream(DataArray::getObject) - .map(ModalInteractionImpl::getMapping) + .map(component -> getMapping(component, resolved)) .filter(Objects::nonNull) .collect(Helpers.toUnmodifiableList()); @@ -58,12 +59,12 @@ public ModalInteractionImpl(JDAImpl api, DataObject object) .orElse(null); } - private static ModalMapping getMapping(DataObject component) + private ModalMapping getMapping(DataObject component, DataObject resolved) { Component.Type type = Component.Type.fromKey(component.getInt("type")); if (type == Component.Type.LABEL) - return new ModalMapping(component.getObject("component")); + return new ModalMapping(this, resolved, component.getObject("component")); return null; }