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

Commit

Permalink
Added default prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bastian committed Apr 1, 2016
1 parent 705e572 commit 1b0cda1
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public abstract class CommandHandler {
protected final List<SimpleCommand> commandList = new ArrayList<>();
private final HashMap<String, List<String>> permissions = new HashMap<>();

protected String defaultPrefix = "";

/**
* Registers an executor.
*
Expand All @@ -50,7 +52,7 @@ public void registerCommand(CommandExecutor executor) {
SimpleCommand command = new SimpleCommand(annotation, method, executor);
for (String alias : annotation.aliases()) {
// add command to map. It's faster to access it from the map than iterating to the whole list
commands.put(alias.toLowerCase(), command);
commands.put(defaultPrefix + alias.toLowerCase().replace(" ", ""), command);
}
// we need a list, too, because a HashMap is not ordered.
commandList.add(command);
Expand Down Expand Up @@ -107,6 +109,29 @@ public List<SimpleCommand> getCommands() {
return Collections.unmodifiableList(commandList);
}

/**
* Sets the default command prefix.
* Changing the default prefix after registering a command has no effect!
*
* @param defaultPrefix The default command prefix.
*/
public void setDefaultPrefix(String defaultPrefix) {
if (defaultPrefix == null) {
this.defaultPrefix = "";
} else {
this.defaultPrefix = defaultPrefix.replace(" ", "");
}
}

/**
* Gets the default command prefix.
*
* @return The default command prefix.
*/
public String getDefaultPrefix() {
return defaultPrefix;
}

/**
* Checks if you are allowed to do something with the given permission.
*
Expand Down

0 comments on commit 1b0cda1

Please sign in to comment.