mirror of
https://github.com/aikar/commands.git
synced 2026-06-11 10:30:38 +00:00
Improvements for JDA command prefixes. (#94)
This commit is contained in:
committed by
Daniel Ennis
parent
c2d421ed19
commit
afc7f801b2
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user