001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.uuid;
020
021import org.checkerframework.checker.nullness.qual.NonNull;
022import org.checkerframework.checker.nullness.qual.Nullable;
023
024import java.util.Collection;
025import java.util.Collections;
026import java.util.List;
027import java.util.UUID;
028
029/**
030 * Service used to provide usernames from player UUIDs
031 */
032public interface UUIDService {
033
034    /**
035     * Attempt to complete the given requests. Returns the mappings
036     * that could be created by this server
037     *
038     * @param uuids Requests
039     * @return Completed requests
040     */
041    @NonNull List<@NonNull UUIDMapping> getNames(final @NonNull List<@NonNull UUID> uuids);
042
043    /**
044     * Attempt to complete the given requests. Returns the mappings
045     * that could be created by this server
046     *
047     * @param usernames Requests
048     * @return Completed requests
049     */
050    @NonNull List<@NonNull UUIDMapping> getUUIDs(final @NonNull List<@NonNull String> usernames);
051
052    /**
053     * Get as many UUID mappings as possible under the condition
054     * that the operation cannot be blocking (for an extended amount of time)
055     *
056     * @return All mappings that could be provided immediately
057     */
058    default @NonNull Collection<@NonNull UUIDMapping> getImmediately() {
059        return Collections.emptyList();
060    }
061
062    /**
063     * Check whether or not this service can be safely used synchronously
064     * without blocking the server for an extended amount of time.
065     *
066     * @return {@code true} if the service can be used synchronously
067     */
068    default boolean canBeSynchronous() {
069        return false;
070    }
071
072    /**
073     * Get a single UUID mapping immediately, if possible
074     *
075     * @param object Username ({@link String}) or {@link UUID}
076     * @return Mapping, if it could be found immediately
077     */
078    default @Nullable UUIDMapping getImmediately(final @NonNull Object object) {
079        return null;
080    }
081
082}