Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Add support for default sub-commands #9

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@
<dependency>
<groupId>li.l1t.common</groupId>
<artifactId>xyc-api-spigot</artifactId>
<version>4.4.2</version>
<version>4.5.7-SNAPSHOT</version>
</dependency>

<!--<dependency>
<dependency>
<groupId>com.sk89q.intake</groupId>
<artifactId>intake</artifactId>
<version>4.2-SNAPSHOT</version>
</dependency>-->
</dependency>

<!-- custom fork with some fixes; for now -->
<dependency>
<!--<dependency>
<groupId>li.l1t.intake</groupId>
<artifactId>intake</artifactId>
<version>xxyy-82322fd</version>
</dependency>
</dependency>-->
</dependencies>

<build>
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/li/l1t/common/intake/CommandBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public CommandBuilder withDispatcherFor(Object handler) {
return this;
}


/**
* Adds a handler for sub-commands in a separate class from the root handler.
*
Expand All @@ -77,7 +78,12 @@ public CommandBuilder withDispatcherFor(Object handler) {
* @return this instance
*/
public CommandBuilder withSubHandler(Object handler, String... aliases) {
rootGroup.group(aliases).registerMethods(handler);
if (aliases != null && aliases.length > 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer !isEmpty(), it's more semantic / easier to read in general

rootGroup.group(aliases).registerMethods(handler);
}
else {
rootGroup.registerMethods(handler);
}
return this;
}

Expand All @@ -93,6 +99,7 @@ public CommandBuilder create() {
public CommandBuilder register() {
Preconditions.checkNotNull(command, "command");
manager.commandRegistrationManager.registerCommand(command, manager.getFallbackPrefix());
manager.getPlugin().getServer().getPluginCommand(command.getName()).setTabCompleter(command);
return this;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/li/l1t/common/intake/CommandsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/li/l1t/common/intake/IntakeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.plugin.Plugin;

import java.util.Collections;
Expand All @@ -38,7 +39,7 @@
* @author <a href="http://xxyy.github.io/">xxyy</a>
* @since 2016-07-23
*/
public class IntakeCommand extends Command implements PluginIdentifiableCommand {
public class IntakeCommand extends Command implements PluginIdentifiableCommand, TabCompleter {
private final CommandsManager manager;
private final Dispatcher dispatcher;
private final Namespace namespace = new Namespace();
Expand Down Expand Up @@ -148,4 +149,9 @@ public List<String> tabComplete(CommandSender sender, String alias, String[] arg
return ImmutableList.of();
}
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
return this.tabComplete(sender, command.getName(), args);
}
}