mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
Change valid name checking to a configurable predicate #382
I see the value in allowing acf users to disable the valid name check. I think others may want to go a step further and create their own valid name verification. Those that want to truly accept all names can simply do `CommandManager#setValidNamePredicate(name -> true)` with the new API. Another solution I considered was having users override the isValidName method on their CommandManager, but this functionality seemed more friendly.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package co.aikar.commands;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.command.CommandSource;
|
||||
import org.spongepowered.api.entity.living.player.Player;
|
||||
@@ -31,7 +32,7 @@ public class ACFSpongeUtil {
|
||||
}
|
||||
|
||||
if (matches.isEmpty()) {
|
||||
if (!isValidName(name, issuer.getManager())) {
|
||||
if (!issuer.getManager().isValidName(name)) {
|
||||
issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name);
|
||||
return null;
|
||||
}
|
||||
@@ -89,12 +90,8 @@ public class ACFSpongeUtil {
|
||||
return matchedPlayers;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean isValidName(String name) {
|
||||
return isValidName(name, null);
|
||||
public static boolean isValidName(@Nullable String name) {
|
||||
return name != null && !name.isEmpty() && ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches();
|
||||
}
|
||||
|
||||
public static boolean isValidName(String name, CommandManager manager) {
|
||||
return name != null && !name.isEmpty() && ((manager != null && manager.isAllowInvalidName()) || ACFPatterns.VALID_NAME_PATTERN.matcher(name).matches());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ public class SpongeCommandManager extends CommandManager<
|
||||
this.formatters.put(MessageType.HELP, new SpongeMessageFormatter(TextColors.AQUA, TextColors.GREEN, TextColors.YELLOW));
|
||||
getLocales(); // auto load locales
|
||||
|
||||
this.validNamePredicate = ACFSpongeUtil::isValidName;
|
||||
|
||||
Sponge.getEventManager().registerListeners(plugin, new ACFSpongeListener(this));
|
||||
|
||||
//TODO more default dependencies for sponge
|
||||
|
||||
Reference in New Issue
Block a user