rework class invariant checks and cast issues
This commit is contained in:
parent
3d5201329b
commit
7888819f6e
@ -12,7 +12,7 @@ import net.tomatentum.marinara.interaction.commands.annotation.SubCommandGroup;
|
|||||||
public class SlashCommandDefinition {
|
public class SlashCommandDefinition {
|
||||||
private List<ExecutableSlashCommandDefinition> executableDefinitons;
|
private List<ExecutableSlashCommandDefinition> executableDefinitons;
|
||||||
private SlashCommand slashCommand;
|
private SlashCommand slashCommand;
|
||||||
private boolean isRootCommand = false;
|
private boolean isRootCommand;
|
||||||
|
|
||||||
public SlashCommandDefinition(SlashCommand applicationCommand) {
|
public SlashCommandDefinition(SlashCommand applicationCommand) {
|
||||||
this.executableDefinitons = new ArrayList<>();
|
this.executableDefinitons = new ArrayList<>();
|
||||||
@ -23,17 +23,15 @@ public class SlashCommandDefinition {
|
|||||||
if (def.applicationCommand() != null) {
|
if (def.applicationCommand() != null) {
|
||||||
if (slashCommand == null)
|
if (slashCommand == null)
|
||||||
this.slashCommand = def.applicationCommand();
|
this.slashCommand = def.applicationCommand();
|
||||||
if (!this.slashCommand.equals(def.applicationCommand()))
|
if (!this.slashCommand.name().equals(def.applicationCommand().name()))
|
||||||
throw new IllegalArgumentException(def + ": has a non matching Application Command description. Please edit it to equal all other descriptions or remove it to use other definitions descriptions");
|
throw new IllegalArgumentException(def + ": has a non matching Application Command description. Please edit it to equal all other descriptions or remove it to use other definitions descriptions");
|
||||||
}
|
}
|
||||||
if (isRootCommand) {
|
|
||||||
if (!def.isRootCommand())
|
if (executableDefinitons.isEmpty())
|
||||||
throw new IllegalArgumentException(def + ": cannot have subcommands and rootcommand definitions together");
|
this.isRootCommand = def.isRootCommand();
|
||||||
long subCommandAmount = executableDefinitons.stream()
|
|
||||||
.filter((x) -> !x.isRootCommand())
|
if ((isRootCommand && !def.isRootCommand()) || (!isRootCommand && def.isRootCommand())) {
|
||||||
.count();
|
throw new IllegalArgumentException(def + ": cannot have subcommands and rootcommand definitions together");
|
||||||
if (subCommandAmount > 0)
|
|
||||||
throw new IllegalArgumentException(def + ": cannot have subcommands and rootcommand definitions together");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
executableDefinitons.add(def);
|
executableDefinitons.add(def);
|
||||||
@ -53,7 +51,7 @@ public class SlashCommandDefinition {
|
|||||||
subCommandGroupMap.put(x.name(), x);
|
subCommandGroupMap.put(x.name(), x);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (SubCommandGroup[]) subCommandGroupMap.values().toArray();
|
return subCommandGroupMap.values().toArray(new SubCommandGroup[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SubCommand[] getSubCommands(String groupName) {
|
public SubCommand[] getSubCommands(String groupName) {
|
||||||
@ -76,7 +74,7 @@ public class SlashCommandDefinition {
|
|||||||
subCommandMap.put(x.name(), x);
|
subCommandMap.put(x.name(), x);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (SubCommand[]) subCommandMap.values().toArray();
|
return subCommandMap.values().toArray(new SubCommand[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SlashCommand getFullSlashCommand() {
|
public SlashCommand getFullSlashCommand() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user