Improvements for JDA command prefixes. (#94)

This commit is contained in:
Jeremy Wood
2018-01-25 18:28:02 -05:00
committed by Daniel Ennis
parent c2d421ed19
commit afc7f801b2
3 changed files with 17 additions and 9 deletions
@@ -3,8 +3,10 @@ package co.aikar.commands;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public interface CommandConfig extends CommandConfigProvider {
@NotNull String getStartsWith();
@NotNull List<String> getCommandPrefixes();
@Override
default CommandConfig provide(MessageReceivedEvent event) {
@@ -2,19 +2,18 @@ package co.aikar.commands;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
public class JDACommandConfig implements CommandConfig {
protected @NotNull String startsWith = "!";
protected @NotNull List<String> commandPrefixes = new CopyOnWriteArrayList<>(new String[] {"!"});
public JDACommandConfig() {
}
@NotNull
public String getStartsWith() {
return startsWith;
}
public void setStartsWith(@NotNull String startsWith) {
this.startsWith = startsWith;
public List<String> getCommandPrefixes() {
return commandPrefixes;
}
}
@@ -226,7 +226,14 @@ public class JDACommandManager extends CommandManager<
}
}
if (!msg.startsWith(config.getStartsWith())) {
boolean foundPrefix = false;
for (String prefix : config.getCommandPrefixes()) {
if (msg.startsWith(prefix)) {
foundPrefix = true;
break;
}
}
if (!foundPrefix) {
return;
}