mirror of
https://github.com/aikar/commands.git
synced 2026-05-31 06:11:55 +00:00
Fix isOptional usage in onlinePlayer context resolvers
Null should not be returned when something is provided as an argument
This commit is contained in:
@@ -32,7 +32,6 @@ import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.format.TextFormat;
|
||||
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -44,7 +43,7 @@ public class VelocityCommandContexts extends CommandContexts<VelocityCommandExec
|
||||
registerContext(OnlinePlayer.class, (c) -> getOnlinePlayer(server, c));
|
||||
registerContext(co.aikar.commands.contexts.OnlinePlayer.class, c -> {
|
||||
OnlinePlayer onlinePlayer = getOnlinePlayer(server, c);
|
||||
return onlinePlayer != null ? new co.aikar.commands.contexts.OnlinePlayer(onlinePlayer.getPlayer()) : null;
|
||||
return new co.aikar.commands.contexts.OnlinePlayer(onlinePlayer.getPlayer());
|
||||
});
|
||||
registerIssuerAwareContext(CommandSource.class, VelocityCommandExecutionContext::getSender);
|
||||
registerIssuerAwareContext(Player.class, (c) -> {
|
||||
@@ -79,13 +78,9 @@ public class VelocityCommandContexts extends CommandContexts<VelocityCommandExec
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private OnlinePlayer getOnlinePlayer(ProxyServer server, VelocityCommandExecutionContext c) throws InvalidCommandArgument {
|
||||
Player proxiedPlayer = ACFVelocityUtil.findPlayerSmart(server, c.getIssuer(), c.popFirstArg());
|
||||
if (proxiedPlayer == null) {
|
||||
if (c.isOptional()) {
|
||||
return null;
|
||||
}
|
||||
throw new InvalidCommandArgument(false);
|
||||
}
|
||||
return new OnlinePlayer(proxiedPlayer);
|
||||
|
||||
Reference in New Issue
Block a user