All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.lucko.luckperms.api.manager.UserManager Maven / Gradle / Ivy

Go to download

An advanced permissions plugin for Bukkit/Spigot, BungeeCord, Sponge, Nukkit and Velocity.

The newest version!
/*
 * This file is part of LuckPerms, licensed under the MIT License.
 *
 *  Copyright (c) lucko (Luck) 
 *  Copyright (c) contributors
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in all
 *  copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 *  SOFTWARE.
 */

package me.lucko.luckperms.api.manager;

import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.api.Storage;
import me.lucko.luckperms.api.User;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Consumer;

/**
 * Represents the object responsible for managing {@link User} instances.
 *
 * 

Note that User instances are automatically loaded for online players. * It's likely that offline players will not have an instance pre-loaded.

* *

All blocking methods return {@link CompletableFuture}s, which will be * populated with the result once the data has been loaded/saved asynchronously. * Care should be taken when using such methods to ensure that the main server * thread is not blocked.

* *

Methods such as {@link CompletableFuture#get()} and equivalent should * not be called on the main server thread. If you need to use * the result of these operations on the main server thread, register a * callback using {@link CompletableFuture#thenAcceptAsync(Consumer, Executor)}.

* * @since 4.0 */ public interface UserManager { /** * Loads a user from the plugin's storage provider into memory. * *

This method is effectively the same as * {@link Storage#loadUser(UUID, String)}, however, the Future returns the * resultant user instance instead of a boolean flag.

* *

Unlike the method in {@link Storage}, when a user cannot be loaded, * the future will be {@link CompletableFuture completed exceptionally}.

* * @param uuid the uuid of the user * @param username the username, if known * @return the resultant user * @throws NullPointerException if the uuid is null * @since 4.1 */ @NonNull CompletableFuture loadUser(@NonNull UUID uuid, @Nullable String username); /** * Loads a user from the plugin's storage provider into memory. * *

This method is effectively the same as {@link Storage#loadUser(UUID)}, * however, the Future returns the resultant user instance instead of a * boolean flag.

* *

Unlike the method in {@link Storage}, when a user cannot be loaded, * the future will be {@link CompletableFuture completed exceptionally}.

* * @param uuid the uuid of the user * @return the resultant user * @throws NullPointerException if the uuid is null * @since 4.1 */ default @NonNull CompletableFuture loadUser(@NonNull UUID uuid) { return loadUser(uuid, null); } /** * Uses the LuckPerms cache to find a uuid for the given username. * *

This lookup is case insensitive.

* * @param username the username * @return a uuid, could be null * @throws NullPointerException if either parameters are null * @throws IllegalArgumentException if the username is invalid * @since 4.2 */ @NonNull CompletableFuture lookupUuid(@NonNull String username); /** * Uses the LuckPerms cache to find a username for the given uuid. * * @param uuid the uuid * @return a username, could be null * @throws NullPointerException if either parameters are null * @throws IllegalArgumentException if the username is invalid * @since 4.2 */ @NonNull CompletableFuture lookupUsername(@NonNull UUID uuid); /** * Saves a user's data back to the plugin's storage provider. * *

You should call this after you make any changes to a user.

* *

This method is effectively the same as {@link Storage#saveUser(User)}, * however, the Future returns void instead of a boolean flag.

* *

Unlike the method in {@link Storage}, when a user cannot be saved, * the future will be {@link CompletableFuture completed exceptionally}.

* * @param user the user to save * @return a future to encapsulate the operation. * @throws NullPointerException if user is null * @throws IllegalStateException if the user instance was not obtained from LuckPerms. * @since 4.1 */ @NonNull CompletableFuture saveUser(@NonNull User user); /** * Saves data about a player to the uuid caching system. * * @param uuid the users mojang unique id * @param username the users username * @return the result of the operation. * @throws NullPointerException if either parameters are null * @throws IllegalArgumentException if the username is invalid * @since 4.2 */ @NonNull CompletableFuture savePlayerData(@NonNull UUID uuid, @NonNull String username); /** * Gets a set all "unique" user UUIDs. * *

"Unique" meaning the user isn't just a member of the "default" group.

* * @return a set of uuids * @since 4.2 */ @NonNull CompletableFuture> getUniqueUsers(); /** * Searches for a list of users with a given permission. * * @param permission the permission to search for * @return a list of held permissions * @throws NullPointerException if the permission is null * @since 4.2 */ @NonNull CompletableFuture>> getWithPermission(@NonNull String permission); /** * Gets a loaded user. * * @param uuid the uuid of the user to get * @return a {@link User} object, if one matching the uuid is loaded, or null if not * @throws NullPointerException if the uuid is null */ @Nullable User getUser(@NonNull UUID uuid); /** * Gets a loaded user. * * @param uuid the uuid of the user to get * @return an optional {@link User} object * @throws NullPointerException if the uuid is null */ default @NonNull Optional getUserOpt(@NonNull UUID uuid) { return Optional.ofNullable(getUser(uuid)); } /** * Gets a loaded user. * * @param name the username of the user to get * @return a {@link User} object, if one matching the uuid is loaded, or null if not * @throws NullPointerException if the name is null */ @Nullable User getUser(@NonNull String name); /** * Gets a loaded user. * * @param name the username of the user to get * @return an optional {@link User} object * @throws NullPointerException if the name is null */ default @NonNull Optional getUserOpt(@NonNull String name) { return Optional.ofNullable(getUser(name)); } /** * Gets a set of all loaded users. * * @return a {@link Set} of {@link User} objects */ @NonNull Set getLoadedUsers(); /** * Check if a user is loaded in memory * * @param uuid the uuid to check for * @return true if the user is loaded * @throws NullPointerException if the uuid is null */ boolean isLoaded(@NonNull UUID uuid); /** * Unload a user from the internal storage, if they're not currently online. * * @param user the user to unload * @throws NullPointerException if the user is null */ void cleanupUser(@NonNull User user); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy