public static <P> @NotNull Optional<P> serviceWithFallback(final @NotNull Class<P> type) {
    final ServiceLoader<P> loader = Services0.loader(type);
    final Iterator<P> it = loader.iterator();
    P firstFallback = null;

    while (it.hasNext()) {
      final P instance;

      try {
        instance = it.next();
      } catch (final Throwable t) {
        if (SERVICE_LOAD_FAILURES_ARE_FATAL) {
          throw new IllegalStateException("Encountered an exception loading service " + type, t);
        } else {
          continue;
        }
      }

      if (instance instanceof Fallback) {
        if (firstFallback == null) {
          firstFallback = instance;
        }
      } else {
        return Optional.of(instance);
      }
    }

    return Optional.ofNullable(firstFallback);
  }
Locates a service.

<p>If multiple services of this type exist, the first non-fallback service will be returned.</p>

@param type the service type
@param <P> the service type
@return a service, or {@link Optional#empty()}
@see Fallback
@since 4.14.0
api/src/main/java/net/kyori/adventure/util/Services.java