refactor(command): move both choices vars to different annotation
All checks were successful
github-mirror / push-github (push) Successful in 1m36s
Build / Gradle-Build (push) Successful in 31s
Publish / Gradle-Publish (push) Successful in 36s
Test / Gradle-Test (push) Successful in 47s

This commit is contained in:
2025-03-18 09:33:53 +01:00
parent 2e5979e6e4
commit caa2ee7089
5 changed files with 19 additions and 8 deletions

View File

@@ -6,6 +6,7 @@ import java.util.Set;
import org.slf4j.Logger;
import net.tomatentum.marinara.interaction.commands.annotation.CommandChoices;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption.PlaceHolderEnum;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOptionChoice;
@@ -18,10 +19,11 @@ import net.tomatentum.marinara.util.LoggerUtil;
public class SlashCommandDefinition {
public static SlashCommandOptionChoice[] getActualChoices(SlashCommandOption option) {
SlashCommandOptionChoice[] choices = option.choices();
if (choices.length <= 0 && !option.choiceEnum().equals(PlaceHolderEnum.class))
choices = EnumChoices.of(option.choiceEnum()).choices();
return choices;
CommandChoices choices = option.choices();
SlashCommandOptionChoice[] actualChoices = choices.value();
if (choices.value().length <= 0 && !choices.cenum().equals(PlaceHolderEnum.class))
actualChoices = EnumChoices.of(choices.cenum()).choices();
return actualChoices;
}
private Set<InteractionIdentifier> entries;

View File

@@ -0,0 +1,8 @@
package net.tomatentum.marinara.interaction.commands.annotation;
import net.tomatentum.marinara.interaction.commands.annotation.SlashCommandOption.PlaceHolderEnum;
public @interface CommandChoices {
public SlashCommandOptionChoice[] value() default {};
public Class<? extends Enum<?>> cenum() default PlaceHolderEnum.class;
}

View File

@@ -15,8 +15,7 @@ public @interface SlashCommandOption {
public SlashCommandOptionType type() default SlashCommandOptionType.STRING;
public boolean required() default false;
public boolean autocomplete() default false;
public SlashCommandOptionChoice[] choices() default {};
public Class<? extends Enum<?>> choiceEnum() default PlaceHolderEnum.class;
public CommandChoices choices() default @CommandChoices;
public static enum PlaceHolderEnum {