Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/main/java/me/croabeast/command/SubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,20 @@ public class SubCommand implements BaseCommand {
* </p>
*
* @param parent the parent command (must not be {@code null}).
* @param name the sub-command name, optionally including aliases separated by a semicolon.
* @param aliases the sub-command name, optionally including aliases separated by a semicolon.
* @throws NullPointerException if the parent is {@code null} or if the name is blank.
*/
public SubCommand(Command parent, String name) {
public SubCommand(Command parent, String name, String... aliases) {
this.parent = Objects.requireNonNull(parent, "Parent cannot be null");

if (StringUtils.isBlank(name))
throw new NullPointerException("Name is empty");

// Split the provided name string by semicolons to extract primary name and aliases.
List<String> list = new ArrayList<>(Arrays.asList(name.split(";")));
this.name = list.get(0);
List<String> list = Arrays.asList(aliases);
this.name = name;
this.permission = parent.getPermission() + '.' + this.name;

// Add any aliases if provided.
if (list.size() > 1) {
for (int i = 1; i < list.size(); i++) {
aliases.add(list.get(i));
}
}
this.aliases.addAll(list);
}

/**
Expand Down
Loading