Release version 4.2.0

blaze it
This commit is contained in:
Luck 2018-05-06 17:16:36 +01:00
parent 91b7af52ac
commit 64838708ab
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
38 changed files with 487 additions and 280 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -47,8 +47,6 @@ public interface ActionLogger {
/**
* Gets a {@link Log} instance from the plugin storage.
*
* <p>Returns the same result as {@link Storage#getLog()}.</p>
*
* @return a log instance
* @see Storage#getLog()
*/

View File

@ -23,12 +23,8 @@
* SOFTWARE.
*/
package me.lucko.luckperms.common.storage;
package me.lucko.luckperms.api;
import com.google.common.collect.ImmutableSet;
import java.util.EnumSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@ -36,71 +32,19 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Represents the result to a player history save operation
* Encapsulates the result of an operation to save uuid data about a player.
*
* @since 4.2
*/
public final class PlayerSaveResult {
private static final PlayerSaveResult CLEAN_INSERT = new PlayerSaveResult(Status.CLEAN_INSERT);
private static final PlayerSaveResult NO_CHANGE = new PlayerSaveResult(Status.NO_CHANGE);
public static PlayerSaveResult cleanInsert() {
return CLEAN_INSERT;
}
public static PlayerSaveResult noChange() {
return NO_CHANGE;
}
public static PlayerSaveResult usernameUpdated(String oldUsername) {
return new PlayerSaveResult(EnumSet.of(Status.USERNAME_UPDATED), oldUsername, null);
}
public static PlayerSaveResult determineBaseResult(String username, String oldUsername) {
PlayerSaveResult result;
if (oldUsername == null) {
result = PlayerSaveResult.cleanInsert();
} else if (oldUsername.equalsIgnoreCase(username)) {
result = PlayerSaveResult.noChange();
} else {
result = PlayerSaveResult.usernameUpdated(oldUsername);
}
return result;
}
private final Set<Status> status;
@Nullable private final String oldUsername;
@Nullable private final Set<UUID> otherUuids;
private PlayerSaveResult(EnumSet<Status> status, @Nullable String oldUsername, @Nullable Set<UUID> otherUuids) {
this.status = ImmutableSet.copyOf(status);
this.oldUsername = oldUsername;
this.otherUuids = otherUuids;
}
private PlayerSaveResult(Status status) {
this(EnumSet.of(status), null, null);
}
/**
* Returns a new {@link PlayerSaveResult} with the {@link Status#OTHER_UUIDS_PRESENT_FOR_USERNAME}
* status attached to the state of this result.
*
* @param otherUuids the other uuids
* @return a new result
*/
public PlayerSaveResult withOtherUuidsPresent(@Nonnull Set<UUID> otherUuids) {
EnumSet<Status> status = EnumSet.copyOf(this.status);
status.add(Status.OTHER_UUIDS_PRESENT_FOR_USERNAME);
return new PlayerSaveResult(status, this.oldUsername, ImmutableSet.copyOf(otherUuids));
}
public interface PlayerSaveResult {
/**
* Gets the status returned by the operation
*
* @return the status
*/
public Set<Status> getStatus() {
return this.status;
}
@Nonnull
Set<Status> getStatus();
/**
* Gets if the result includes a certain status code.
@ -108,9 +52,7 @@ public final class PlayerSaveResult {
* @param status the status to check for
* @return if the result includes the status
*/
public boolean includes(Status status) {
return this.status.contains(status);
}
boolean includes(@Nonnull Status status);
/**
* Gets the old username involved in the result
@ -119,9 +61,7 @@ public final class PlayerSaveResult {
* @see Status#USERNAME_UPDATED
*/
@Nullable
public String getOldUsername() {
return this.oldUsername;
}
String getOldUsername();
/**
* Gets the other uuids involved in the result
@ -130,29 +70,12 @@ public final class PlayerSaveResult {
* @see Status#OTHER_UUIDS_PRESENT_FOR_USERNAME
*/
@Nullable
public Set<UUID> getOtherUuids() {
return this.otherUuids;
}
@Override
public boolean equals(Object that) {
if (this == that) return true;
if (that == null || getClass() != that.getClass()) return false;
PlayerSaveResult result = (PlayerSaveResult) that;
return Objects.equals(this.status, result.status) &&
Objects.equals(this.oldUsername, result.oldUsername) &&
Objects.equals(this.otherUuids, result.otherUuids);
}
@Override
public int hashCode() {
return Objects.hash(this.status, this.oldUsername, this.otherUuids);
}
Set<UUID> getOtherUuids();
/**
* The various states the result can take
*/
public enum Status {
enum Status {
/**
* There was no existing data saved for either the uuid or username

View File

@ -34,7 +34,6 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -42,16 +41,6 @@ import javax.annotation.Nullable;
/**
* A means of loading and saving permission data to/from the backend.
*
* <p>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.</p>
*
* <p>Methods such as {@link CompletableFuture#get()} and equivalent should
* <strong>not</strong> 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)}.</p>
*
* @since 2.14
*/
public interface Storage {
@ -64,80 +53,6 @@ public interface Storage {
@Nonnull
String getName();
/**
* Loads and returns the entire log from storage
*
* @return a log instance, could be null if loading failed
*/
@Nonnull
CompletableFuture<Log> getLog();
/**
* Gets a set all "unique" user UUIDs.
*
* <p>"Unique" meaning the user isn't just a member of the "default" group.</p>
*
* @return a set of uuids, or null if the operation failed.
*/
@Nonnull
CompletableFuture<Set<UUID>> getUniqueUsers();
/**
* Searches for a list of users with a given permission.
*
* @param permission the permission to search for
* @return a list of held permissions, or null if the operation failed
* @throws NullPointerException if the permission is null
* @since 2.17
*/
@Nonnull
CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(@Nonnull String permission);
/**
* Searches for a list of groups with a given permission.
*
* @param permission the permission to search for
* @return a list of held permissions, or null if the operation failed
* @throws NullPointerException if the permission is null
* @since 2.17
*/
@Nonnull
CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(@Nonnull String permission);
/**
* Saves UUID caching data to the global cache
*
* @param username the users username
* @param uuid the users mojang unique id
* @return true if the operation completed successfully.
* @throws NullPointerException if either parameters are null
* @throws IllegalArgumentException if the username is invalid
*/
@Nonnull
CompletableFuture<Boolean> saveUUIDData(@Nonnull String username, @Nonnull UUID uuid);
/**
* Gets a UUID from a username
*
* @param username the corresponding username
* @return a uuid object, could be null
* @throws NullPointerException if either parameters are null
* @throws IllegalArgumentException if the username is invalid
*/
@Nonnull
CompletableFuture<UUID> getUUID(@Nonnull String username);
/**
* Gets a username from a UUID
*
* @param uuid the corresponding uuid
* @return a name string, could be null
* @throws NullPointerException if either parameters are null
* @since 2.17
*/
@Nonnull
CompletableFuture<String> getName(@Nonnull UUID uuid);
/**
* Gets whether the storage instance is allowing logins on the platform.
*
@ -147,34 +62,6 @@ public interface Storage {
@Deprecated
boolean isAcceptingLogins();
/**
* Returns an executor which will run all passed runnables on the
* main server thread.
*
* <p>This method is deprecated as plugins should create and use their own
* executor instances.</p>
*
* @return an executor instance
* @deprecated as plugins should create their own executors
*/
@Nonnull
@Deprecated
Executor getSyncExecutor();
/**
* Returns an executor which will run all passed runnables asynchronously
* using the platforms scheduler and thread pools.
*
* <p>This method is deprecated as plugins should create and use their own
* executor instances.</p>
*
* @return an executor instance
* @deprecated as plugins should create their own executors
*/
@Nonnull
@Deprecated
Executor getAsyncExecutor();
/**
* Saves an action to storage
*
@ -187,6 +74,16 @@ public interface Storage {
@Deprecated
CompletableFuture<Boolean> logAction(@Nonnull LogEntry entry);
/**
* Loads and returns the entire log from storage
*
* @return a log instance, could be null if loading failed
* @deprecated in favour of {@link ActionLogger#getLog()}
*/
@Nonnull
@Deprecated
CompletableFuture<Log> getLog();
/**
* Loads a user's data from the main storage into the plugins local storage.
*
@ -229,6 +126,31 @@ public interface Storage {
@Deprecated
CompletableFuture<Boolean> saveUser(@Nonnull User user);
/**
* Gets a set all "unique" user UUIDs.
*
* <p>"Unique" meaning the user isn't just a member of the "default" group.</p>
*
* @return a set of uuids, or null if the operation failed.
* @deprecated in favour of {@link UserManager#getUniqueUsers()}
*/
@Nonnull
@Deprecated
CompletableFuture<Set<UUID>> getUniqueUsers();
/**
* Searches for a list of users with a given permission.
*
* @param permission the permission to search for
* @return a list of held permissions, or null if the operation failed
* @throws NullPointerException if the permission is null
* @since 2.17
* @deprecated in favour of {@link UserManager#getWithPermission(String)}
*/
@Nonnull
@Deprecated
CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(@Nonnull String permission);
/**
* Creates and loads a group into the plugins local storage
*
@ -293,6 +215,19 @@ public interface Storage {
@Deprecated
CompletableFuture<Boolean> deleteGroup(@Nonnull Group group);
/**
* Searches for a list of groups with a given permission.
*
* @param permission the permission to search for
* @return a list of held permissions, or null if the operation failed
* @throws NullPointerException if the permission is null
* @since 2.17
* @deprecated in favour of {@link GroupManager#getWithPermission(String)}
*/
@Nonnull
@Deprecated
CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(@Nonnull String permission);
/**
* Creates and loads a track into the plugins local storage
*
@ -355,4 +290,70 @@ public interface Storage {
@Deprecated
CompletableFuture<Boolean> deleteTrack(@Nonnull Track track);
/**
* Saves UUID caching data to the global cache
*
* @param username the users username
* @param uuid the users mojang unique id
* @return true if the operation completed successfully.
* @throws NullPointerException if either parameters are null
* @throws IllegalArgumentException if the username is invalid
* @deprecated in favour of {@link UserManager#savePlayerData(UUID, String)}
*/
@Nonnull
CompletableFuture<Boolean> saveUUIDData(@Nonnull String username, @Nonnull UUID uuid);
/**
* Gets a UUID from a username
*
* @param username the corresponding username
* @return a uuid object, could be null
* @throws NullPointerException if either parameters are null
* @throws IllegalArgumentException if the username is invalid
* @deprecated in favour of {@link UserManager#lookupUuid(String)}
*/
@Nonnull
CompletableFuture<UUID> getUUID(@Nonnull String username);
/**
* Gets a username from a UUID
*
* @param uuid the corresponding uuid
* @return a name string, could be null
* @throws NullPointerException if either parameters are null
* @since 2.17
* @deprecated in favour of {@link UserManager#lookupUsername(UUID)}
*/
@Nonnull
@Deprecated
CompletableFuture<String> getName(@Nonnull UUID uuid);
/**
* Returns an executor which will run all passed runnables on the
* main server thread.
*
* <p>This method is deprecated as plugins should create and use their own
* executor instances.</p>
*
* @return an executor instance
* @deprecated as plugins should create their own executors
*/
@Nonnull
@Deprecated
Executor getSyncExecutor();
/**
* Returns an executor which will run all passed runnables asynchronously
* using the platforms scheduler and thread pools.
*
* <p>This method is deprecated as plugins should create and use their own
* executor instances.</p>
*
* @return an executor instance
* @deprecated as plugins should create their own executors
*/
@Nonnull
@Deprecated
Executor getAsyncExecutor();
}

View File

@ -401,6 +401,20 @@ public interface CachedData {
*/
void invalidateMeta(@Nonnull Contexts contexts);
/**
* Invalidates all cached {@link PermissionData} instances.
*
* @since 4.2
*/
void invalidatePermissions();
/**
* Invalidates all cached {@link MetaData} instances.
*
* @since 4.2
*/
void invalidateMeta();
/**
* Invalidates all of the underlying Permission calculators.
*

View File

@ -26,11 +26,15 @@
package me.lucko.luckperms.api.manager;
import me.lucko.luckperms.api.Group;
import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.Storage;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -38,6 +42,16 @@ import javax.annotation.Nullable;
/**
* Represents the object responsible for managing {@link Group} instances.
*
* <p>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.</p>
*
* <p>Methods such as {@link CompletableFuture#get()} and equivalent should
* <strong>not</strong> 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)}.</p>
*
* @since 4.0
*/
public interface GroupManager {
@ -138,6 +152,17 @@ public interface GroupManager {
@Nonnull
CompletableFuture<Void> loadAllGroups();
/**
* Searches for a list of groups with a given permission.
*
* @param permission the permission to search for
* @return a list of held permissions, or null if the operation failed
* @throws NullPointerException if the permission is null
* @since 4.2
*/
@Nonnull
CompletableFuture<List<HeldPermission<String>>> getWithPermission(@Nonnull String permission);
/**
* Gets a loaded group.
*

View File

@ -31,6 +31,8 @@ import me.lucko.luckperms.api.Track;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -38,6 +40,16 @@ import javax.annotation.Nullable;
/**
* Represents the object responsible for managing {@link Track} instances.
*
* <p>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.</p>
*
* <p>Methods such as {@link CompletableFuture#get()} and equivalent should
* <strong>not</strong> 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)}.</p>
*
* @since 4.0
*/
public interface TrackManager {

View File

@ -25,13 +25,18 @@
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 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;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -42,6 +47,16 @@ import javax.annotation.Nullable;
* <p>Note that User instances are automatically loaded for online players.
* It's likely that offline players will not have an instance pre-loaded.</p>
*
* <p>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.</p>
*
* <p>Methods such as {@link CompletableFuture#get()} and equivalent should
* <strong>not</strong> 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)}.</p>
*
* @since 4.0
*/
public interface UserManager {
@ -85,6 +100,32 @@ public interface UserManager {
return loadUser(uuid, null);
}
/**
* Uses the LuckPerms cache to find a uuid for the given username.
*
* <p>This lookup is case insensitive.</p>
*
* @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<UUID> 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<String> lookupUsername(@Nonnull UUID uuid);
/**
* Saves a user's data back to the plugin's storage provider.
*
@ -105,6 +146,41 @@ public interface UserManager {
@Nonnull
CompletableFuture<Void> 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<PlayerSaveResult> savePlayerData(@Nonnull UUID uuid, @Nonnull String username);
/**
* Gets a set all "unique" user UUIDs.
*
* <p>"Unique" meaning the user isn't just a member of the "default" group.</p>
*
* @return a set of uuids
* @since 4.2
*/
@Nonnull
CompletableFuture<Set<UUID>> 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<List<HeldPermission<UUID>>> getWithPermission(@Nonnull String permission);
/**
* Gets a loaded user.
*

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -297,7 +297,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
final User user = getUserManager().getIfLoaded(player.getUniqueId());
if (user != null) {
user.getCachedData().invalidateCaches();
user.getCachedData().invalidate();
getUserManager().unload(user);
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -25,16 +25,20 @@
package me.lucko.luckperms.common.api.delegates.manager;
import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.api.ApiUtils;
import me.lucko.luckperms.common.api.delegates.model.ApiGroup;
import me.lucko.luckperms.common.bulkupdate.comparisons.Constraint;
import me.lucko.luckperms.common.bulkupdate.comparisons.StandardComparison;
import me.lucko.luckperms.common.managers.group.GroupManager;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.node.factory.NodeFactory;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@ -94,6 +98,13 @@ public class ApiGroupManager extends ApiAbstractManager<Group, me.lucko.luckperm
return this.plugin.getStorage().loadAllGroups();
}
@Nonnull
@Override
public CompletableFuture<List<HeldPermission<String>>> getWithPermission(@Nonnull String permission) {
Objects.requireNonNull(permission, "permission");
return this.plugin.getStorage().getGroupsWithPermission(Constraint.of(StandardComparison.EQUAL, permission));
}
@Override
public me.lucko.luckperms.api.Group getGroup(@Nonnull String name) {
Objects.requireNonNull(name, "name");

View File

@ -25,14 +25,19 @@
package me.lucko.luckperms.common.api.delegates.manager;
import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.common.api.ApiUtils;
import me.lucko.luckperms.common.api.delegates.model.ApiUser;
import me.lucko.luckperms.common.bulkupdate.comparisons.Constraint;
import me.lucko.luckperms.common.bulkupdate.comparisons.StandardComparison;
import me.lucko.luckperms.common.managers.user.UserManager;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.UserIdentifier;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
@ -68,6 +73,20 @@ public class ApiUserManager extends ApiAbstractManager<User, me.lucko.luckperms.
.thenApply(this::getDelegateFor);
}
@Nonnull
@Override
public CompletableFuture<UUID> lookupUuid(@Nonnull String username) {
Objects.requireNonNull(username, "username");
return this.plugin.getStorage().getPlayerUuid(username);
}
@Nonnull
@Override
public CompletableFuture<String> lookupUsername(@Nonnull UUID uuid) {
Objects.requireNonNull(uuid, "uuid");
return this.plugin.getStorage().getPlayerName(uuid);
}
@Nonnull
@Override
public CompletableFuture<Void> saveUser(@Nonnull me.lucko.luckperms.api.User user) {
@ -75,6 +94,27 @@ public class ApiUserManager extends ApiAbstractManager<User, me.lucko.luckperms.
return this.plugin.getStorage().saveUser(ApiUser.cast(user));
}
@Nonnull
@Override
public CompletableFuture<PlayerSaveResult> savePlayerData(@Nonnull UUID uuid, @Nonnull String username) {
Objects.requireNonNull(uuid, "uuid");
Objects.requireNonNull(username, "username");
return this.plugin.getStorage().savePlayerData(uuid, username);
}
@Nonnull
@Override
public CompletableFuture<Set<UUID>> getUniqueUsers() {
return this.plugin.getStorage().getUniqueUsers();
}
@Nonnull
@Override
public CompletableFuture<List<HeldPermission<UUID>>> getWithPermission(@Nonnull String permission) {
Objects.requireNonNull(permission, "permission");
return this.plugin.getStorage().getUsersWithPermission(Constraint.of(StandardComparison.EQUAL, permission));
}
@Override
public me.lucko.luckperms.api.User getUser(@Nonnull UUID uuid) {
Objects.requireNonNull(uuid, "uuid");

View File

@ -50,7 +50,7 @@ public class ApiPlatformInfo implements PlatformInfo {
@Override
public double getApiVersion() {
return 4.1;
return 4.2;
}
@Nonnull

View File

@ -99,7 +99,7 @@ public class ApiPermissionHolder implements me.lucko.luckperms.api.PermissionHol
@Nonnull
@Override
public CompletableFuture<Void> refreshCachedData() {
return CompletableFuture.runAsync(() -> this.handle.getCachedData().invalidateCaches());
return CompletableFuture.runAsync(() -> this.handle.getCachedData().invalidate());
}
@Nonnull

View File

@ -355,14 +355,24 @@ public abstract class AbstractCachedData implements CachedData {
this.meta.synchronous().invalidate(getDefaultMetaContexts(contexts));
}
@Override
public void invalidatePermissions() {
this.permission.synchronous().invalidateAll();
}
@Override
public void invalidateMeta() {
this.meta.synchronous().invalidateAll();
}
@Override
public void invalidatePermissionCalculators() {
this.permission.synchronous().asMap().values().forEach(PermissionCache::invalidateCache);
}
public void invalidateCaches() {
this.permission.synchronous().invalidateAll();
this.meta.synchronous().invalidateAll();
public void invalidate() {
invalidatePermissions();
invalidateMeta();
}
public void doCacheCleanup() {

View File

@ -1,37 +0,0 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* 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.common.caching.handlers;
import me.lucko.luckperms.common.model.PermissionHolder;
/**
* Represents an object which is notified when the state of a {@link PermissionHolder} changes.
*/
public interface StateListener {
void onStateChange();
}

View File

@ -25,11 +25,12 @@
package me.lucko.luckperms.common.listener;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.common.assignments.AssignmentRule;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.PlayerSaveResult;
import me.lucko.luckperms.common.storage.PlayerSaveResultImpl;
import java.util.Set;
import java.util.UUID;
@ -63,11 +64,11 @@ public abstract class AbstractConnectionListener implements ConnectionListener {
// save uuid data.
PlayerSaveResult saveResult = this.plugin.getStorage().savePlayerData(u, username).join();
if (saveResult.includes(PlayerSaveResult.Status.CLEAN_INSERT)) {
if (saveResult.includes(PlayerSaveResultImpl.Status.CLEAN_INSERT)) {
this.plugin.getEventFactory().handleUserFirstLogin(u, username);
}
if (saveResult.includes(PlayerSaveResult.Status.OTHER_UUIDS_PRESENT_FOR_USERNAME)) {
if (saveResult.includes(PlayerSaveResultImpl.Status.OTHER_UUIDS_PRESENT_FOR_USERNAME)) {
this.plugin.getLogger().warn("LuckPerms already has data for player '" + username + "' - but this data is stored under a different uuid.");
this.plugin.getLogger().warn("'" + username + "' has previously used the unique ids " + saveResult.getOtherUuids() + " but is now connecting with '" + u + "'");
this.plugin.getLogger().warn("This is usually because the server is not authenticating correctly. If you're using BungeeCord, please ensure that IP-Forwarding is setup correctly!");

View File

@ -205,7 +205,7 @@ public abstract class PermissionHolder {
* Invalidates the holder's cached data.
*/
public void invalidateCachedData() {
getCachedData().invalidateCaches();
getCachedData().invalidate();
}
protected void invalidateCache() {

View File

@ -30,6 +30,7 @@ import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.actionlog.Log;
@ -115,11 +116,6 @@ public class AbstractStorage implements Storage {
return this.dao.getName();
}
@Override
public Storage noBuffer() {
return this;
}
@Override
public void init() {
try {

View File

@ -0,0 +1,135 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <luck@lucko.me>
* 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.common.storage;
import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.api.PlayerSaveResult;
import java.util.EnumSet;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Represents the result to a player history save operation
*/
public final class PlayerSaveResultImpl implements PlayerSaveResult {
private static final PlayerSaveResultImpl CLEAN_INSERT = new PlayerSaveResultImpl(Status.CLEAN_INSERT);
private static final PlayerSaveResultImpl NO_CHANGE = new PlayerSaveResultImpl(Status.NO_CHANGE);
public static PlayerSaveResultImpl cleanInsert() {
return CLEAN_INSERT;
}
public static PlayerSaveResultImpl noChange() {
return NO_CHANGE;
}
public static PlayerSaveResultImpl usernameUpdated(String oldUsername) {
return new PlayerSaveResultImpl(EnumSet.of(Status.USERNAME_UPDATED), oldUsername, null);
}
public static PlayerSaveResultImpl determineBaseResult(String username, String oldUsername) {
PlayerSaveResultImpl result;
if (oldUsername == null) {
result = PlayerSaveResultImpl.cleanInsert();
} else if (oldUsername.equalsIgnoreCase(username)) {
result = PlayerSaveResultImpl.noChange();
} else {
result = PlayerSaveResultImpl.usernameUpdated(oldUsername);
}
return result;
}
private final Set<Status> status;
@Nullable private final String oldUsername;
@Nullable private final Set<UUID> otherUuids;
private PlayerSaveResultImpl(EnumSet<Status> status, @Nullable String oldUsername, @Nullable Set<UUID> otherUuids) {
this.status = ImmutableSet.copyOf(status);
this.oldUsername = oldUsername;
this.otherUuids = otherUuids;
}
private PlayerSaveResultImpl(Status status) {
this(EnumSet.of(status), null, null);
}
/**
* Returns a new {@link PlayerSaveResultImpl} with the {@link Status#OTHER_UUIDS_PRESENT_FOR_USERNAME}
* status attached to the state of this result.
*
* @param otherUuids the other uuids
* @return a new result
*/
public PlayerSaveResultImpl withOtherUuidsPresent(@Nonnull Set<UUID> otherUuids) {
EnumSet<Status> status = EnumSet.copyOf(this.status);
status.add(Status.OTHER_UUIDS_PRESENT_FOR_USERNAME);
return new PlayerSaveResultImpl(status, this.oldUsername, ImmutableSet.copyOf(otherUuids));
}
@Nonnull
@Override
public Set<Status> getStatus() {
return this.status;
}
@Override
public boolean includes(@Nonnull Status status) {
return this.status.contains(status);
}
@Nullable
@Override
public String getOldUsername() {
return this.oldUsername;
}
@Nullable
@Override
public Set<UUID> getOtherUuids() {
return this.otherUuids;
}
@Override
public boolean equals(Object that) {
if (this == that) return true;
if (that == null || getClass() != that.getClass()) return false;
PlayerSaveResultImpl result = (PlayerSaveResultImpl) that;
return Objects.equals(this.status, result.status) &&
Objects.equals(this.oldUsername, result.oldUsername) &&
Objects.equals(this.otherUuids, result.otherUuids);
}
@Override
public int hashCode() {
return Objects.hash(this.status, this.oldUsername, this.otherUuids);
}
}

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.common.storage;
import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.api.event.cause.CreationCause;
import me.lucko.luckperms.api.event.cause.DeletionCause;
import me.lucko.luckperms.common.actionlog.Log;
@ -56,8 +57,6 @@ public interface Storage {
String getName();
Storage noBuffer();
void init();
void shutdown();

View File

@ -27,6 +27,7 @@ package me.lucko.luckperms.common.storage.dao;
import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.common.actionlog.Log;
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
import me.lucko.luckperms.common.bulkupdate.comparisons.Constraint;
@ -34,7 +35,6 @@ import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.PlayerSaveResult;
import java.util.Collections;
import java.util.List;

View File

@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.common.actionlog.Log;
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
import me.lucko.luckperms.common.bulkupdate.comparisons.Constraint;
@ -36,7 +37,6 @@ import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.PlayerSaveResult;
import me.lucko.luckperms.common.storage.SplitStorageType;
import me.lucko.luckperms.common.storage.StorageType;

View File

@ -32,6 +32,7 @@ import com.google.common.collect.Maps;
import me.lucko.luckperms.api.ChatMetaType;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.common.actionlog.Log;
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
@ -45,7 +46,6 @@ import me.lucko.luckperms.common.node.factory.NodeFactory;
import me.lucko.luckperms.common.node.model.NodeDataContainer;
import me.lucko.luckperms.common.node.utils.MetaType;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.PlayerSaveResult;
import me.lucko.luckperms.common.storage.dao.AbstractDao;
import me.lucko.luckperms.common.storage.dao.file.loader.ConfigurateLoader;
import me.lucko.luckperms.common.storage.dao.file.loader.JsonLoader;

View File

@ -30,7 +30,8 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;
import me.lucko.luckperms.common.storage.PlayerSaveResult;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.common.storage.PlayerSaveResultImpl;
import me.lucko.luckperms.common.utils.Uuids;
import java.io.BufferedReader;
@ -104,7 +105,7 @@ public class FileUuidCache {
// perform the insert
String oldUsername = this.lookupMap.put(uuid, username);
PlayerSaveResult result = PlayerSaveResult.determineBaseResult(username, oldUsername);
PlayerSaveResultImpl result = PlayerSaveResultImpl.determineBaseResult(username, oldUsername);
Set<UUID> conflicting = new HashSet<>(this.lookupMap.lookupUuid(username));
conflicting.remove(uuid);

View File

@ -40,6 +40,7 @@ import com.mongodb.client.model.UpdateOptions;
import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.api.context.ContextSet;
import me.lucko.luckperms.api.context.ImmutableContextSet;
import me.lucko.luckperms.api.context.MutableContextSet;
@ -59,7 +60,7 @@ import me.lucko.luckperms.common.node.factory.NodeFactory;
import me.lucko.luckperms.common.node.model.NodeDataContainer;
import me.lucko.luckperms.common.node.model.NodeHeldPermission;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.PlayerSaveResult;
import me.lucko.luckperms.common.storage.PlayerSaveResultImpl;
import me.lucko.luckperms.common.storage.StorageCredentials;
import me.lucko.luckperms.common.storage.dao.AbstractDao;
@ -582,7 +583,7 @@ public class MongoDao extends AbstractDao {
c.replaceOne(new Document("_id", uuid), new Document("_id", uuid).append("name", username), new UpdateOptions().upsert(true));
}
PlayerSaveResult result = PlayerSaveResult.determineBaseResult(username, oldUsername);
PlayerSaveResultImpl result = PlayerSaveResultImpl.determineBaseResult(username, oldUsername);
Set<UUID> conflicting = new HashSet<>();
try (MongoCursor<Document> cursor = c.find(new Document("name", username)).iterator()) {

View File

@ -32,6 +32,7 @@ import com.google.gson.reflect.TypeToken;
import me.lucko.luckperms.api.HeldPermission;
import me.lucko.luckperms.api.LogEntry;
import me.lucko.luckperms.api.Node;
import me.lucko.luckperms.api.PlayerSaveResult;
import me.lucko.luckperms.common.actionlog.ExtendedLogEntry;
import me.lucko.luckperms.common.actionlog.Log;
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
@ -49,7 +50,7 @@ import me.lucko.luckperms.common.node.factory.NodeFactory;
import me.lucko.luckperms.common.node.model.NodeDataContainer;
import me.lucko.luckperms.common.node.model.NodeHeldPermission;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.storage.PlayerSaveResult;
import me.lucko.luckperms.common.storage.PlayerSaveResultImpl;
import me.lucko.luckperms.common.storage.dao.AbstractDao;
import me.lucko.luckperms.common.storage.dao.sql.connection.AbstractConnectionFactory;
import me.lucko.luckperms.common.storage.dao.sql.connection.file.SQLiteConnectionFactory;
@ -932,7 +933,7 @@ public class SqlDao extends AbstractDao {
}
}
PlayerSaveResult result = PlayerSaveResult.determineBaseResult(username, oldUsername);
PlayerSaveResultImpl result = PlayerSaveResultImpl.determineBaseResult(username, oldUsername);
Set<UUID> conflicting = new HashSet<>();
try (Connection c = this.provider.getConnection()) {

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -266,7 +266,7 @@ public class LPNukkitPlugin extends AbstractLuckPermsPlugin {
final User user = getUserManager().getIfLoaded(player.getUniqueId());
if (user != null) {
user.getCachedData().invalidateCaches();
user.getCachedData().invalidate();
getUserManager().unload(user);
}
}

View File

@ -6,7 +6,7 @@
<groupId>me.lucko.luckperms</groupId>
<artifactId>luckperms</artifactId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
<modules>
<module>api</module>
@ -55,7 +55,7 @@
<maven.test.skip>true</maven.test.skip>
<!-- Manually entered release version -->
<release.version>4.1</release.version>
<release.version>4.2</release.version>
<!-- Get how many commits have been made since the last tag (the previous release) -->
<patch.version>${git.closest.tag.commit.count}</patch.version>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>luckperms</artifactId>
<groupId>me.lucko.luckperms</groupId>
<version>4.1-SNAPSHOT</version>
<version>4.2-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -321,7 +321,7 @@ public abstract class CalculatedSubject implements LPSubject {
@Override
public void invalidateCaches() {
this.cachedData.invalidateCaches();
this.cachedData.invalidate();
}
}

View File

@ -161,7 +161,7 @@ public abstract class HolderSubject<T extends PermissionHolder> implements LPSub
@Override
public void invalidateCaches() {
// invalidate for all changes
this.parent.getCachedData().invalidateCaches();
this.parent.getCachedData().invalidate();
}
}