mirror of
https://github.com/aikar/commands.git
synced 2026-06-08 17:47:35 +00:00
Improvements (#143)
Improve help output for commands split over multiple base commands Fix help last page detection Fix missing argument on Player Context Resolve Expose registered root commands
This commit is contained in:
@@ -117,7 +117,10 @@ public class BukkitCommandContexts extends CommandContexts<BukkitCommandExecutio
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else if (arg == null) {
|
||||
throw new InvalidCommandArgument();
|
||||
}
|
||||
|
||||
OnlinePlayer onlinePlayer = getOnlinePlayer(c.getIssuer(), arg, isOptional);
|
||||
return onlinePlayer != null ? onlinePlayer.getPlayer() : null;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -307,6 +309,11 @@ public class BukkitCommandManager extends CommandManager<
|
||||
return new BukkitRootCommand(this, cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RootCommand> getRegisteredRootCommands() {
|
||||
return Collections.unmodifiableCollection(registeredCommands.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BukkitCommandIssuer getCommandIssuer(Object issuer) {
|
||||
if (!(issuer instanceof CommandSender)) {
|
||||
|
||||
@@ -31,6 +31,8 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -175,6 +177,11 @@ public class BungeeCommandManager extends CommandManager<
|
||||
public RootCommand createRootCommand(String cmd) {
|
||||
return new BungeeRootCommand(this, cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RootCommand> getRegisteredRootCommands() {
|
||||
return Collections.unmodifiableCollection(registeredCommands.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BungeeCommandExecutionContext createCommandContext(RegisteredCommand command, CommandParameter parameter, CommandIssuer sender, List<String> args, int i, Map<String, Object> passedArgs) {
|
||||
|
||||
@@ -145,6 +145,10 @@ public abstract class BaseCommand {
|
||||
* The conditions of the command. This may be null if no conditions has been provided.
|
||||
*/
|
||||
@Nullable String conditions;
|
||||
/**
|
||||
* Identifies if the command has an explicit help command annotated with {@link HelpCommand}
|
||||
*/
|
||||
boolean hasHelpCommand;
|
||||
|
||||
/**
|
||||
* The handler of all uncaught exceptions thrown by the user's command implementation.
|
||||
@@ -327,6 +331,7 @@ public abstract class BaseCommand {
|
||||
sublist = commandAliases;
|
||||
} else if (helpCommand != null) {
|
||||
sublist = helpCommand;
|
||||
hasHelpCommand = true;
|
||||
}
|
||||
|
||||
boolean preCommand = annotations.hasAnnotation(method, PreCommand.class);
|
||||
|
||||
@@ -58,6 +58,12 @@ public class CommandHelp {
|
||||
|
||||
SetMultimap<String, RegisteredCommand> subCommands = rootCommand.getSubCommands();
|
||||
Set<RegisteredCommand> seen = new HashSet<>();
|
||||
|
||||
if (!rootCommand.getDefCommand().hasHelpCommand) {
|
||||
helpEntries.add(new HelpEntry(this, rootCommand.getDefaultRegisteredCommand()));
|
||||
seen.add(rootCommand.getDefaultRegisteredCommand());
|
||||
}
|
||||
|
||||
subCommands.entries().forEach(e -> {
|
||||
String key = e.getKey();
|
||||
if (key.equals(BaseCommand.DEFAULT) || key.equals(BaseCommand.CATCHUNKNOWN)) {
|
||||
@@ -162,7 +168,7 @@ public class CommandHelp {
|
||||
}
|
||||
printEntries.add(e);
|
||||
}
|
||||
this.lastPage = !(min > 0 || results.hasNext());
|
||||
this.lastPage = max >= totalResults;
|
||||
|
||||
if (search == null) {
|
||||
formatter.showAllResults(this, printEntries);
|
||||
|
||||
@@ -34,6 +34,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.List;
|
||||
@@ -283,6 +285,8 @@ public abstract class CommandManager <
|
||||
return rootCommands.computeIfAbsent(ACFPatterns.SPACE.split(cmd.toLowerCase(), 2)[0], this::createRootCommand);
|
||||
}
|
||||
|
||||
public abstract Collection<RootCommand> getRegisteredRootCommands();
|
||||
|
||||
public RegisteredCommand createRegisteredCommand(BaseCommand command, String cmdName, Method method, String prefSubCommand) {
|
||||
return new RegisteredCommand(command, cmdName, method, prefSubCommand);
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
|
||||
|
||||
if (BaseCommand.CATCHUNKNOWN.equals(prefSubCommand) || BaseCommand.DEFAULT.equals(prefSubCommand)) {
|
||||
prefSubCommand = "";
|
||||
command = command.trim();
|
||||
}
|
||||
this.command = command + (!annotations.hasAnnotation(method, CommandAlias.class, false) && !prefSubCommand.isEmpty() ? prefSubCommand : "");
|
||||
this.method = method;
|
||||
@@ -295,6 +296,14 @@ public class RegisteredCommand <CEC extends CommandExecutionContext<CEC, ? exten
|
||||
public String getSyntaxText() {
|
||||
return syntaxText;
|
||||
}
|
||||
|
||||
public String getHelpText() {
|
||||
return helpText;
|
||||
}
|
||||
|
||||
public boolean isPrivate() {
|
||||
return isPrivate;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return command;
|
||||
|
||||
@@ -33,7 +33,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
interface RootCommand {
|
||||
public interface RootCommand {
|
||||
void addChild(BaseCommand command);
|
||||
CommandManager getManager();
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
@@ -181,6 +183,11 @@ public class JDACommandManager extends CommandManager<
|
||||
public RootCommand createRootCommand(String cmd) {
|
||||
return new JDARootCommand(this, cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RootCommand> getRegisteredRootCommands() {
|
||||
return Collections.unmodifiableCollection(commands.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locales getLocales() {
|
||||
|
||||
Reference in New Issue
Block a user