use of org.spongepowered.api.user.UserManager in project SpongeCommon by SpongePowered.
the class SpongeUserValueParameter method parseValue.
@Override
@NonNull
public Optional<? extends UUID> parseValue(@NonNull final CommandCause cause, final ArgumentReader.@NonNull Mutable reader) throws ArgumentParseException {
final String peek = reader.peekString();
if (peek.startsWith("@")) {
try {
final ServerPlayer entity = (ServerPlayer) (this.selectorArgumentType.parse((StringReader) reader).findSingleEntity(((CommandSourceStack) cause)));
return Optional.of(entity.uniqueId());
} catch (final CommandSyntaxException e) {
throw reader.createException(Component.text(e.getContext()));
}
}
final UserManager userManager = SpongeCommon.game().server().userManager();
try {
final UUID uuid = UUID.fromString(reader.parseString());
if (userManager.exists(uuid)) {
return Optional.of(uuid);
}
} catch (final Exception ignored) {
}
// if no UUID, get the name. We've already advanced the reader at this point.
final Optional<UUID> result = Sponge.server().gameProfileManager().cache().findByName(peek).map(GameProfile::uuid).filter(userManager::exists);
if (result.isPresent()) {
return result;
}
throw reader.createException(Component.text("Could not find user with user name \"" + peek + "\""));
}
Aggregations