Skip to content

Commit

Permalink
remove unnecessary generic type from GenericEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaktushose committed Dec 3, 2024
1 parent 581106a commit 35ecb7e
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public Button getButton(String button, String runtimeId) {
* @param selectMenu the id of the selectMenu
* @return a JDA {@link SelectMenu}
*/
@SuppressWarnings("unchecked")
public <T extends SelectMenu> T getSelectMenu(String selectMenu) {
if (!selectMenu.matches("[a-zA-Z]+\\.[a-zA-Z]+")) {
throw new IllegalArgumentException("Unknown Select Menu");
Expand Down Expand Up @@ -268,6 +269,7 @@ public <T extends SelectMenu> T getSelectMenu(String selectMenu) {
* InteractionRuntime}
* @return a JDA {@link SelectMenu}
*/
@SuppressWarnings("unchecked")
public <T extends SelectMenu> T getSelectMenu(String selectMenu, String runtimeId) {
if (!selectMenu.matches("[a-zA-Z]+\\.[a-zA-Z]+")) {
throw new IllegalArgumentException("Unknown Select Menu");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.kaktushose.jda.commands.dispatching.interactions;

import com.github.kaktushose.jda.commands.reflect.InteractionRegistry;
import com.github.kaktushose.jda.commands.reflect.interactions.GenericInteractionDefinition;
import com.github.kaktushose.jda.commands.reflect.interactions.components.ButtonDefinition;
import com.github.kaktushose.jda.commands.reflect.interactions.components.menus.GenericSelectMenuDefinition;
import net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent;
Expand All @@ -17,34 +16,22 @@
* @see com.github.kaktushose.jda.commands.dispatching.interactions.modals.ModalEvent ModalEvent
* @since 4.0.0
*/
public abstract class GenericEvent<T extends GenericInteractionDefinition> extends GenericInteractionCreateEvent {
public abstract class GenericEvent extends GenericInteractionCreateEvent {

protected final Context context;
private final InteractionRegistry interactionRegistry;
private final T definition;

/**
* Constructs a new GenericEvent.
*
* @param context the underlying {@link Context}
*/
@SuppressWarnings("unchecked")
protected GenericEvent(Context context, InteractionRegistry interactionRegistry) {
super(context.getEvent().getJDA(), context.getEvent().getResponseNumber(), context.getEvent().getInteraction());
definition = (T) context.getInteractionDefinition();
this.context = context;
this.interactionRegistry = interactionRegistry;
}

/**
* Get the interaction object which describes the component that is executed.
*
* @return the underlying interaction object
*/
public T getInteractionDefinition() {
return definition;
}

/**
* Get the {@link Context} object.
*
Expand Down Expand Up @@ -90,10 +77,11 @@ public Button getButton(String button) {
* {@code ExampleMenu.onSelectMenu}.
* </p>
*
* @param menu the id of the selectMenu
* @param menu the id of the selectMenu
* @return a JDA {@link SelectMenu}
*/
public <S extends SelectMenu> S getSelectMenu(String menu) {
@SuppressWarnings("unchecked")
public <T extends SelectMenu> T getSelectMenu(String menu) {
if (!menu.matches("[a-zA-Z]+\\.[a-zA-Z]+")) {
throw new IllegalArgumentException("Unknown Select Menu");
}
Expand All @@ -103,6 +91,6 @@ public <S extends SelectMenu> S getSelectMenu(String menu) {
.filter(it -> it.getDefinitionId().equals(sanitizedId))
.findFirst().orElseThrow(() -> new IllegalArgumentException("Unknown Select Menu"));

return (S) selectMenuDefinition.toSelectMenu(context.getRuntime().getRuntimeId(), true);
return (T) selectMenuDefinition.toSelectMenu(context.getRuntime().getRuntimeId(), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.github.kaktushose.jda.commands.dispatching.interactions.Context;
import com.github.kaktushose.jda.commands.dispatching.interactions.GenericEvent;
import com.github.kaktushose.jda.commands.reflect.InteractionRegistry;
import com.github.kaktushose.jda.commands.reflect.interactions.AutoCompleteDefinition;
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.Command;
import net.dv8tion.jda.api.interactions.commands.CommandAutoCompleteInteraction;
Expand All @@ -22,7 +21,7 @@
* @see GenericEvent
* @since 4.0.0
*/
public class AutoCompleteEvent extends GenericEvent<AutoCompleteDefinition> {
public class AutoCompleteEvent extends GenericEvent {

private final CommandAutoCompleteInteractionEvent event;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.github.kaktushose.jda.commands.dispatching.reply.ModalReplyable;
import com.github.kaktushose.jda.commands.dispatching.reply.ReplyContext;
import com.github.kaktushose.jda.commands.reflect.InteractionRegistry;
import com.github.kaktushose.jda.commands.reflect.interactions.commands.GenericCommandDefinition;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -16,7 +15,7 @@
* @see GenericEvent
* @since 4.0.0
*/
public class CommandEvent extends GenericEvent<GenericCommandDefinition> implements ModalReplyable {
public class CommandEvent extends GenericEvent implements ModalReplyable {

private final ReplyContext replyContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.github.kaktushose.jda.commands.dispatching.reply.ModalReplyable;
import com.github.kaktushose.jda.commands.dispatching.reply.ReplyContext;
import com.github.kaktushose.jda.commands.reflect.InteractionRegistry;
import com.github.kaktushose.jda.commands.reflect.interactions.components.GenericComponentDefinition;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
import org.jetbrains.annotations.NotNull;

Expand All @@ -19,7 +18,7 @@
* @see GenericEvent
* @since 4.0.0
*/
public class ComponentEvent extends GenericEvent<GenericComponentDefinition> implements ModalReplyable {
public class ComponentEvent extends GenericEvent implements ModalReplyable {

private final ReplyContext replyContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.github.kaktushose.jda.commands.dispatching.reply.ReplyContext;
import com.github.kaktushose.jda.commands.dispatching.reply.Replyable;
import com.github.kaktushose.jda.commands.reflect.InteractionRegistry;
import com.github.kaktushose.jda.commands.reflect.interactions.ModalDefinition;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -16,7 +15,7 @@
* @see GenericEvent
* @since 4.0.0
*/
public class ModalEvent extends GenericEvent<ModalDefinition> implements Replyable {
public class ModalEvent extends GenericEvent implements Replyable {

private final ReplyContext replyContext;

Expand Down

0 comments on commit 35ecb7e

Please sign in to comment.