Skip to content

Commit

Permalink
Fix hasCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Sep 11, 2022
1 parent a34c4dc commit fcf419d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/java/net/citizensnpcs/api/command/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,25 @@ private String getUsage(String[] args, Command cmd) {
*/
public boolean hasCommand(org.bukkit.command.Command cmd, String... modifier) {
String cmdName = cmd.getName().toLowerCase();
return commands.containsKey(Joiner.on(' ').join(cmdName, modifier)) || commands.containsKey(cmdName + " *");
String[] parts = new String[modifier.length + 1];
System.arraycopy(modifier, 0, parts, 1, modifier.length);
parts[0] = cmdName;
return hasCommand(parts);
}

/**
* Checks to see whether there is a command handler for the given command parts at the root level. This will check
* aliases as well.
*
* @param parts
* The parts to check (must not be empty)
* @return Whether the command is handled
*/
public boolean hasCommand(String... parts) {
if (parts == null || parts.length == 0) {
throw new IllegalArgumentException("parts must not be empty");
}
return commands.containsKey(Joiner.on(' ').join(parts)) || commands.containsKey(parts[0] + " *");
}

private boolean hasPermission(CommandInfo method, CommandSender sender) {
Expand Down

0 comments on commit fcf419d

Please sign in to comment.