bump version to 0.38-SNAPSHOT + pass input to SuggestionProvider + rewrite command parsing + ...
All checks were successful
Build and Deploy artifact / build (push) Successful in 1m31s
All checks were successful
Build and Deploy artifact / build (push) Successful in 1m31s
This commit is contained in:
parent
997906cd02
commit
23f7d1a550
26 changed files with 382 additions and 302 deletions
|
|
@ -16,7 +16,7 @@ public final class PlayerSuggestionProvider<T extends CommandSource> implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(T __) {
|
||||
public List<String> suggest(T __, String ___) {
|
||||
return proxyServer.getAllPlayers().stream()
|
||||
.map(Player::getUsername)
|
||||
.toList();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package de.kentoj.kencommandapi.type;
|
||||
|
||||
import com.leakyabstractions.result.api.Result;
|
||||
import com.leakyabstractions.result.core.Results;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
|
@ -7,6 +9,8 @@ import de.kentoj.kencommandapi.api.argument.ArgumentType;
|
|||
import de.kentoj.kencommandapi.api.suggestion.SuggestionProvider;
|
||||
import de.kentoj.kencommandapi.suggestionprovider.PlayerSuggestionProvider;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerArgumentType<T extends CommandSource> implements ArgumentType<T, Player> {
|
||||
|
||||
private final ProxyServer server;
|
||||
|
|
@ -16,10 +20,20 @@ public class PlayerArgumentType<T extends CommandSource> implements ArgumentType
|
|||
}
|
||||
|
||||
@Override
|
||||
public Player parseInputUnchecked(String input) {
|
||||
var player = server.getPlayer(input).orElse(null);
|
||||
if (player == null) throw new IllegalArgumentException("Player not online");
|
||||
return player;
|
||||
public Result<Player, String> parseInputUnchecked(String input) {
|
||||
// TODO UUID support
|
||||
Player player;
|
||||
if (input.length() == 36) {
|
||||
try {
|
||||
player = server.getPlayer(UUID.fromString(input)).orElse(null);
|
||||
} catch (IllegalArgumentException _) {
|
||||
return Results.failure("Invalid UUID.");
|
||||
}
|
||||
} else {
|
||||
player = server.getPlayer(input).orElse(null);
|
||||
}
|
||||
|
||||
return Results.ofNullable(player, "Player not online.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue