Fix isOptional usage in onlinePlayer context resolvers

Null should not be returned when something is provided as an argument
This commit is contained in:
chickeneer
2022-01-15 13:45:55 -06:00
parent 61904737e0
commit 153a636fa1
3 changed files with 13 additions and 18 deletions
@@ -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);