More work

This commit is contained in:
Luck 2019-10-06 21:34:24 +01:00
parent 72dec16f54
commit fd954d8293
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
123 changed files with 680 additions and 1098 deletions

View File

@ -60,10 +60,10 @@ public interface ActionLog {
/**
* Gets the log content for a given user
*
* @param uuid the uuid to filter by
* @param uniqueId the uuid to filter by
* @return all content in this log where the user = uuid
*/
@NonNull SortedSet<Action> getUserHistory(@NonNull UUID uuid);
@NonNull SortedSet<Action> getUserHistory(@NonNull UUID uniqueId);
/**
* Gets the log content for a given group

View File

@ -200,7 +200,7 @@ public interface PermissionHolder {
* @return a Tristate for the holders permission status for the node
* @throws NullPointerException if the node is null
*/
@NonNull Tristate hasNode(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate);
@NonNull Tristate containsNode(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate);
/**
* Sets a permission node for the permission holder.
@ -462,18 +462,6 @@ public interface PermissionHolder {
* <p>This method is called periodically by the platform, so it is only necessary to run
* if you want to guarantee that the current data is totally up-to-date.</p>
*/
void auditTemporaryPermissions();
/**
* Checks to see if the object inherits a certain permission.
*
* <p>Although this method is named inheritsPermission, it can be used for all node types.</p>
*
* @param node the node to check for
* @param equalityPredicate how to determine if a node matches
* @return a Tristate for the holders inheritance status for the node
* @throws NullPointerException if the node is null
*/
@NonNull Tristate inheritsNode(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate);
void auditTemporaryNodes();
}

View File

@ -25,8 +25,8 @@
package net.luckperms.api.model.group;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.model.PermissionHolder;
import net.luckperms.api.query.QueryOptions;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -63,10 +63,10 @@ public interface Group extends PermissionHolder {
* <p>Will return <code>null</code> if the groups display name is equal to it's
* {@link #getName() actual name}.</p>
*
* @param contextSet the contexts to lookup in
* @param queryOptions the query options to lookup in
* @return the display name
*/
@Nullable String getDisplayName(@NonNull ContextSet contextSet);
@Nullable String getDisplayName(@NonNull QueryOptions queryOptions);
/**
* Gets the weight of this group, if present.

View File

@ -59,22 +59,22 @@ public interface UserManager {
/**
* Loads a user from the plugin's storage provider into memory.
*
* @param uuid the uuid of the user
* @param uniqueId the uuid of the user
* @param username the username, if known
* @return the resultant user
* @throws NullPointerException if the uuid is null
*/
@NonNull CompletableFuture<User> loadUser(@NonNull UUID uuid, @Nullable String username);
@NonNull CompletableFuture<User> loadUser(@NonNull UUID uniqueId, @Nullable String username);
/**
* Loads a user from the plugin's storage provider into memory.
*
* @param uuid the uuid of the user
* @param uniqueId the uuid of the user
* @return the resultant user
* @throws NullPointerException if the uuid is null
*/
default @NonNull CompletableFuture<User> loadUser(@NonNull UUID uuid) {
return loadUser(uuid, null);
default @NonNull CompletableFuture<User> loadUser(@NonNull UUID uniqueId) {
return loadUser(uniqueId, null);
}
/**
@ -92,12 +92,12 @@ public interface UserManager {
/**
* Uses the LuckPerms cache to find a username for the given uuid.
*
* @param uuid the uuid
* @param uniqueId the uuid
* @return a username, could be null
* @throws NullPointerException if either parameters are null
* @throws IllegalArgumentException if the username is invalid
*/
@NonNull CompletableFuture<String> lookupUsername(@NonNull UUID uuid);
@NonNull CompletableFuture<String> lookupUsername(@NonNull UUID uniqueId);
/**
* Saves a user's data back to the plugin's storage provider.
@ -114,13 +114,13 @@ public interface UserManager {
/**
* Saves data about a player to the uuid caching system.
*
* @param uuid the users mojang unique id
* @param uniqueId 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
*/
@NonNull CompletableFuture<PlayerSaveResult> savePlayerData(@NonNull UUID uuid, @NonNull String username);
@NonNull CompletableFuture<PlayerSaveResult> savePlayerData(@NonNull UUID uniqueId, @NonNull String username);
/**
* Gets a set all "unique" user UUIDs.
@ -143,11 +143,11 @@ public interface UserManager {
/**
* Gets a loaded user.
*
* @param uuid the uuid of the user to get
* @param uniqueId 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);
@Nullable User getUser(@NonNull UUID uniqueId);
/**
* Gets a loaded user.
@ -168,11 +168,11 @@ public interface UserManager {
/**
* Check if a user is loaded in memory
*
* @param uuid the uuid to check for
* @param uniqueId the uuid to check for
* @return true if the user is loaded
* @throws NullPointerException if the uuid is null
*/
boolean isLoaded(@NonNull UUID uuid);
boolean isLoaded(@NonNull UUID uniqueId);
/**
* Unload a user from the internal storage, if they're not currently online.

View File

@ -87,9 +87,13 @@ public enum DataQueryOrder implements Comparator<DataType> {
private static final List<DataType> TRANSIENT_LAST_LIST = Collections.unmodifiableList(Arrays.asList(DataType.NORMAL, DataType.TRANSIENT));
/**
* Gets a {@link List} of all {@link DataType}s, in the order defined by
* Gets a {@link List} of all {@link DataType}s, in order of greatest to least, as defined by
* the {@code comparator}.
*
* <p>Equivalent to calling {@link Arrays#sort(Object[], Comparator)} on
* {@link DataType#values()}, but with the comparator
* {@link Comparator#reversed() reversed}.</p>
*
* @param comparator the comparator
* @return the ordered data types
*/

View File

@ -57,7 +57,7 @@ public class BukkitSenderFactory extends SenderFactory<CommandSender> {
}
@Override
protected UUID getUuid(CommandSender sender) {
protected UUID getUniqueId(CommandSender sender) {
if (sender instanceof Player) {
return ((Player) sender).getUniqueId();
}

View File

@ -224,19 +224,19 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
}
@Override
public Optional<Player> getPlayer(UUID uuid) {
return Optional.ofNullable(getServer().getPlayer(uuid));
public Optional<Player> getPlayer(UUID uniqueId) {
return Optional.ofNullable(getServer().getPlayer(uniqueId));
}
@Override
public Optional<UUID> lookupUuid(String username) {
public Optional<UUID> lookupUniqueId(String username) {
//noinspection deprecation
return Optional.ofNullable(getServer().getOfflinePlayer(username)).map(OfflinePlayer::getUniqueId);
}
@Override
public Optional<String> lookupUsername(UUID uuid) {
return Optional.ofNullable(getServer().getOfflinePlayer(uuid)).map(OfflinePlayer::getName);
public Optional<String> lookupUsername(UUID uniqueId) {
return Optional.ofNullable(getServer().getOfflinePlayer(uniqueId)).map(OfflinePlayer::getName);
}
@Override
@ -255,8 +255,8 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
}
@Override
public boolean isPlayerOnline(UUID uuid) {
Player player = getServer().getPlayer(uuid);
public boolean isPlayerOnline(UUID uniqueId) {
Player player = getServer().getPlayer(uniqueId);
return player != null && player.isOnline();
}

View File

@ -268,7 +268,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
getApiProvider().getEventBus().subscribe(UserDataRecalculateEvent.class, event -> {
User user = ApiUser.cast(event.getUser());
Optional<Player> player = getBootstrap().getPlayer(user.getUuid());
Optional<Player> player = getBootstrap().getPlayer(user.getUniqueId());
player.ifPresent(p -> refreshAutoOp(p, false));
});
}
@ -312,7 +312,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
final User user = getUserManager().getIfLoaded(player.getUniqueId());
if (user != null) {
user.getCachedData().invalidate();
getUserManager().unload(user);
getUserManager().unload(user.getUniqueId());
}
}
@ -361,7 +361,7 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
@Override
public Optional<QueryOptions> getQueryOptionsForUser(User user) {
return this.bootstrap.getPlayer(user.getUuid()).map(player -> this.contextManager.getQueryOptions(player));
return this.bootstrap.getPlayer(user.getUniqueId()).map(player -> this.contextManager.getQueryOptions(player));
}
@Override

View File

@ -191,7 +191,7 @@ public class LPPermissionAttachment extends PermissionAttachment {
// set the transient node
User user = this.permissible.getUser();
user.setPermission(DataType.TRANSIENT, node, true);
user.setNode(DataType.TRANSIENT, node, true);
}
private void unsetPermissionInternal(String name) {

View File

@ -191,7 +191,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
if (p.name().isEmpty()) {
continue;
}
holder.setPermission(DataType.NORMAL, NodeBuilders.determineMostApplicable(p.name()).value(p.isTrue()).withContext(DefaultContextKeys.SERVER_KEY, "global").withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
holder.setNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(p.name()).value(p.isTrue()).withContext(DefaultContextKeys.SERVER_KEY, "global").withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
// Include any child permissions
for (Map.Entry<String, Boolean> child : p.getChildren().entrySet()) {
@ -199,7 +199,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
continue;
}
holder.setPermission(DataType.NORMAL, NodeBuilders.determineMostApplicable(child.getKey()).value((boolean) child.getValue()).withContext(DefaultContextKeys.SERVER_KEY, "global").withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
holder.setNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(child.getKey()).value((boolean) child.getValue()).withContext(DefaultContextKeys.SERVER_KEY, "global").withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
}
}
@ -210,7 +210,7 @@ public class MigrationBPermissions extends SubCommand<Object> {
parentName = GroupManager.DEFAULT_GROUP_NAME;
}
holder.setPermission(DataType.NORMAL, Inheritance.builder(parentName).value(true).withContext(DefaultContextKeys.SERVER_KEY, "global").withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
holder.setNode(DataType.NORMAL, Inheritance.builder(parentName).value(true).withContext(DefaultContextKeys.SERVER_KEY, "global").withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
});
// Migrate existing meta
@ -220,16 +220,16 @@ public class MigrationBPermissions extends SubCommand<Object> {
}
if (meta.getKey().equalsIgnoreCase("prefix")) {
holder.setPermission(DataType.NORMAL, Prefix.builder(c.getPriority(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
holder.setNode(DataType.NORMAL, Prefix.builder(c.getPriority(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
continue;
}
if (meta.getKey().equalsIgnoreCase("suffix")) {
holder.setPermission(DataType.NORMAL, Suffix.builder(c.getPriority(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
holder.setNode(DataType.NORMAL, Suffix.builder(c.getPriority(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
continue;
}
holder.setPermission(DataType.NORMAL, Meta.builder(meta.getKey(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
holder.setNode(DataType.NORMAL, Meta.builder(meta.getKey(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true);
}
}
}

View File

@ -107,11 +107,11 @@ public class MigrationGroupManager extends SubCommand<Object> {
for (String node : g.getPermissionList()) {
if (node.isEmpty()) continue;
group.setPermission(DataType.NORMAL, MigrationUtils.parseNode(node, true).build(), true);
group.setNode(DataType.NORMAL, MigrationUtils.parseNode(node, true).build(), true);
}
for (String s : g.getInherits()) {
if (s.isEmpty()) continue;
group.setPermission(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(s)).build(), true);
group.setNode(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(s)).build(), true);
}
plugin.getStorage().saveGroup(group);
@ -231,7 +231,7 @@ public class MigrationGroupManager extends SubCommand<Object> {
Group group = plugin.getStorage().createAndLoadGroup(e.getKey(), CreationCause.INTERNAL).join();
for (Node node : e.getValue()) {
group.setPermission(DataType.NORMAL, node, true);
group.setNode(DataType.NORMAL, node, true);
}
plugin.getStorage().saveGroup(group);
@ -242,17 +242,17 @@ public class MigrationGroupManager extends SubCommand<Object> {
log.log("Starting user migration.");
AtomicInteger userCount = new AtomicInteger(0);
Iterators.tryIterate(users.entrySet(), e -> {
User user = plugin.getStorage().loadUser(e.getKey().getUuid(), e.getKey().getUsername().orElse(null)).join();
User user = plugin.getStorage().loadUser(e.getKey().getUniqueId(), e.getKey().getUsername().orElse(null)).join();
for (Node node : e.getValue()) {
user.setPermission(DataType.NORMAL, node, true);
user.setNode(DataType.NORMAL, node, true);
}
String primaryGroup = primaryGroups.get(e.getKey().getUuid());
String primaryGroup = primaryGroups.get(e.getKey().getUniqueId());
if (primaryGroup != null && !primaryGroup.isEmpty()) {
user.setPermission(DataType.NORMAL, Inheritance.builder(primaryGroup).build(), true);
user.setNode(DataType.NORMAL, Inheritance.builder(primaryGroup).build(), true);
user.getPrimaryGroup().setStoredValue(primaryGroup);
user.unsetPermission(DataType.NORMAL, Inheritance.builder(me.lucko.luckperms.common.model.manager.group.GroupManager.DEFAULT_GROUP_NAME).build());
user.unsetNode(DataType.NORMAL, Inheritance.builder(me.lucko.luckperms.common.model.manager.group.GroupManager.DEFAULT_GROUP_NAME).build());
}
plugin.getStorage().saveUser(user);

View File

@ -132,7 +132,7 @@ public class MigrationPermissionsBukkit extends SubCommand<Object> {
ConfigurationSection permsSection = data.getConfigurationSection("permissions");
for (String perm : permsSection.getKeys(false)) {
boolean value = permsSection.getBoolean(perm);
holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, value).build(), true);
holder.setNode(DataType.NORMAL, MigrationUtils.parseNode(perm, value).build(), true);
}
}
@ -143,7 +143,7 @@ public class MigrationPermissionsBukkit extends SubCommand<Object> {
ConfigurationSection permsSection = worldSection.getConfigurationSection(world);
for (String perm : permsSection.getKeys(false)) {
boolean value = permsSection.getBoolean(perm);
holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, value).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true);
holder.setNode(DataType.NORMAL, MigrationUtils.parseNode(perm, value).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true);
}
}
}
@ -153,13 +153,13 @@ public class MigrationPermissionsBukkit extends SubCommand<Object> {
if (data.isList("groups")) {
List<String> groups = data.getStringList("groups");
for (String group : groups) {
holder.setPermission(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(group)).build(), true);
holder.setNode(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(group)).build(), true);
}
}
if (data.isList("inheritance")) {
List<String> groups = data.getStringList("inheritance");
for (String group : groups) {
holder.setPermission(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(group)).build(), true);
holder.setNode(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(group)).build(), true);
}
}
}

View File

@ -205,7 +205,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
String world = standardizeWorld(worldData.getKey());
for (String node : worldData.getValue()) {
if (node.isEmpty()) continue;
holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(node, true).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true);
holder.setNode(DataType.NORMAL, MigrationUtils.parseNode(node, true).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true);
}
}
@ -227,7 +227,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
for (String node : worldData.getValue()) {
if (node.isEmpty()) continue;
long expiry = timedPermissionsTime.getOrDefault(Strings.nullToEmpty(world) + ":" + node, 0L);
holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(node, true).withContext(DefaultContextKeys.WORLD_KEY, world).expiry(expiry).build(), true);
holder.setNode(DataType.NORMAL, MigrationUtils.parseNode(node, true).withContext(DefaultContextKeys.WORLD_KEY, world).expiry(expiry).build(), true);
}
}
@ -255,7 +255,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
}
}
holder.setPermission(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(parentName)).withContext(DefaultContextKeys.WORLD_KEY, world).expiry(expiry).build(), true);
holder.setNode(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(parentName)).withContext(DefaultContextKeys.WORLD_KEY, world).expiry(expiry).build(), true);
// migrate primary groups
if (world == null && holder instanceof User && expiry == 0) {
@ -269,7 +269,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
if (primary != null && !primary.isEmpty() && !primary.equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME)) {
User user = ((User) holder);
user.getPrimaryGroup().setStoredValue(primary);
holder.unsetPermission(DataType.NORMAL, Inheritance.builder(GroupManager.DEFAULT_GROUP_NAME).build());
holder.unsetNode(DataType.NORMAL, Inheritance.builder(GroupManager.DEFAULT_GROUP_NAME).build());
}
}
@ -278,11 +278,11 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
String suffix = entity.getOwnSuffix();
if (prefix != null && !prefix.isEmpty()) {
holder.setPermission(DataType.NORMAL, Prefix.builder(weight, prefix).build(), true);
holder.setNode(DataType.NORMAL, Prefix.builder(weight, prefix).build(), true);
}
if (suffix != null && !suffix.isEmpty()) {
holder.setPermission(DataType.NORMAL, Suffix.builder(weight, suffix).build(), true);
holder.setNode(DataType.NORMAL, Suffix.builder(weight, suffix).build(), true);
}
// migrate options
@ -307,7 +307,7 @@ public class MigrationPermissionsEx extends SubCommand<Object> {
continue;
}
holder.setPermission(DataType.NORMAL, Meta.builder(opt.getKey(), opt.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true);
holder.setNode(DataType.NORMAL, Meta.builder(opt.getKey(), opt.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true);
}
}
}

View File

@ -177,7 +177,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
}
for (Group parent : g.getParents()) {
group.setPermission(DataType.NORMAL, Inheritance.builder(parent.getName().toLowerCase()).build(), true);
group.setNode(DataType.NORMAL, Inheritance.builder(parent.getName().toLowerCase()).build(), true);
}
// server --> prefix afaik
@ -190,9 +190,9 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
}
if (server != null) {
group.setPermission(DataType.NORMAL, Prefix.builder(g.getRank(), prefix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true);
group.setNode(DataType.NORMAL, Prefix.builder(g.getRank(), prefix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true);
} else {
group.setPermission(DataType.NORMAL, Prefix.builder(g.getRank(), prefix.getValue()).build(), true);
group.setNode(DataType.NORMAL, Prefix.builder(g.getRank(), prefix.getValue()).build(), true);
}
}
@ -205,9 +205,9 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
}
if (server != null) {
group.setPermission(DataType.NORMAL, Suffix.builder(g.getRank(), suffix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true);
group.setNode(DataType.NORMAL, Suffix.builder(g.getRank(), suffix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true);
} else {
group.setPermission(DataType.NORMAL, Suffix.builder(g.getRank(), suffix.getValue()).build(), true);
group.setNode(DataType.NORMAL, Suffix.builder(g.getRank(), suffix.getValue()).build(), true);
}
}
@ -252,18 +252,18 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
String suffix = joinFuture(pm.getPlayerOwnSuffix(uuid));
if (prefix != null && !prefix.isEmpty()) {
user.setPermission(DataType.NORMAL, Prefix.builder(maxWeight.get(), prefix).build(), true);
user.setNode(DataType.NORMAL, Prefix.builder(maxWeight.get(), prefix).build(), true);
}
if (suffix != null && !suffix.isEmpty()) {
user.setPermission(DataType.NORMAL, Suffix.builder(maxWeight.get(), suffix).build(), true);
user.setNode(DataType.NORMAL, Suffix.builder(maxWeight.get(), suffix).build(), true);
}
Group primaryGroup = joinFuture(pm.getPlayerPrimaryGroup(uuid));
if (primaryGroup != null && primaryGroup.getName() != null) {
String primary = primaryGroup.getName().toLowerCase();
if (!primary.equals(GroupManager.DEFAULT_GROUP_NAME)) {
user.setPermission(DataType.NORMAL, Inheritance.builder(primary).build(), true);
user.setNode(DataType.NORMAL, Inheritance.builder(primary).build(), true);
user.getPrimaryGroup().setStoredValue(primary);
}
}
@ -314,7 +314,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
if (server != null) nb.withContext(DefaultContextKeys.SERVER_KEY, server);
if (world != null) nb.withContext(DefaultContextKeys.WORLD_KEY, world);
holder.setPermission(DataType.NORMAL, nb.build(), true);
holder.setNode(DataType.NORMAL, nb.build(), true);
}
private void applyGroup(PermissionManager pm, PermissionHolder holder, CachedGroup g, String server) {
@ -335,7 +335,7 @@ public class MigrationPowerfulPerms extends SubCommand<Object> {
nb.withContext(DefaultContextKeys.SERVER_KEY, server);
}
holder.setPermission(DataType.NORMAL, nb.build(), true);
holder.setNode(DataType.NORMAL, nb.build(), true);
}
private static <T> T joinFuture(Future<T> future) {

View File

@ -181,7 +181,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
// migrate groups
Set<Node> parents = userParents.get(u);
if (parents != null) {
parents.forEach(node -> user.setPermission(DataType.NORMAL, node, true));
parents.forEach(node -> user.setNode(DataType.NORMAL, node, true));
}
user.getPrimaryGroup().setStoredValue(MigrationUtils.standardizeName(service.getPlayerPrimaryGroup(u)));
@ -201,9 +201,9 @@ public class MigrationZPermissions extends SubCommand<Object> {
if (e.getPermission().isEmpty()) continue;
if (e.getWorld() != null && !e.getWorld().getName().equals("")) {
holder.setPermission(DataType.NORMAL, NodeBuilders.determineMostApplicable(e.getPermission()).value(e.isValue()).withContext(DefaultContextKeys.WORLD_KEY, e.getWorld().getName()).build(), true);
holder.setNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(e.getPermission()).value(e.isValue()).withContext(DefaultContextKeys.WORLD_KEY, e.getWorld().getName()).build(), true);
} else {
holder.setPermission(DataType.NORMAL, NodeBuilders.determineMostApplicable(e.getPermission()).value(e.isValue()).build(), true);
holder.setNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(e.getPermission()).value(e.isValue()).build(), true);
}
}
@ -211,7 +211,7 @@ public class MigrationZPermissions extends SubCommand<Object> {
if (entity.isGroup()) {
for (PermissionEntity inheritance : entity.getParents()) {
if (!inheritance.getDisplayName().equals(holder.getObjectName())) {
holder.setPermission(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(inheritance.getDisplayName())).build(), true);
holder.setNode(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(inheritance.getDisplayName())).build(), true);
}
}
}
@ -226,11 +226,11 @@ public class MigrationZPermissions extends SubCommand<Object> {
if (valueString.isEmpty()) continue;
if (key.equals("prefix")) {
holder.setPermission(DataType.NORMAL, Prefix.builder(weight, valueString).build(), true);
holder.setNode(DataType.NORMAL, Prefix.builder(weight, valueString).build(), true);
} else if (key.equals("suffix")) {
holder.setPermission(DataType.NORMAL, Suffix.builder(weight, valueString).build(), true);
holder.setNode(DataType.NORMAL, Suffix.builder(weight, valueString).build(), true);
} else {
holder.setPermission(DataType.NORMAL, Meta.builder(key, valueString).build(), true);
holder.setNode(DataType.NORMAL, Meta.builder(key, valueString).build(), true);
}
}
}

View File

@ -283,7 +283,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
chatMetaNode.withContext(DefaultContextKeys.WORLD_KEY, world);
// assume success
holder.setPermission(DataType.NORMAL, chatMetaNode.build(), true);
holder.setNode(DataType.NORMAL, chatMetaNode.build(), true);
this.vaultPermission.holderSave(holder);
}
@ -312,7 +312,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat {
metaNode.withContext(DefaultContextKeys.WORLD_KEY, world);
// assume success
holder.setPermission(DataType.NORMAL, metaNode.build(), true);
holder.setNode(DataType.NORMAL, metaNode.build(), true);
this.vaultPermission.holderSave(holder);
}

View File

@ -49,7 +49,6 @@ import net.luckperms.api.context.ContextSet;
import net.luckperms.api.context.DefaultContextKeys;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.model.DataType;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.Tristate;
import net.luckperms.api.query.Flag;
import net.luckperms.api.query.QueryOptions;
@ -127,9 +126,9 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
}
// lookup a username from the database
uuid = this.plugin.getStorage().getPlayerUuid(player.toLowerCase()).join();
uuid = this.plugin.getStorage().getPlayerUniqueId(player.toLowerCase()).join();
if (uuid == null) {
uuid = this.plugin.getBootstrap().lookupUuid(player).orElse(null);
uuid = this.plugin.getBootstrap().lookupUniqueId(player).orElse(null);
}
// unable to find a user, throw an exception
@ -264,9 +263,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
PermissionHolder user = lookupUser(uuid);
ContextSet contexts = getQueryOptions(uuid, world).context();
String[] ret = user.normalData().immutable().values().stream()
.filter(NodeType.INHERITANCE::matches)
.map(NodeType.INHERITANCE::cast)
String[] ret = user.normalData().immutableInheritance().values().stream()
.filter(n -> n.shouldApplyWithContext(contexts))
.map(n -> {
Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName());
@ -441,7 +438,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
logMsg("#holderAddPermission: %s - %s - %s", holder.getPlainDisplayName(), permission, world);
}
if (((Result) holder.setPermission(DataType.NORMAL, NodeBuilders.determineMostApplicable(permission).value(true).withContext(DefaultContextKeys.SERVER_KEY, getVaultServer()).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true)).wasSuccessful()) {
if (((Result) holder.setNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(permission).value(true).withContext(DefaultContextKeys.SERVER_KEY, getVaultServer()).withContext(DefaultContextKeys.WORLD_KEY, world).build(), true)).wasSuccessful()) {
return holderSave(holder);
}
return false;
@ -455,7 +452,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission {
logMsg("#holderRemovePermission: %s - %s - %s", holder.getPlainDisplayName(), permission, world);
}
if (holder.unsetPermission(DataType.NORMAL, NodeBuilders.determineMostApplicable(permission).withContext(DefaultContextKeys.SERVER_KEY, getVaultServer()).withContext(DefaultContextKeys.WORLD_KEY, world).build()).wasSuccessful()) {
if (holder.unsetNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(permission).withContext(DefaultContextKeys.SERVER_KEY, getVaultServer()).withContext(DefaultContextKeys.WORLD_KEY, world).build()).wasSuccessful()) {
return holderSave(holder);
}
return false;

View File

@ -53,7 +53,7 @@ public class BungeeSenderFactory extends SenderFactory<CommandSender> {
}
@Override
protected UUID getUuid(CommandSender sender) {
protected UUID getUniqueId(CommandSender sender) {
if (sender instanceof ProxiedPlayer) {
return ((ProxiedPlayer) sender).getUniqueId();
}

View File

@ -182,12 +182,12 @@ public class LPBungeeBootstrap extends Plugin implements LuckPermsBootstrap {
}
@Override
public Optional<ProxiedPlayer> getPlayer(UUID uuid) {
return Optional.ofNullable(getProxy().getPlayer(uuid));
public Optional<ProxiedPlayer> getPlayer(UUID uniqueId) {
return Optional.ofNullable(getProxy().getPlayer(uniqueId));
}
@Override
public Optional<UUID> lookupUuid(String username) {
public Optional<UUID> lookupUniqueId(String username) {
if (getProxy().getPluginManager().getPlugin("RedisBungee") != null) {
try {
return RedisBungeeUtil.lookupUuid(username);
@ -200,10 +200,10 @@ public class LPBungeeBootstrap extends Plugin implements LuckPermsBootstrap {
}
@Override
public Optional<String> lookupUsername(UUID uuid) {
public Optional<String> lookupUsername(UUID uniqueId) {
if (getProxy().getPluginManager().getPlugin("RedisBungee") != null) {
try {
return RedisBungeeUtil.lookupUsername(uuid);
return RedisBungeeUtil.lookupUsername(uniqueId);
} catch (Throwable t) {
t.printStackTrace();
}
@ -228,8 +228,8 @@ public class LPBungeeBootstrap extends Plugin implements LuckPermsBootstrap {
}
@Override
public boolean isPlayerOnline(UUID uuid) {
ProxiedPlayer player = getProxy().getPlayer(uuid);
public boolean isPlayerOnline(UUID uniqueId) {
ProxiedPlayer player = getProxy().getPlayer(uniqueId);
return player != null && player.isConnected();
}
}

View File

@ -189,7 +189,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin {
@Override
public Optional<QueryOptions> getQueryOptionsForUser(User user) {
return this.bootstrap.getPlayer(user.getUuid()).map(player -> this.contextManager.getQueryOptions(player));
return this.bootstrap.getPlayer(user.getUniqueId()).map(player -> this.contextManager.getQueryOptions(player));
}
@Override

View File

@ -135,21 +135,21 @@ public class MigrationBungeePerms extends SubCommand<Object> {
// Migrate global perms
for (String perm : entity.getPerms()) {
if (perm.isEmpty()) continue;
holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, true).build(), true);
holder.setNode(DataType.NORMAL, MigrationUtils.parseNode(perm, true).build(), true);
}
// Migrate per-server perms
for (Map.Entry<String, Server> e : entity.getServers().entrySet()) {
for (String perm : e.getValue().getPerms()) {
if (perm.isEmpty()) continue;
holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, true).withContext(DefaultContextKeys.SERVER_KEY, e.getKey()).build(), true);
holder.setNode(DataType.NORMAL, MigrationUtils.parseNode(perm, true).withContext(DefaultContextKeys.SERVER_KEY, e.getKey()).build(), true);
}
// Migrate per-world perms
for (Map.Entry<String, World> we : e.getValue().getWorlds().entrySet()) {
for (String perm : we.getValue().getPerms()) {
if (perm.isEmpty()) continue;
holder.setPermission(DataType.NORMAL, MigrationUtils.parseNode(perm, true).withContext(DefaultContextKeys.SERVER_KEY, e.getKey()).withContext(DefaultContextKeys.WORLD_KEY, we.getKey()).build(), true);
holder.setNode(DataType.NORMAL, MigrationUtils.parseNode(perm, true).withContext(DefaultContextKeys.SERVER_KEY, e.getKey()).withContext(DefaultContextKeys.WORLD_KEY, we.getKey()).build(), true);
}
}
}
@ -157,7 +157,7 @@ public class MigrationBungeePerms extends SubCommand<Object> {
// Migrate any parent groups
for (String inherit : parents) {
if (inherit.isEmpty()) continue;
holder.setPermission(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(inherit)).build(), true);
holder.setNode(DataType.NORMAL, Inheritance.builder(MigrationUtils.standardizeName(inherit)).build(), true);
}
// Migrate prefix and suffix
@ -165,10 +165,10 @@ public class MigrationBungeePerms extends SubCommand<Object> {
String suffix = entity.getSuffix();
if (prefix != null && !prefix.isEmpty()) {
holder.setPermission(DataType.NORMAL, Prefix.builder(weight, prefix).build(), true);
holder.setNode(DataType.NORMAL, Prefix.builder(weight, prefix).build(), true);
}
if (suffix != null && !suffix.isEmpty()) {
holder.setPermission(DataType.NORMAL, Suffix.builder(weight, suffix).build(), true);
holder.setNode(DataType.NORMAL, Suffix.builder(weight, suffix).build(), true);
}
}
}

View File

@ -67,10 +67,10 @@ public class Log {
.collect(Collectors.toCollection(TreeSet::new));
}
public SortedSet<LoggedAction> getUserHistory(UUID uuid) {
public SortedSet<LoggedAction> getUserHistory(UUID uniqueId) {
return this.content.stream()
.filter(e -> e.getTarget().getType() == Action.Target.Type.USER)
.filter(e -> e.getTarget().getUniqueId().isPresent() && e.getTarget().getUniqueId().get().equals(uuid))
.filter(e -> e.getTarget().getUniqueId().isPresent() && e.getTarget().getUniqueId().get().equals(uniqueId))
.collect(ImmutableCollectors.toSortedSet(Comparator.naturalOrder()));
}

View File

@ -49,7 +49,7 @@ public class LogDispatcher {
this.plugin.getOnlineSenders()
.filter(CommandPermission.LOG_NOTIFY::isAuthorized)
.filter(s -> {
boolean shouldCancel = LogNotify.isIgnoring(this.plugin, s.getUuid()) || (sender != null && s.getUuid().equals(sender.getUuid()));
boolean shouldCancel = LogNotify.isIgnoring(this.plugin, s.getUniqueId()) || (sender != null && s.getUniqueId().equals(sender.getUniqueId()));
return !this.plugin.getEventFactory().handleLogNotify(shouldCancel, entry, origin, s);
})
.forEach(s -> Message.LOG.send(s,

View File

@ -78,13 +78,13 @@ public class LoggedAction implements Action {
private final long timestamp;
private final SourceImpl source;
private final TargetImpl target;
private final String action;
private final String description;
private LoggedAction(long timestamp, UUID sourceUniqueId, String sourceName, Target.Type targetType, UUID targetUniqueId, String targetName, String description) {
private LoggedAction(long timestamp, UUID sourceUniqueId, String sourceName, UUID targetUniqueId, String targetName, Target.Type targetType, String description) {
this.timestamp = timestamp;
this.source = new SourceImpl(sourceUniqueId, sourceName);
this.target = new TargetImpl(targetUniqueId, targetName, targetType);
this.action = description;
this.description = description;
}
@Override
@ -120,7 +120,7 @@ public class LoggedAction implements Action {
@Override
public @NonNull String getDescription() {
return this.action;
return this.description;
}
@Override
@ -133,7 +133,7 @@ public class LoggedAction implements Action {
query = Objects.requireNonNull(query, "query").toLowerCase();
return this.source.name.toLowerCase().contains(query) ||
this.target.name.toLowerCase().contains(query) ||
this.action.toLowerCase().contains(query);
this.description.toLowerCase().contains(query);
}
public void submit(LuckPermsPlugin plugin, Sender sender) {
@ -297,14 +297,14 @@ public class LoggedAction implements Action {
public Builder source(Sender source) {
sourceName(source.getNameWithLocation());
source(source.getUuid());
source(source.getUniqueId());
return this;
}
public Builder target(PermissionHolder target) {
if (target.getType() == HolderType.USER) {
targetName(((User) target).getName().orElse("null"));
target(((User) target).getUuid());
targetName(((User) target).getUsername().orElse("null"));
target(((User) target).getUniqueId());
targetType(Target.Type.USER);
} else if (target.getType() == HolderType.GROUP) {
targetName(((Group) target).getName());
@ -362,7 +362,7 @@ public class LoggedAction implements Action {
Objects.requireNonNull(this.targetName, "targetName");
Objects.requireNonNull(this.description, "description");
return new LoggedAction(this.timestamp, this.sourceUniqueId, this.sourceName, this.targetType, this.targetUniqueId, this.targetName, this.description);
return new LoggedAction(this.timestamp, this.sourceUniqueId, this.sourceName, this.targetUniqueId, this.targetName, this.targetType, this.description);
}
}

View File

@ -57,9 +57,9 @@ public class ApiActionLog implements ActionLog {
}
@Override
public @NonNull SortedSet<Action> getUserHistory(@NonNull UUID uuid) {
Objects.requireNonNull(uuid, "uuid");
return (SortedSet) this.handle.getUserHistory(uuid);
public @NonNull SortedSet<Action> getUserHistory(@NonNull UUID uniqueId) {
Objects.requireNonNull(uniqueId, "uuid");
return (SortedSet) this.handle.getUserHistory(uniqueId);
}
@Override

View File

@ -30,7 +30,7 @@ import com.google.common.base.Preconditions;
import me.lucko.luckperms.common.cacheddata.GroupCachedDataManager;
import me.lucko.luckperms.common.model.Group;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.query.QueryOptions;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -68,8 +68,8 @@ public class ApiGroup extends ApiPermissionHolder implements net.luckperms.api.m
}
@Override
public @Nullable String getDisplayName(@NonNull ContextSet contextSet) {
return this.handle.getDisplayName(contextSet).orElse(null);
public @Nullable String getDisplayName(@NonNull QueryOptions queryOptions) {
return this.handle.calculateDisplayName(queryOptions).orElse(null);
}
@Override

View File

@ -29,7 +29,6 @@ import com.google.common.collect.ImmutableSortedSet;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
import me.lucko.luckperms.common.node.utils.NodeTools;
import net.luckperms.api.cacheddata.CachedDataManager;
import net.luckperms.api.context.ContextSet;
@ -47,6 +46,8 @@ import net.luckperms.api.query.QueryOptions;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -133,21 +134,26 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo
public @NonNull SortedSet<Node> resolveDistinctInheritedNodes(@NonNull QueryOptions queryOptions) {
List<Node> entries = this.handle.getAllEntries(queryOptions);
NodeTools.removeSamePermission(entries.iterator());
removeSamePermission(entries.iterator());
SortedSet<Node> ret = new TreeSet<>(NodeWithContextComparator.reverse());
ret.addAll(entries);
return ImmutableSortedSet.copyOfSorted(ret);
}
@Override
public void auditTemporaryPermissions() {
this.handle.auditTemporaryPermissions();
private static <T extends Node> void removeSamePermission(Iterator<T> it) {
Set<String> alreadyIn = new HashSet<>();
while (it.hasNext()) {
T next = it.next();
if (!alreadyIn.add(next.getKey())) {
it.remove();
}
}
}
@Override
public @NonNull Tristate inheritsNode(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate) {
return this.handle.inheritsPermission(node, equalityPredicate);
public void auditTemporaryNodes() {
this.handle.auditTemporaryNodes();
}
private abstract class AbstractData implements Data {
@ -168,23 +174,23 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo
}
@Override
public @NonNull Tristate hasNode(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate) {
return ApiPermissionHolder.this.handle.hasPermission(this.dataType, node, equalityPredicate);
public @NonNull Tristate containsNode(@NonNull Node node, @NonNull NodeEqualityPredicate equalityPredicate) {
return ApiPermissionHolder.this.handle.hasNode(this.dataType, node, equalityPredicate);
}
@Override
public @NonNull DataMutateResult addNode(@NonNull Node node) {
return ApiPermissionHolder.this.handle.setPermission(this.dataType, node, true);
return ApiPermissionHolder.this.handle.setNode(this.dataType, node, true);
}
@Override
public @NonNull TemporaryDataMutateResult addNode(@NonNull Node node, @NonNull TemporaryMergeBehaviour temporaryMergeBehaviour) {
return ApiPermissionHolder.this.handle.setPermission(this.dataType, node, temporaryMergeBehaviour);
return ApiPermissionHolder.this.handle.setNode(this.dataType, node, temporaryMergeBehaviour);
}
@Override
public @NonNull DataMutateResult removeNode(@NonNull Node node) {
return ApiPermissionHolder.this.handle.unsetPermission(this.dataType, node);
return ApiPermissionHolder.this.handle.unsetNode(this.dataType, node);
}
@Override
@ -194,12 +200,12 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo
@Override
public void clearNodes() {
ApiPermissionHolder.this.handle.clearNodes(this.dataType, null);
ApiPermissionHolder.this.handle.clearNodes(this.dataType, null, false);
}
@Override
public void clearNodes(@NonNull ContextSet contextSet) {
ApiPermissionHolder.this.handle.clearNodes(this.dataType, contextSet);
ApiPermissionHolder.this.handle.clearNodes(this.dataType, contextSet, false);
}
@Override

View File

@ -60,12 +60,12 @@ public class ApiUser extends ApiPermissionHolder implements net.luckperms.api.mo
@Override
public @NonNull UUID getUniqueId() {
return this.handle.getUuid();
return this.handle.getUniqueId();
}
@Override
public String getUsername() {
return this.handle.getName().orElse(null);
return this.handle.getUsername().orElse(null);
}
@Override
@ -80,7 +80,7 @@ public class ApiUser extends ApiPermissionHolder implements net.luckperms.api.mo
return DataMutateResult.ALREADY_HAS;
}
if (!this.handle.hasPermission(DataType.NORMAL, Inheritance.builder(group.toLowerCase()).build(), NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
if (!this.handle.hasNode(DataType.NORMAL, Inheritance.builder(group.toLowerCase()).build(), NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
return DataMutateResult.FAIL;
}

View File

@ -29,7 +29,6 @@ import me.lucko.luckperms.common.api.ApiUtils;
import me.lucko.luckperms.common.bulkupdate.comparison.Constraint;
import me.lucko.luckperms.common.bulkupdate.comparison.StandardComparison;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.UserIdentifier;
import me.lucko.luckperms.common.model.manager.user.UserManager;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.util.ImmutableCollectors;
@ -60,28 +59,28 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
}
@Override
public @NonNull CompletableFuture<net.luckperms.api.model.user.User> loadUser(@NonNull UUID uuid, @Nullable String username) {
Objects.requireNonNull(uuid, "uuid");
public @NonNull CompletableFuture<net.luckperms.api.model.user.User> loadUser(@NonNull UUID uniqueId, @Nullable String username) {
Objects.requireNonNull(uniqueId, "uuid");
ApiUtils.checkUsername(username, this.plugin);
if (this.plugin.getUserManager().getIfLoaded(uuid) == null) {
this.plugin.getUserManager().getHouseKeeper().registerApiUsage(uuid);
if (this.plugin.getUserManager().getIfLoaded(uniqueId) == null) {
this.plugin.getUserManager().getHouseKeeper().registerApiUsage(uniqueId);
}
return this.plugin.getStorage().loadUser(uuid, username)
return this.plugin.getStorage().loadUser(uniqueId, username)
.thenApply(this::getDelegateFor);
}
@Override
public @NonNull CompletableFuture<UUID> lookupUniqueId(@NonNull String username) {
Objects.requireNonNull(username, "username");
return this.plugin.getStorage().getPlayerUuid(username);
return this.plugin.getStorage().getPlayerUniqueId(username);
}
@Override
public @NonNull CompletableFuture<String> lookupUsername(@NonNull UUID uuid) {
Objects.requireNonNull(uuid, "uuid");
return this.plugin.getStorage().getPlayerName(uuid);
public @NonNull CompletableFuture<String> lookupUsername(@NonNull UUID uniqueId) {
Objects.requireNonNull(uniqueId, "uuid");
return this.plugin.getStorage().getPlayerName(uniqueId);
}
@Override
@ -91,10 +90,10 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
}
@Override
public @NonNull CompletableFuture<PlayerSaveResult> savePlayerData(@NonNull UUID uuid, @NonNull String username) {
Objects.requireNonNull(uuid, "uuid");
public @NonNull CompletableFuture<PlayerSaveResult> savePlayerData(@NonNull UUID uniqueId, @NonNull String username) {
Objects.requireNonNull(uniqueId, "uuid");
Objects.requireNonNull(username, "username");
return this.plugin.getStorage().savePlayerData(uuid, username);
return this.plugin.getStorage().savePlayerData(uniqueId, username);
}
@Override
@ -109,9 +108,9 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
}
@Override
public net.luckperms.api.model.user.User getUser(@NonNull UUID uuid) {
Objects.requireNonNull(uuid, "uuid");
return getDelegateFor(this.handle.getIfLoaded(uuid));
public net.luckperms.api.model.user.User getUser(@NonNull UUID uniqueId) {
Objects.requireNonNull(uniqueId, "uuid");
return getDelegateFor(this.handle.getIfLoaded(uniqueId));
}
@Override
@ -128,14 +127,14 @@ public class ApiUserManager extends ApiAbstractManager<User, net.luckperms.api.m
}
@Override
public boolean isLoaded(@NonNull UUID uuid) {
Objects.requireNonNull(uuid, "uuid");
return this.handle.isLoaded(UserIdentifier.of(uuid, null));
public boolean isLoaded(@NonNull UUID uniqueId) {
Objects.requireNonNull(uniqueId, "uuid");
return this.handle.isLoaded(uniqueId);
}
@Override
public void cleanupUser(net.luckperms.api.model.user.@NonNull User user) {
Objects.requireNonNull(user, "user");
this.handle.getHouseKeeper().clearApiUsage(ApiUser.cast(user).getUuid());
this.handle.getHouseKeeper().clearApiUsage(ApiUser.cast(user).getUniqueId());
}
}

View File

@ -219,7 +219,7 @@ public class Exporter implements Runnable {
List<String> output = new ArrayList<>();
User user = this.plugin.getStorage().loadUser(uuid, null).join();
output.add("# Export user: " + user.getUuid().toString() + " - " + user.getName().orElse("unknown username"));
output.add("# Export user: " + user.getUniqueId().toString() + " - " + user.getUsername().orElse("unknown username"));
boolean inDefault = false;
for (Node node : user.normalData().immutable().values()) {
@ -228,15 +228,15 @@ public class Exporter implements Runnable {
continue;
}
output.add("/lp " + NodeCommandFactory.generateCommand(node, user.getUuid().toString(), HolderType.USER, true, false));
output.add("/lp " + NodeCommandFactory.generateCommand(node, user.getUniqueId().toString(), HolderType.USER, true, false));
}
if (!user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(GroupManager.DEFAULT_GROUP_NAME)) {
output.add("/lp user " + user.getUuid().toString() + " switchprimarygroup " + user.getPrimaryGroup().getStoredValue().get());
output.add("/lp user " + user.getUniqueId().toString() + " switchprimarygroup " + user.getPrimaryGroup().getStoredValue().get());
}
if (!inDefault) {
output.add("/lp user " + user.getUuid().toString() + " parent remove default");
output.add("/lp user " + user.getUniqueId().toString() + " parent remove default");
}
this.plugin.getUserManager().cleanup(user);

View File

@ -109,7 +109,7 @@ public final class ArgumentPermissions {
if (target instanceof User) {
User targetUser = ((User) target);
if (targetUser.getUuid().equals(sender.getUuid())) {
if (targetUser.getUniqueId().equals(sender.getUniqueId())) {
// the sender is trying to edit themselves
Tristate ret = sender.getPermissionValue(base.getPermission() + ".modify.self");
if (ret != Tristate.UNDEFINED) {
@ -174,7 +174,7 @@ public final class ArgumentPermissions {
if (target instanceof User) {
User targetUser = ((User) target);
if (targetUser.getUuid().equals(sender.getUuid())) {
if (targetUser.getUniqueId().equals(sender.getUniqueId())) {
// the sender is trying to view themselves
Tristate ret = sender.getPermissionValue(base.getPermission() + ".view.self");
if (ret != Tristate.UNDEFINED) {
@ -299,9 +299,9 @@ public final class ArgumentPermissions {
return false;
}
User user = plugin.getUserManager().getIfLoaded(sender.getUuid());
User user = plugin.getUserManager().getIfLoaded(sender.getUniqueId());
if (user == null) {
throw new IllegalStateException("Unable to get a User for " + sender.getUuid() + " - " + sender.getName());
throw new IllegalStateException("Unable to get a User for " + sender.getUniqueId() + " - " + sender.getName());
}
PermissionCache permissionData = user.getCachedData().getPermissionData(QueryOptions.defaultContextualOptions().toBuilder().context(contextSet).build());

View File

@ -214,7 +214,7 @@ public class ArgumentParser {
public static UUID parseUserTarget(int index, List<String> args, LuckPermsPlugin plugin, Sender sender) {
final String target = args.get(index);
return UserMainCommand.parseTargetUuid(target, plugin, sender);
return UserMainCommand.parseTargetUniqueId(target, plugin, sender);
}
public abstract static class ArgumentException extends CommandException {}

View File

@ -70,7 +70,7 @@ public final class StorageAssistant {
}
if (auditTemporary) {
group.auditTemporaryPermissions();
group.auditTemporaryNodes();
}
return group;

View File

@ -87,7 +87,7 @@ public class MetaAddChatMeta extends SharedSubCommand {
return CommandResult.NO_PERMISSION;
}
DataMutateResult result = holder.setPermission(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).withContext(context).build(), true);
DataMutateResult result = holder.setNode(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).withContext(context).build(), true);
if (result.wasSuccessful()) {
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(

View File

@ -93,7 +93,7 @@ public class MetaAddTempChatMeta extends SharedSubCommand {
return CommandResult.NO_PERMISSION;
}
TemporaryDataMutateResult ret = holder.setPermission(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).expiry(duration).withContext(context).build(), modifier);
TemporaryDataMutateResult ret = holder.setNode(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).expiry(duration).withContext(context).build(), modifier);
if (((Result) ret.getResult()).wasSuccessful()) {
duration = ret.getMergedNode().getExpiry().getEpochSecond();

View File

@ -103,7 +103,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand {
return CommandResult.SUCCESS;
}
DataMutateResult result = holder.unsetPermission(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).withContext(context).build());
DataMutateResult result = holder.unsetNode(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).withContext(context).build());
if (result.wasSuccessful()) {
TextComponent.Builder builder = Message.REMOVE_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();

View File

@ -103,7 +103,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand {
return CommandResult.SUCCESS;
}
DataMutateResult result = holder.unsetPermission(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).expiry(10L).withContext(context).build());
DataMutateResult result = holder.unsetNode(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).expiry(10L).withContext(context).build());
if (result.wasSuccessful()) {
TextComponent.Builder builder = Message.REMOVE_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();

View File

@ -81,13 +81,13 @@ public class MetaSet extends SharedSubCommand {
Node node = Meta.builder(key, value).withContext(context).build();
if (holder.hasPermission(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
if (holder.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
Message.ALREADY_HAS_META.send(sender, holder.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
holder.removeIf(DataType.NORMAL, context, n -> n instanceof MetaNode && !n.hasExpiry() && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key), null);
holder.setPermission(DataType.NORMAL, node, true);
holder.setNode(DataType.NORMAL, node, true);
TextComponent.Builder builder = Message.SET_META_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(

View File

@ -123,7 +123,7 @@ public class MetaSetChatMeta extends SharedSubCommand {
}
}
DataMutateResult result = holder.setPermission(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).withContext(context).build(), true);
DataMutateResult result = holder.setNode(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).withContext(context).build(), true);
if (result.wasSuccessful()) {
TextComponent.Builder builder = Message.ADD_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(

View File

@ -86,13 +86,13 @@ public class MetaSetTemp extends SharedSubCommand {
Node node = Meta.builder(key, value).withContext(context).expiry(duration).build();
if (holder.hasPermission(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
if (holder.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE).asBoolean()) {
Message.ALREADY_HAS_TEMP_META.send(sender, holder.getFormattedDisplayName(), key, value, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));
return CommandResult.STATE_ERROR;
}
holder.removeIf(DataType.NORMAL, context, n -> n instanceof MetaNode && n.hasExpiry() && ((MetaNode) n).getMetaKey().equalsIgnoreCase(key), null);
duration = holder.setPermission(DataType.NORMAL, node, modifier).getMergedNode().getExpiry().getEpochSecond();
duration = holder.setNode(DataType.NORMAL, node, modifier).getMergedNode().getExpiry().getEpochSecond();
TextComponent.Builder builder = Message.SET_META_TEMP_SUCCESS.asComponent(plugin.getLocaleManager(), key, value, holder.getFormattedDisplayName(), DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder();
HoverEvent event = HoverEvent.showText(TextUtils.fromLegacy(

View File

@ -133,7 +133,7 @@ public class MetaSetTempChatMeta extends SharedSubCommand {
}
}
TemporaryDataMutateResult ret = holder.setPermission(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).expiry(duration).withContext(context).build(), modifier);
TemporaryDataMutateResult ret = holder.setNode(DataType.NORMAL, ((this.type == ChatMetaType.PREFIX ? Prefix.builder(priority, meta) : Suffix.builder(priority, meta))).expiry(duration).withContext(context).build(), modifier);
if (((Result) ret.getResult()).wasSuccessful()) {
duration = ret.getMergedNode().getExpiry().getEpochSecond();

View File

@ -72,9 +72,9 @@ public class HolderClear<T extends PermissionHolder> extends SubCommand<T> {
}
if (context.isEmpty()) {
holder.clearNodes(DataType.NORMAL, null);
holder.clearNodes(DataType.NORMAL, null, false);
} else {
holder.clearNodes(DataType.NORMAL, context);
holder.clearNodes(DataType.NORMAL, context, false);
}
int changed = before - holder.normalData().immutable().size();

View File

@ -44,7 +44,6 @@ import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.types.InheritanceNode;
import java.util.ArrayList;
@ -77,9 +76,7 @@ public class HolderShowTracks<T extends PermissionHolder> extends SubCommand<T>
if (holder.getType() == HolderType.USER) {
// if the holder is a user, we want to query parent groups for tracks
Set<InheritanceNode> nodes = holder.normalData().immutable().values().stream()
.filter(NodeType.INHERITANCE::matches)
.map(NodeType.INHERITANCE::cast)
Set<InheritanceNode> nodes = holder.normalData().immutableInheritance().values().stream()
.filter(Node::getValue)
.filter(n -> !n.hasExpiry())
.collect(Collectors.toSet());

View File

@ -80,7 +80,7 @@ public class ParentAdd extends SharedSubCommand {
return CommandResult.NO_PERMISSION;
}
DataMutateResult result = holder.setPermission(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
DataMutateResult result = holder.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
if (result.wasSuccessful()) {
Message.SET_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));

View File

@ -91,7 +91,7 @@ public class ParentAddTemp extends SharedSubCommand {
return CommandResult.STATE_ERROR;
}
TemporaryDataMutateResult ret = holder.setPermission(DataType.NORMAL, Inheritance.builder(group.getName()).expiry(duration).withContext(context).build(), modifier);
TemporaryDataMutateResult ret = holder.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).expiry(duration).withContext(context).build(), modifier);
if (((Result) ret.getResult()).wasSuccessful()) {
duration = ret.getMergedNode().getExpiry().getEpochSecond();

View File

@ -92,7 +92,7 @@ public class ParentRemove extends SharedSubCommand {
}
}
DataMutateResult result = holder.unsetPermission(DataType.NORMAL, Inheritance.builder(groupName).withContext(context).build());
DataMutateResult result = holder.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).withContext(context).build());
if (result.wasSuccessful()) {
Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));

View File

@ -74,7 +74,7 @@ public class ParentRemoveTemp extends SharedSubCommand {
return CommandResult.NO_PERMISSION;
}
DataMutateResult result = holder.unsetPermission(DataType.NORMAL, Inheritance.builder(groupName).expiry(10L).withContext(context).build());
DataMutateResult result = holder.unsetNode(DataType.NORMAL, Inheritance.builder(groupName).expiry(10L).withContext(context).build());
if (result.wasSuccessful()) {
Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFormattedDisplayName(), groupName, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));

View File

@ -82,7 +82,7 @@ public class ParentSet extends SharedSubCommand {
}
holder.clearNormalParents(context, false);
holder.setPermission(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
holder.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
if (holder.getType() == HolderType.USER) {
((User) holder).getPrimaryGroup().setStoredValue(group.getName());
}

View File

@ -115,7 +115,7 @@ public class ParentSetTrack extends SharedSubCommand {
}
holder.removeIf(DataType.NORMAL, null, NodeType.INHERITANCE.predicate(n -> n.getContexts().equals(context) && track.containsGroup(n.getGroupName())), null);
holder.setPermission(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
holder.setNode(DataType.NORMAL, Inheritance.builder(group.getName()).withContext(context).build(), true);
Message.SET_TRACK_PARENT_SUCCESS.send(sender, holder.getFormattedDisplayName(), track.getName(), group.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));

View File

@ -95,9 +95,9 @@ public class UserSwitchPrimaryGroup extends SharedSubCommand {
}
Node node = Inheritance.builder(group.getName()).build();
if (!user.hasPermission(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_VALUE).asBoolean()) {
if (!user.hasNode(DataType.NORMAL, node, NodeEqualityPredicate.IGNORE_VALUE).asBoolean()) {
Message.USER_PRIMARYGROUP_ERROR_NOTMEMBER.send(sender, user.getFormattedDisplayName(), group.getName());
holder.setPermission(DataType.NORMAL, node, true);
holder.setNode(DataType.NORMAL, node, true);
}
user.getPrimaryGroup().setStoredValue(group.getName());

View File

@ -65,7 +65,7 @@ public class PermissionCheck extends SharedSubCommand {
String node = ArgumentParser.parseString(0, args);
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
Tristate result = holder.hasPermission(DataType.NORMAL, NodeBuilders.determineMostApplicable(node).withContext(context).build(), NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY);
Tristate result = holder.hasNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(node).withContext(context).build(), NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY);
String s = MessageUtils.formatTristate(result);
Message.CHECK_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context));

View File

@ -38,16 +38,18 @@ import me.lucko.luckperms.common.locale.LocaleManager;
import me.lucko.luckperms.common.locale.command.CommandSpec;
import me.lucko.luckperms.common.locale.message.Message;
import me.lucko.luckperms.common.model.PermissionHolder;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.node.utils.InheritanceInfo;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.node.NodeEqualityPredicate;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.Tristate;
import net.luckperms.api.node.metadata.types.InheritanceOriginMetadata;
import net.luckperms.api.query.QueryOptions;
import java.util.List;
import java.util.Optional;
public class PermissionCheckInherits extends SharedSubCommand {
public PermissionCheckInherits(LocaleManager locale) {
@ -64,14 +66,17 @@ public class PermissionCheckInherits extends SharedSubCommand {
String node = ArgumentParser.parseString(0, args);
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
InheritanceInfo result = holder.searchForInheritedMatch(NodeBuilders.determineMostApplicable(node).withContext(context).build(), NodeEqualityPredicate.IGNORE_VALUE_OR_IF_TEMPORARY);
Optional<Node> match = holder.resolveInheritances(QueryOptions.nonContextual()).stream()
.filter(n -> n.getKey().equalsIgnoreCase(node) && n.getContexts().equals(context))
.findFirst();
String location = match.map(n -> n.metadata(InheritanceOriginMetadata.KEY).getOrigin()).orElse(null);
String location = result.getLocation().orElse(null);
if (location == null || location.equalsIgnoreCase(holder.getObjectName())) {
location = "self";
}
String s = MessageUtils.formatTristate(result.getResult());
String s = MessageUtils.formatTristate(match.map(n -> Tristate.of(n.getValue())).orElse(Tristate.UNDEFINED));
Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFormattedDisplayName(), node, s, MessageUtils.contextSetToString(plugin.getLocaleManager(), context), location);
return CommandResult.SUCCESS;
}

View File

@ -85,7 +85,7 @@ public class PermissionSet extends SharedSubCommand {
}
}
DataMutateResult result = holder.setPermission(DataType.NORMAL, builtNode, true);
DataMutateResult result = holder.setNode(DataType.NORMAL, builtNode, true);
if (result.wasSuccessful()) {
Message.SETPERMISSION_SUCCESS.send(sender, node, value, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));

View File

@ -91,7 +91,7 @@ public class PermissionSetTemp extends SharedSubCommand {
}
}
TemporaryDataMutateResult result = holder.setPermission(DataType.NORMAL, builtNode, modifier);
TemporaryDataMutateResult result = holder.setNode(DataType.NORMAL, builtNode, modifier);
if (((Result) result.getResult()).wasSuccessful()) {
duration = result.getMergedNode().getExpiry().getEpochSecond();

View File

@ -84,7 +84,7 @@ public class PermissionUnset extends SharedSubCommand {
}
}
DataMutateResult result = holder.unsetPermission(DataType.NORMAL, builtNode);
DataMutateResult result = holder.unsetNode(DataType.NORMAL, builtNode);
if (result.wasSuccessful()) {
Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));

View File

@ -84,7 +84,7 @@ public class PermissionUnsetTemp extends SharedSubCommand {
}
}
DataMutateResult result = holder.unsetPermission(DataType.NORMAL, builtNode);
DataMutateResult result = holder.unsetNode(DataType.NORMAL, builtNode);
if (result.wasSuccessful()) {
Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFormattedDisplayName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));

View File

@ -45,8 +45,9 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.sender.Sender;
import me.lucko.luckperms.common.util.Predicates;
import net.luckperms.api.context.MutableContextSet;
import net.luckperms.api.context.ImmutableContextSet;
import net.luckperms.api.model.DataType;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.types.DisplayNameNode;
import java.util.List;
@ -64,9 +65,14 @@ public class GroupSetDisplayName extends SubCommand<Group> {
}
String name = ArgumentParser.parseString(0, args);
MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
ImmutableContextSet context = ArgumentParser.parseContext(1, args, plugin).immutableCopy();
String previousName = group.getDisplayName(context).orElse(null);
String previousName = group.normalData().immutable().get(context).stream()
.filter(NodeType.DISPLAY_NAME::matches)
.map(NodeType.DISPLAY_NAME::cast)
.findFirst()
.map(DisplayNameNode::getDisplayName)
.orElse(null);
if (previousName == null && name.equals(group.getName())) {
Message.GROUP_SET_DISPLAY_NAME_DOESNT_HAVE.send(sender, group.getName());
@ -97,7 +103,7 @@ public class GroupSetDisplayName extends SubCommand<Group> {
return CommandResult.SUCCESS;
}
group.setPermission(DataType.NORMAL, DisplayName.builder(name).withContext(context).build(), true);
group.setNode(DataType.NORMAL, DisplayName.builder(name).withContext(context).build(), true);
Message.GROUP_SET_DISPLAY_NAME.send(sender, name, group.getName(), MessageUtils.contextSetToString(plugin.getLocaleManager(), context));

View File

@ -62,7 +62,7 @@ public class GroupSetWeight extends SubCommand<Group> {
int weight = ArgumentParser.parsePriority(0, args);
group.removeIf(DataType.NORMAL, null, n -> n instanceof WeightNode, null);
group.setPermission(DataType.NORMAL, Weight.builder(weight).build(), true);
group.setNode(DataType.NORMAL, Weight.builder(weight).build(), true);
Message.GROUP_SET_WEIGHT.send(sender, weight, group.getFormattedDisplayName());

View File

@ -76,7 +76,7 @@ public class LogNotify extends SubCommand<Log> {
if (state) {
// add the perm
user.setPermission(DataType.NORMAL, NodeBuilders.determineMostApplicable(IGNORE_NODE).build(), true);
user.setNode(DataType.NORMAL, NodeBuilders.determineMostApplicable(IGNORE_NODE).build(), true);
} else {
// remove the perm
user.removeIf(DataType.NORMAL, ImmutableContextSetImpl.EMPTY, n -> n.getKey().equalsIgnoreCase(IGNORE_NODE), null);
@ -92,7 +92,7 @@ public class LogNotify extends SubCommand<Log> {
return CommandResult.SUCCESS;
}
final UUID uuid = sender.getUuid();
final UUID uuid = sender.getUniqueId();
if (args.isEmpty()) {
if (isIgnoring(plugin, uuid)) {
// toggle on

View File

@ -58,7 +58,7 @@ public final class MigrationUtils {
public static void setGroupWeight(Group group, int weight) {
group.removeIf(DataType.NORMAL, null, NodeType.WEIGHT::matches, null);
group.setPermission(DataType.NORMAL, Weight.builder(weight).build(), true);
group.setNode(DataType.NORMAL, Weight.builder(weight).build(), true);
}
public static String standardizeName(String string) {

View File

@ -105,7 +105,7 @@ public class VerboseCommand extends SingleCommand {
}
if (mode.equals("off") || mode.equals("false") || mode.equals("paste") || mode.equals("upload")) {
VerboseListener listener = plugin.getVerboseHandler().unregisterListener(sender.getUuid());
VerboseListener listener = plugin.getVerboseHandler().unregisterListener(sender.getUniqueId());
if (mode.equals("paste") || mode.equals("upload")) {
if (listener == null) {

View File

@ -78,7 +78,7 @@ public class UserClone extends SubCommand<User> {
Message.CLONE_SUCCESS.send(sender, user.getFormattedDisplayName(), otherUser.getFormattedDisplayName());
LoggedAction.build().source(sender).target(otherUser)
.description("clone", user.getName())
.description("clone", user.getUsername())
.build().submit(plugin, sender);
StorageAssistant.save(otherUser, sender, plugin);

View File

@ -64,12 +64,12 @@ public class UserInfo extends SubCommand<User> {
return CommandResult.NO_PERMISSION;
}
Message status = plugin.getBootstrap().isPlayerOnline(user.getUuid()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
Message status = plugin.getBootstrap().isPlayerOnline(user.getUniqueId()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
Message.USER_INFO_GENERAL.send(sender,
user.getName().orElse("Unknown"),
user.getUuid(),
user.getUuid().version() == 4 ? "&2mojang" : "&8offline",
user.getUsername().orElse("Unknown"),
user.getUniqueId(),
user.getUniqueId().version() == 4 ? "&2mojang" : "&8offline",
status.asString(plugin.getLocaleManager()),
user.getPrimaryGroup().getValue()
);

View File

@ -80,9 +80,9 @@ public class UserMainCommand extends MainCommand<User, UserIdentifier> {
);
}
public static UUID parseTargetUuid(String target, LuckPermsPlugin plugin, Sender sender) {
UUID uuid = Uuids.parse(target);
if (uuid == null) {
public static UUID parseTargetUniqueId(String target, LuckPermsPlugin plugin, Sender sender) {
UUID uniqueId = Uuids.parse(target);
if (uniqueId == null) {
if (!plugin.getConfiguration().get(ConfigKeys.ALLOW_INVALID_USERNAMES)) {
if (!DataConstraints.PLAYER_USERNAME_TEST.test(target)) {
Message.USER_INVALID_ENTRY.send(sender, target);
@ -95,45 +95,45 @@ public class UserMainCommand extends MainCommand<User, UserIdentifier> {
}
}
uuid = plugin.getStorage().getPlayerUuid(target.toLowerCase()).join();
if (uuid == null) {
uniqueId = plugin.getStorage().getPlayerUniqueId(target.toLowerCase()).join();
if (uniqueId == null) {
if (!plugin.getConfiguration().get(ConfigKeys.USE_SERVER_UUID_CACHE)) {
Message.USER_NOT_FOUND.send(sender, target);
return null;
}
uuid = plugin.getBootstrap().lookupUuid(target).orElse(null);
if (uuid == null) {
uniqueId = plugin.getBootstrap().lookupUniqueId(target).orElse(null);
if (uniqueId == null) {
Message.USER_NOT_FOUND.send(sender, target);
return null;
}
}
}
return uuid;
return uniqueId;
}
@Override
protected UserIdentifier parseTarget(String target, LuckPermsPlugin plugin, Sender sender) {
UUID uuid = parseTargetUuid(target, plugin, sender);
if (uuid == null) {
UUID uniqueId = parseTargetUniqueId(target, plugin, sender);
if (uniqueId == null) {
return null;
}
String name = plugin.getStorage().getPlayerName(uuid).join();
return UserIdentifier.of(uuid, name);
String name = plugin.getStorage().getPlayerName(uniqueId).join();
return UserIdentifier.of(uniqueId, name);
}
@Override
protected User getTarget(UserIdentifier target, LuckPermsPlugin plugin, Sender sender) {
User user = plugin.getStorage().loadUser(target.getUuid(), target.getUsername().orElse(null)).join();
user.auditTemporaryPermissions();
User user = plugin.getStorage().loadUser(target.getUniqueId(), target.getUsername().orElse(null)).join();
user.auditTemporaryNodes();
return user;
}
@Override
protected ReentrantLock getLockForTarget(UserIdentifier target) {
return this.locks.get(target.getUuid());
return this.locks.get(target.getUniqueId());
}
@Override

View File

@ -25,8 +25,6 @@
package me.lucko.luckperms.common.context;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.cache.ExpiringCache;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
@ -64,14 +62,6 @@ public abstract class ContextManager<T> {
this.subjectClass = subjectClass;
}
public List<ContextCalculator<? super T>> getCalculators() {
return ImmutableList.copyOf(this.calculators);
}
public List<StaticContextCalculator> getStaticCalculators() {
return ImmutableList.copyOf(this.staticCalculators);
}
public ImmutableContextSet getPotentialContexts() {
ImmutableContextSet.Builder builder = ImmutableContextSet.builder();
for (ContextCalculator<? super T> calculator : this.calculators) {
@ -142,7 +132,7 @@ public abstract class ContextManager<T> {
return formQueryOptions(subject, accumulator.build());
}
QueryOptions calculateStatic() {
private QueryOptions calculateStatic() {
ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl();
for (StaticContextCalculator calculator : this.staticCalculators) {

View File

@ -285,20 +285,20 @@ public final class EventFactory {
}
}
public void handleUserFirstLogin(UUID uuid, String username) {
post(UserFirstLoginEvent.class, () -> generate(UserFirstLoginEvent.class, uuid, username));
public void handleUserFirstLogin(UUID uniqueId, String username) {
post(UserFirstLoginEvent.class, () -> generate(UserFirstLoginEvent.class, uniqueId, username));
}
public void handlePlayerLoginProcess(UUID uuid, String username, User user) {
public void handlePlayerLoginProcess(UUID uniqueId, String username, User user) {
if (!shouldPost(PlayerLoginProcessEvent.class)) {
return;
}
post(generate(PlayerLoginProcessEvent.class, uuid, username, new ApiUser(user)));
post(generate(PlayerLoginProcessEvent.class, uniqueId, username, new ApiUser(user)));
}
public void handlePlayerDataSave(UUID uuid, String username, PlayerSaveResult result) {
post(PlayerDataSaveEvent.class, () -> generate(PlayerDataSaveEvent.class, uuid, username, result));
public void handlePlayerDataSave(UUID uniqueId, String username, PlayerSaveResult result) {
post(PlayerDataSaveEvent.class, () -> generate(PlayerDataSaveEvent.class, uniqueId, username, result));
}
public void handleUserLoad(User user) {

View File

@ -46,7 +46,7 @@ public class SenderPlatformEntity implements PlatformEntity {
if (this.sender.isConsole()) {
return null;
}
return this.sender.getUuid();
return this.sender.getUniqueId();
}
@Override

View File

@ -61,7 +61,7 @@ public class InheritanceGraph implements Graph<PermissionHolder> {
@Override
public Iterable<? extends PermissionHolder> successors(PermissionHolder holder) {
Set<Group> successors = new LinkedHashSet<>();
for (InheritanceNode n : holder.getOwnGroupNodes(this.queryOptions)) {
for (InheritanceNode n : holder.getOwnInheritanceNodes(this.queryOptions)) {
// effectively: if not (we're applying global groups or it's specific anyways)
if (!((this.queryOptions.flag(Flag.APPLY_INHERITANCE_NODES_WITHOUT_SERVER_CONTEXT) || n.getContexts().containsKey(DefaultContextKeys.SERVER_KEY)) &&
(this.queryOptions.flag(Flag.APPLY_INHERITANCE_NODES_WITHOUT_WORLD_CONTEXT) || n.getContexts().containsKey(DefaultContextKeys.WORLD_KEY)))) {

View File

@ -1,61 +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.inheritance;
import me.lucko.luckperms.common.model.Group;
import net.luckperms.api.node.Node;
public final class ResolvedGroup {
private final Node node;
private final Group group;
ResolvedGroup(Node node, Group group) {
this.node = node;
this.group = group;
}
Node node() {
return this.node;
}
Group group() {
return this.group;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ResolvedGroup that = (ResolvedGroup) o;
return this.group.equals(that.group);
}
@Override
public int hashCode() {
return this.group.hashCode();
}
}

View File

@ -122,7 +122,7 @@ public class LuckPermsMessagingService implements InternalMessagingService, Inco
this.plugin.getBootstrap().getScheduler().executeAsync(() -> {
UUID requestId = generatePingId();
this.plugin.getLogger().info("[Messaging] Sending user ping for '" + user.getPlainDisplayName() + "' with id: " + requestId);
this.messenger.sendOutgoingMessage(new UserUpdateMessageImpl(requestId, user.getUuid()));
this.messenger.sendOutgoingMessage(new UserUpdateMessageImpl(requestId, user.getUniqueId()));
});
}
@ -252,7 +252,7 @@ public class LuckPermsMessagingService implements InternalMessagingService, Inco
return;
}
this.plugin.getStorage().loadUser(user.getUuid(), null);
this.plugin.getStorage().loadUser(user.getUniqueId(), null);
} else if (message instanceof ActionLogMessage) {
ActionLogMessage msg = (ActionLogMessage) message;

View File

@ -1,62 +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.model;
import me.lucko.luckperms.common.cache.Cache;
import me.lucko.luckperms.common.config.ConfigKeys;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.DisplayNameNode;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Optional;
/**
* Cache instance to supply the display name of a {@link Group}.
*/
public class DisplayNameCache extends Cache<Optional<String>> {
private final Group group;
public DisplayNameCache(Group group) {
this.group = group;
}
@Override
protected @NonNull Optional<String> supply() {
// query for a displayname node
for (Node n : this.group.getOwnNodes(this.group.getPlugin().getContextManager().getStaticQueryOptions())) {
if (n instanceof DisplayNameNode) {
DisplayNameNode displayNameNode = (DisplayNameNode) n;
return Optional.of(displayNameNode.getDisplayName());
}
}
// fallback to config
String name = this.group.getPlugin().getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).get(this.group.getObjectName());
return name == null || name.equals(this.group.getObjectName()) ? Optional.empty() : Optional.of(name);
}
}

View File

@ -28,16 +28,19 @@ package me.lucko.luckperms.common.model;
import me.lucko.luckperms.common.api.implementation.ApiGroup;
import me.lucko.luckperms.common.cache.Cache;
import me.lucko.luckperms.common.cacheddata.GroupCachedDataManager;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.luckperms.api.context.ContextSet;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.DisplayNameNode;
import net.luckperms.api.query.QueryOptions;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Optional;
import java.util.OptionalInt;
public class Group extends PermissionHolder implements Identifiable<String> {
public class Group extends PermissionHolder {
private final ApiGroup apiDelegate = new ApiGroup(this);
/**
@ -53,7 +56,7 @@ public class Group extends PermissionHolder implements Identifiable<String> {
/**
* Caches the groups display name
*/
private final Cache<Optional<String>> displayNameCache = new DisplayNameCache(this);
private final Cache<Optional<String>> displayNameCache = new DisplayNameCache();
/**
* The groups data cache instance
@ -87,9 +90,13 @@ public class Group extends PermissionHolder implements Identifiable<String> {
return this.name;
}
public ApiGroup getApiDelegate() {
return this.apiDelegate;
}
@Override
public String getId() {
return this.name;
public GroupCachedDataManager getCachedData() {
return this.cachedData;
}
@Override
@ -107,30 +114,18 @@ public class Group extends PermissionHolder implements Identifiable<String> {
return this.displayNameCache.get();
}
/**
* Gets a display name value exactly matching a specific context.
*
* <p>Note that the behaviour of {@link #getDisplayName()} is not the same as this.</p>
*
* @param contextSet the contexts to lookup in
* @return the display name
*/
public Optional<String> getDisplayName(ContextSet contextSet) {
for (Node n : normalData().immutable().get(contextSet.immutableCopy())) {
public Optional<String> calculateDisplayName(QueryOptions queryOptions) {
// query for a displayname node
for (Node n : getOwnNodes(queryOptions)) {
if (n instanceof DisplayNameNode) {
return Optional.of(((DisplayNameNode) n).getDisplayName());
DisplayNameNode displayNameNode = (DisplayNameNode) n;
return Optional.of(displayNameNode.getDisplayName());
}
}
return Optional.empty();
}
public ApiGroup getApiDelegate() {
return this.apiDelegate;
}
@Override
public GroupCachedDataManager getCachedData() {
return this.cachedData;
// fallback to config
String name = getPlugin().getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).get(this.name);
return name == null || name.equals(this.name) ? Optional.empty() : Optional.of(name);
}
@Override
@ -161,4 +156,13 @@ public class Group extends PermissionHolder implements Identifiable<String> {
return "Group(name=" + this.name + ")";
}
/**
* Cache instance to supply the display name of a {@link Group}.
*/
public class DisplayNameCache extends Cache<Optional<String>> {
@Override
protected @NonNull Optional<String> supply() {
return calculateDisplayName(getPlugin().getContextManager().getStaticQueryOptions());
}
}
}

View File

@ -1,41 +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.model;
/**
* Interface to represent an identifiable object
*/
public interface Identifiable<T> {
/**
* Returns the objects identifier.
* If the type is a {@link String}, this method must return a {@link String#toLowerCase()} representation
*
* @return the identifier
*/
T getId();
}

View File

@ -76,6 +76,7 @@ import java.util.function.Predicate;
public final class NodeMap {
private static final Function<ImmutableContextSet, SortedSet<Node>> VALUE_SET_SUPPLIER = k -> new ConcurrentSkipListSet<>(NodeComparator.reverse());
private static final Function<ImmutableContextSet, SortedSet<InheritanceNode>> INHERITANCE_VALUE_SET_SUPPLIER = k -> new ConcurrentSkipListSet<>(NodeComparator.reverse());
/**
* The holder which this map is for
*/
@ -100,7 +101,8 @@ public final class NodeMap {
/**
* A cache which holds an immutable copy of the backing map
*/
private final NodeMapCache cache = new NodeMapCache(this);
private final ImmutableSetMultimapCache<ImmutableContextSet, Node> mapCache = new ImmutableSetMultimapCache<>(this.map);
private final ImmutableSetMultimapCache<ImmutableContextSet, InheritanceNode> inheritanceMapCache = new ImmutableSetMultimapCache<>(this.inheritanceMap);
NodeMap(PermissionHolder holder) {
this.holder = holder;
@ -152,14 +154,19 @@ public final class NodeMap {
* @return an immutable copy
*/
public ImmutableSetMultimap<ImmutableContextSet, Node> immutable() {
return this.cache.get();
return this.mapCache.get();
}
public ImmutableSetMultimap<ImmutableContextSet, InheritanceNode> immutableInheritance() {
return this.inheritanceMapCache.get();
}
/**
* Invalidates the cache
*/
void invalidate() {
this.cache.invalidate();
this.mapCache.invalidate();
this.inheritanceMapCache.get();
}
private Node localise(Node node) {
@ -180,10 +187,10 @@ public final class NodeMap {
nodesInContext.add(n);
if (n instanceof InheritanceNode) {
SortedSet<InheritanceNode> groupNodesInContext = this.inheritanceMap.computeIfAbsent(context, INHERITANCE_VALUE_SET_SUPPLIER);
groupNodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.computeIfAbsent(context, INHERITANCE_VALUE_SET_SUPPLIER);
inheritanceNodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
if (n.getValue()) {
groupNodesInContext.add((InheritanceNode) n);
inheritanceNodesInContext.add((InheritanceNode) n);
}
}
}
@ -196,9 +203,9 @@ public final class NodeMap {
}
if (node instanceof InheritanceNode) {
SortedSet<InheritanceNode> groupNodesInContext = this.inheritanceMap.get(context);
if (groupNodesInContext != null) {
groupNodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.get(context);
if (inheritanceNodesInContext != null) {
inheritanceNodesInContext.removeIf(e -> e.equals(node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE));
}
}
}
@ -211,9 +218,9 @@ public final class NodeMap {
}
if (node instanceof InheritanceNode && node.getValue()) {
SortedSet<InheritanceNode> groupNodesInContext = this.inheritanceMap.get(context);
if (groupNodesInContext != null) {
groupNodesInContext.remove(node);
SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.get(context);
if (inheritanceNodesInContext != null) {
inheritanceNodesInContext.remove(node);
}
}
}
@ -269,9 +276,9 @@ public final class NodeMap {
ret = nodesInContext.removeIf(predicate);
}
SortedSet<InheritanceNode> groupNodesInContext = this.inheritanceMap.get(context);
if (groupNodesInContext != null) {
groupNodesInContext.removeIf(predicate);
SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.get(context);
if (inheritanceNodesInContext != null) {
inheritanceNodesInContext.removeIf(predicate);
}
return ret;
@ -293,9 +300,9 @@ public final class NodeMap {
removed.add(entry);
}
if (entry instanceof InheritanceNode && entry.getValue()) {
SortedSet<InheritanceNode> groupNodesInContext = this.inheritanceMap.get(entry.getContexts());
if (groupNodesInContext != null) {
groupNodesInContext.remove(entry);
SortedSet<InheritanceNode> inheritanceNodesInContext = this.inheritanceMap.get(entry.getContexts());
if (inheritanceNodesInContext != null) {
inheritanceNodesInContext.remove(entry);
}
}
it.remove();
@ -306,7 +313,7 @@ public final class NodeMap {
return work;
}
private static final class NodeMapCache extends Cache<ImmutableSetMultimap<ImmutableContextSet, Node>> {
private static final class ImmutableSetMultimapCache<K, V> extends Cache<ImmutableSetMultimap<K, V>> {
private static final Constructor<ImmutableSetMultimap> IMMUTABLE_SET_MULTIMAP_CONSTRUCTOR;
static {
try {
@ -317,20 +324,20 @@ public final class NodeMap {
}
}
private final NodeMap handle;
private final Map<K, ? extends Collection<V>> handle;
private NodeMapCache(NodeMap handle) {
private ImmutableSetMultimapCache(Map<K, ? extends Collection<V>> handle) {
this.handle = handle;
}
@Override
protected @NonNull ImmutableSetMultimap<ImmutableContextSet, Node> supply() {
ImmutableMap.Builder<ImmutableContextSet, ImmutableSet<Node>> builder = ImmutableMap.builder();
protected @NonNull ImmutableSetMultimap<K, V> supply() {
ImmutableMap.Builder<K, ImmutableSet<V>> builder = ImmutableMap.builder();
int size = 0;
for (Map.Entry<ImmutableContextSet, SortedSet<Node>> entry : this.handle.map.entrySet()) {
ImmutableContextSet key = entry.getKey();
ImmutableSet<Node> values = ImmutableSet.copyOf(entry.getValue());
for (Map.Entry<K, ? extends Collection<V>> entry : this.handle.entrySet()) {
K key = entry.getKey();
ImmutableSet<V> values = ImmutableSet.copyOf(entry.getValue());
if (!values.isEmpty()) {
builder.put(key, values);
size += values.size();

View File

@ -34,8 +34,6 @@ import me.lucko.luckperms.common.cacheddata.type.MetaAccumulator;
import me.lucko.luckperms.common.inheritance.InheritanceComparator;
import me.lucko.luckperms.common.inheritance.InheritanceGraph;
import me.lucko.luckperms.common.node.comparator.NodeWithContextComparator;
import me.lucko.luckperms.common.node.utils.InheritanceInfo;
import me.lucko.luckperms.common.node.utils.NodeTools;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.luckperms.api.context.ContextSet;
@ -86,10 +84,9 @@ import java.util.function.Predicate;
* These lookup methods initially use Lists of nodes populated with the
* inheritance tree. Nodes at the start of this list have priority over nodes at
* the end. Nodes higher up the tree appear at the end of these lists. In order
* to remove duplicate elements, the lists are flattened using the methods in
* {@link NodeTools}. This is significantly faster than trying to prevent
* duplicates throughout the process of accumulation, and reduces the need for
* too much caching.</p>
* to remove duplicate elements, the lists are flattened. This is significantly
* faster than trying to prevent duplicates throughout the process of accumulation,
* and reduces the need for too much caching.</p>
*
* <p>Cached state is avoided in these instances to cut down on memory
* footprint. The nodes are stored indexed to the contexts they apply in, so
@ -268,7 +265,7 @@ public abstract class PermissionHolder {
return ret;
}
public List<InheritanceNode> getOwnGroupNodes(QueryOptions queryOptions) {
public List<InheritanceNode> getOwnInheritanceNodes(QueryOptions queryOptions) {
List<InheritanceNode> ret = new ArrayList<>();
Comparator<DataType> comparator = queryOptions.option(DataQueryOrderFunction.KEY)
@ -382,14 +379,14 @@ public abstract class PermissionHolder {
*
* @return true if permissions had expired and were removed
*/
public boolean auditTemporaryPermissions() {
boolean transientWork = auditTemporaryPermissions(DataType.TRANSIENT);
boolean normalWork = auditTemporaryPermissions(DataType.NORMAL);
public boolean auditTemporaryNodes() {
boolean transientWork = auditTemporaryNodes(DataType.TRANSIENT);
boolean normalWork = auditTemporaryNodes(DataType.NORMAL);
return transientWork || normalWork;
}
private boolean auditTemporaryPermissions(DataType dataType) {
private boolean auditTemporaryNodes(DataType dataType) {
ImmutableCollection<? extends Node> before = getData(dataType).immutable().values();
Set<Node> removed = new HashSet<>();
@ -407,15 +404,7 @@ public abstract class PermissionHolder {
return work;
}
/**
* Check if the holder has a permission node
*
* @param type which backing map to check
* @param node the Node to check
* @param equalityPredicate how to match
* @return a tristate, returns undefined if no match
*/
public Tristate hasPermission(DataType type, Node node, NodeEqualityPredicate equalityPredicate) {
public Tristate hasNode(DataType type, Node node, NodeEqualityPredicate equalityPredicate) {
if (this.getType() == HolderType.GROUP && node instanceof InheritanceNode && ((InheritanceNode) node).getGroupName().equalsIgnoreCase(getObjectName())) {
return Tristate.TRUE;
}
@ -426,29 +415,8 @@ public abstract class PermissionHolder {
.map(n -> Tristate.of(n.getValue())).orElse(Tristate.UNDEFINED);
}
/**
* Check if the holder inherits a node
*
* @param node the Node to check
* @param equalityPredicate how to match
* @return the result of the lookup
*/
public InheritanceInfo searchForInheritedMatch(Node node, NodeEqualityPredicate equalityPredicate) {
for (Node n : resolveInheritances(QueryOptions.nonContextual())) {
if (n.equals(node, equalityPredicate)) {
return InheritanceInfo.of(n);
}
}
return InheritanceInfo.empty();
}
public Tristate inheritsPermission(Node node, NodeEqualityPredicate equalityPredicate) {
return searchForInheritedMatch(node, equalityPredicate).getResult();
}
public DataMutateResult setPermission(DataType dataType, Node node, boolean callEvent) {
if (hasPermission(dataType, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME) != Tristate.UNDEFINED) {
public DataMutateResult setNode(DataType dataType, Node node, boolean callEvent) {
if (hasNode(dataType, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME) != Tristate.UNDEFINED) {
return DataMutateResult.ALREADY_HAS;
}
@ -467,7 +435,7 @@ public abstract class PermissionHolder {
return DataMutateResult.SUCCESS;
}
public TemporaryDataMutateResult setPermission(DataType dataType, Node node, TemporaryMergeBehaviour mergeBehaviour) {
public TemporaryDataMutateResult setNode(DataType dataType, Node node, TemporaryMergeBehaviour mergeBehaviour) {
if (node.hasExpiry() && mergeBehaviour != TemporaryMergeBehaviour.FAIL_WITH_ALREADY_HAS) {
Node otherMatch = getData(dataType).immutable().values().stream()
.filter(NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE.equalTo(node))
@ -507,11 +475,11 @@ public abstract class PermissionHolder {
}
// Fallback to the normal handling.
return new TemporaryResult(setPermission(dataType, node, true), node);
return new TemporaryResult(setNode(dataType, node, true), node);
}
public DataMutateResult unsetPermission(DataType dataType, Node node) {
if (hasPermission(dataType, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE) == Tristate.UNDEFINED) {
public DataMutateResult unsetNode(DataType dataType, Node node) {
if (hasNode(dataType, node, NodeEqualityPredicate.IGNORE_EXPIRY_TIME_AND_VALUE) == Tristate.UNDEFINED) {
return DataMutateResult.LACKS;
}
@ -552,7 +520,7 @@ public abstract class PermissionHolder {
return true;
}
public boolean clearNodes(DataType dataType, ContextSet contextSet) {
public boolean clearNodes(DataType dataType, ContextSet contextSet, boolean giveDefault) {
NodeMap data = getData(dataType);
ImmutableCollection<? extends Node> before = data.immutable().values();
@ -562,6 +530,10 @@ public abstract class PermissionHolder {
data.clear(contextSet);
}
if (getType() == HolderType.USER && giveDefault) {
getPlugin().getUserManager().giveDefaultIfNeeded((User) this, false);
}
invalidateCache();
ImmutableCollection<? extends Node> after = data.immutable().values();

View File

@ -37,7 +37,6 @@ import net.luckperms.api.context.ContextSet;
import net.luckperms.api.model.DataMutateResult;
import net.luckperms.api.model.DataType;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.track.DemotionResult;
import net.luckperms.api.track.PromotionResult;
@ -52,7 +51,7 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public final class Track implements Identifiable<String> {
public final class Track {
/**
* The name of the track
@ -87,11 +86,6 @@ public final class Track implements Identifiable<String> {
return this.apiDelegate;
}
@Override
public String getId() {
return getName();
}
/**
* Gets an ordered list of the groups on this track
*
@ -279,9 +273,7 @@ public final class Track implements Identifiable<String> {
}
// find all groups that are inherited by the user in the exact contexts given and applicable to this track
List<InheritanceNode> nodes = user.normalData().immutable().get(context.immutableCopy()).stream()
.filter(NodeType.INHERITANCE::matches)
.map(NodeType.INHERITANCE::cast)
List<InheritanceNode> nodes = user.normalData().immutableInheritance().get(context.immutableCopy()).stream()
.filter(Node::getValue)
.filter(node -> containsGroup(node.getGroupName()))
.distinct()
@ -303,7 +295,7 @@ public final class Track implements Identifiable<String> {
return PromotionResults.undefinedFailure();
}
user.setPermission(DataType.NORMAL, Inheritance.builder(nextGroup.getId()).withContext(context).build(), true);
user.setNode(DataType.NORMAL, Inheritance.builder(nextGroup.getName()).withContext(context).build(), true);
this.plugin.getEventFactory().handleUserPromote(user, this, null, first, sender);
return PromotionResults.addedToFirst(first);
}
@ -329,8 +321,8 @@ public final class Track implements Identifiable<String> {
return PromotionResults.undefinedFailure();
}
user.unsetPermission(DataType.NORMAL, oldNode);
user.setPermission(DataType.NORMAL, Inheritance.builder(nextGroup.getName()).withContext(context).build(), true);
user.unsetNode(DataType.NORMAL, oldNode);
user.setNode(DataType.NORMAL, Inheritance.builder(nextGroup.getName()).withContext(context).build(), true);
if (context.isEmpty() && user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(old)) {
user.getPrimaryGroup().setStoredValue(nextGroup.getName());
@ -346,9 +338,7 @@ public final class Track implements Identifiable<String> {
}
// find all groups that are inherited by the user in the exact contexts given and applicable to this track
List<InheritanceNode> nodes = user.normalData().immutable().get(context.immutableCopy()).stream()
.filter(NodeType.INHERITANCE::matches)
.map(NodeType.INHERITANCE::cast)
List<InheritanceNode> nodes = user.normalData().immutableInheritance().get(context.immutableCopy()).stream()
.filter(Node::getValue)
.filter(node -> containsGroup(node.getGroupName()))
.distinct()
@ -375,7 +365,7 @@ public final class Track implements Identifiable<String> {
return DemotionResults.removedFromFirst(null);
}
user.unsetPermission(DataType.NORMAL, oldNode);
user.unsetNode(DataType.NORMAL, oldNode);
this.plugin.getEventFactory().handleUserDemote(user, this, old, null, sender);
return DemotionResults.removedFromFirst(old);
}
@ -385,8 +375,8 @@ public final class Track implements Identifiable<String> {
return DemotionResults.malformedTrack(previous);
}
user.unsetPermission(DataType.NORMAL, oldNode);
user.setPermission(DataType.NORMAL, Inheritance.builder(previousGroup.getName()).withContext(context).build(), true);
user.unsetNode(DataType.NORMAL, oldNode);
user.setNode(DataType.NORMAL, Inheritance.builder(previousGroup.getName()).withContext(context).build(), true);
if (context.isEmpty() && user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME).equalsIgnoreCase(old)) {
user.getPrimaryGroup().setStoredValue(previousGroup.getName());

View File

@ -32,25 +32,23 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.primarygroup.ContextualHolder;
import me.lucko.luckperms.common.primarygroup.PrimaryGroupHolder;
import net.luckperms.api.model.DataType;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.Optional;
import java.util.UUID;
public class User extends PermissionHolder implements Identifiable<UserIdentifier> {
public class User extends PermissionHolder {
private final ApiUser apiDelegate = new ApiUser(this);
/**
* The users Mojang UUID
*/
private final UUID uuid;
private final UUID uniqueId;
/**
* The last known username of a player
*/
private @Nullable String name = null;
private @Nullable String username = null;
/**
* The users primary group
@ -62,21 +60,14 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
*/
private final UserCachedDataManager cachedData;
public User(UUID uuid, String name, LuckPermsPlugin plugin) {
public User(UUID uniqueId, LuckPermsPlugin plugin) {
super(plugin);
this.uuid = uuid;
setName(name, false);
this.uniqueId = uniqueId;
this.primaryGroup = plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION).apply(this);
this.cachedData = new UserCachedDataManager(this);
getPlugin().getEventFactory().handleUserCacheLoad(this, this.cachedData);
}
public User(UUID uuid, LuckPermsPlugin plugin) {
this(uuid, null, plugin);
}
@Override
protected void invalidateCache() {
super.invalidateCache();
@ -87,27 +78,22 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
}
}
public UUID getUuid() {
return this.uuid;
public UUID getUniqueId() {
return this.uniqueId;
}
public Optional<String> getName() {
return Optional.ofNullable(this.name);
public Optional<String> getUsername() {
return Optional.ofNullable(this.username);
}
@Override
public String getObjectName() {
return this.uuid.toString();
}
@Override
public UserIdentifier getId() {
return UserIdentifier.of(this.uuid, this.name);
return this.uniqueId.toString();
}
@Override
public String getFormattedDisplayName() {
return this.name != null ? this.name : this.uuid.toString();
return this.username != null ? this.username : this.uniqueId.toString();
}
@Override
@ -135,17 +121,17 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
* @param weak if true, the value will only be updated if a value hasn't been set previously.
* @return true if a change was made
*/
public boolean setName(String name, boolean weak) {
public boolean setUsername(String name, boolean weak) {
if (name != null && name.length() > 16) {
return false; // nope
}
// if weak is true, only update the value in the User if it's null
if (weak && this.name != null) {
if (weak && this.username != null) {
// try to update casing if they're equalIgnoreCase
if (this.name.equalsIgnoreCase(name)) {
this.name = name;
if (this.username.equalsIgnoreCase(name)) {
this.username = name;
}
return false;
@ -157,21 +143,21 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
}
// if one or the other is null, just update and return true
if ((this.name == null) != (name == null)) {
this.name = name;
if ((this.username == null) != (name == null)) {
this.username = name;
return true;
}
if (this.name == null) {
if (this.username == null) {
// they're both null
return false;
} else {
// both non-null
if (this.name.equalsIgnoreCase(name)) {
this.name = name; // update case anyway, but return false
if (this.username.equalsIgnoreCase(name)) {
this.username = name; // update case anyway, but return false
return false;
} else {
this.name = name;
this.username = name;
return true;
}
}
@ -182,35 +168,22 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
return HolderType.USER;
}
/**
* Clear all of the users permission nodes
*/
public boolean clearEnduringNodes() {
boolean ret = clearNodes(DataType.NORMAL, null);
if (!ret) {
return false;
}
getPlugin().getUserManager().giveDefaultIfNeeded(this, false);
return true;
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof User)) return false;
final User other = (User) o;
return this.uuid.equals(other.uuid);
return this.uniqueId.equals(other.uniqueId);
}
@Override
public int hashCode() {
return this.uuid.hashCode();
return this.uniqueId.hashCode();
}
@Override
public String toString() {
return "User(uuid=" + this.uuid + ")";
return "User(uuid=" + this.uniqueId + ")";
}
}

View File

@ -35,39 +35,34 @@ import java.util.UUID;
/**
* Used to identify a specific {@link User}.
*/
public final class UserIdentifier implements Identifiable<UUID> {
public final class UserIdentifier {
/**
* Creates a {@link UserIdentifier}.
*
* @param uuid the uuid of the user
* @param uniqueId the uuid of the user
* @param username the username of the user, nullable
* @return a new identifier
*/
public static UserIdentifier of(@NonNull UUID uuid, @Nullable String username) {
Objects.requireNonNull(uuid, "uuid");
public static UserIdentifier of(@NonNull UUID uniqueId, @Nullable String username) {
Objects.requireNonNull(uniqueId, "uuid");
if (username == null || username.equalsIgnoreCase("null") || username.isEmpty()) {
username = null;
}
return new UserIdentifier(uuid, username);
return new UserIdentifier(uniqueId, username);
}
private final UUID uuid;
private final UUID uniqueId;
private final String username;
private UserIdentifier(UUID uuid, String username) {
this.uuid = uuid;
private UserIdentifier(UUID uniqueId, String username) {
this.uniqueId = uniqueId;
this.username = username;
}
public UUID getUuid() {
return this.uuid;
}
@Override
public UUID getId() {
return getUuid();
public UUID getUniqueId() {
return this.uniqueId;
}
public Optional<String> getUsername() {
@ -79,16 +74,16 @@ public final class UserIdentifier implements Identifiable<UUID> {
if (o == this) return true;
if (!(o instanceof UserIdentifier)) return false;
final UserIdentifier other = (UserIdentifier) o;
return this.uuid.equals(other.uuid);
return this.uniqueId.equals(other.uniqueId);
}
@Override
public int hashCode() {
return this.uuid.hashCode();
return this.uniqueId.hashCode();
}
@Override
public String toString() {
return "UserIdentifier(uuid=" + this.uuid + ", username=" + this.username + ")";
return "UserIdentifier(uniqueId=" + this.uniqueId + ", username=" + this.username + ")";
}
}

View File

@ -28,7 +28,6 @@ package me.lucko.luckperms.common.model.manager;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.common.cache.LoadingMap;
import me.lucko.luckperms.common.model.Identifiable;
import java.util.Map;
@ -39,7 +38,7 @@ import java.util.Map;
* @param <C> the super class being managed
* @param <T> the implementation class this manager is "managing"
*/
public abstract class AbstractManager<I, C extends Identifiable<I>, T extends C> implements Manager<I, C, T> {
public abstract class AbstractManager<I, C, T extends C> implements Manager<I, C, T> {
private final LoadingMap<I, T> objects = LoadingMap.of(this);
@ -70,13 +69,6 @@ public abstract class AbstractManager<I, C extends Identifiable<I>, T extends C>
}
}
@Override
public void unload(C object) {
if (object != null) {
unload(object.getId());
}
}
protected I sanitizeIdentifier(I i) {
return i;
}

View File

@ -25,8 +25,6 @@
package me.lucko.luckperms.common.model.manager;
import me.lucko.luckperms.common.model.Identifiable;
import java.util.Map;
import java.util.function.Function;
@ -37,7 +35,7 @@ import java.util.function.Function;
* @param <C> the super class being managed
* @param <T> the implementation class this manager is "managing"
*/
public interface Manager<I, C extends Identifiable<I>, T extends C> extends Function<I, T> {
public interface Manager<I, C, T extends C> extends Function<I, T> {
/**
* Gets a map containing all cached instances held by this manager.
@ -79,11 +77,4 @@ public interface Manager<I, C extends Identifiable<I>, T extends C> extends Func
*/
void unload(I id);
/**
* Removes and unloads the object from the manager
*
* @param object The object to unload
*/
void unload(C object);
}

View File

@ -30,7 +30,6 @@ import com.google.common.collect.ImmutableCollection;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.UserIdentifier;
import me.lucko.luckperms.common.model.manager.AbstractManager;
import me.lucko.luckperms.common.model.manager.group.GroupManager;
import me.lucko.luckperms.common.node.types.Inheritance;
@ -38,7 +37,6 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.luckperms.api.model.DataType;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeType;
import net.luckperms.api.node.types.InheritanceNode;
import java.util.Optional;
@ -47,7 +45,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
public abstract class AbstractUserManager<T extends User> extends AbstractManager<UserIdentifier, User, T> implements UserManager<T> {
public abstract class AbstractUserManager<T extends User> extends AbstractManager<UUID, User, T> implements UserManager<T> {
private final LuckPermsPlugin plugin;
private final UserHousekeeper housekeeper;
@ -59,18 +57,16 @@ public abstract class AbstractUserManager<T extends User> extends AbstractManage
}
@Override
public T getOrMake(UserIdentifier id) {
T ret = super.getOrMake(id);
if (id.getUsername().isPresent()) {
ret.setName(id.getUsername().get(), false);
}
return ret;
public T getOrMake(UUID id, String username) {
T user = getOrMake(id);
user.setUsername(username, false);
return user;
}
@Override
public T getByUsername(String name) {
for (T user : getAll().values()) {
Optional<String> n = user.getName();
Optional<String> n = user.getUsername();
if (n.isPresent() && n.get().equalsIgnoreCase(name)) {
return user;
}
@ -78,32 +74,25 @@ public abstract class AbstractUserManager<T extends User> extends AbstractManage
return null;
}
@Override
public T getIfLoaded(UUID uuid) {
return getIfLoaded(UserIdentifier.of(uuid, null));
}
@Override
public boolean giveDefaultIfNeeded(User user, boolean save) {
boolean work = false;
// check that they are actually a member of their primary group, otherwise remove it
if (this.plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION_METHOD).equals("stored")) {
String pg = user.getPrimaryGroup().getValue();
boolean has = false;
String primaryGroup = user.getPrimaryGroup().getValue();
boolean memberOfPrimaryGroup = false;
for (Node node : user.normalData().immutable().get(ImmutableContextSetImpl.EMPTY)) {
if (node instanceof InheritanceNode && ((InheritanceNode) node).getGroupName().equalsIgnoreCase(pg)) {
has = true;
for (InheritanceNode node : user.normalData().immutableInheritance().get(ImmutableContextSetImpl.EMPTY)) {
if (node.getGroupName().equalsIgnoreCase(primaryGroup)) {
memberOfPrimaryGroup = true;
break;
}
}
// need to find a new primary group for the user.
if (!has) {
String group = user.normalData().immutable().get(ImmutableContextSetImpl.EMPTY).stream()
.filter(NodeType.INHERITANCE::matches)
.map(NodeType.INHERITANCE::cast)
if (!memberOfPrimaryGroup) {
String group = user.normalData().immutableInheritance().get(ImmutableContextSetImpl.EMPTY).stream()
.findFirst()
.map(InheritanceNode::getGroupName)
.orElse(null);
@ -119,21 +108,12 @@ public abstract class AbstractUserManager<T extends User> extends AbstractManage
// check that all users are member of at least one group
boolean hasGroup = false;
if (user.getPrimaryGroup().getStoredValue().isPresent()) {
for (Node node : user.normalData().immutable().values()) {
if (!node.getContexts().isEmpty()) {
continue;
}
if (node instanceof InheritanceNode) {
hasGroup = true;
break;
}
}
hasGroup = !user.normalData().immutableInheritance().get(ImmutableContextSetImpl.EMPTY).isEmpty();
}
if (!hasGroup) {
user.getPrimaryGroup().setStoredValue(GroupManager.DEFAULT_GROUP_NAME);
user.setPermission(DataType.NORMAL, Inheritance.builder(GroupManager.DEFAULT_GROUP_NAME).build(), false);
user.setNode(DataType.NORMAL, Inheritance.builder(GroupManager.DEFAULT_GROUP_NAME).build(), false);
work = true;
}
@ -151,7 +131,7 @@ public abstract class AbstractUserManager<T extends User> extends AbstractManage
@Override
public void cleanup(User user) {
this.housekeeper.cleanup(user.getId());
this.housekeeper.cleanup(user.getUniqueId());
}
@Override
@ -159,7 +139,7 @@ public abstract class AbstractUserManager<T extends User> extends AbstractManage
return CompletableFuture.runAsync(
() -> {
Stream.concat(
getAll().keySet().stream().map(UserIdentifier::getUuid),
getAll().keySet().stream(),
this.plugin.getBootstrap().getOnlinePlayers()
).forEach(u -> this.plugin.getStorage().loadUser(u, null).join());
},

View File

@ -26,9 +26,9 @@
package me.lucko.luckperms.common.model.manager.user;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.UserIdentifier;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class StandardUserManager extends AbstractUserManager<User> {
@ -40,9 +40,7 @@ public class StandardUserManager extends AbstractUserManager<User> {
}
@Override
public User apply(UserIdentifier id) {
return !id.getUsername().isPresent() ?
new User(id.getUuid(), this.plugin) :
new User(id.getUuid(), id.getUsername().get(), this.plugin);
public User apply(UUID id) {
return new User(id, this.plugin);
}
}

View File

@ -25,7 +25,6 @@
package me.lucko.luckperms.common.model.manager.user;
import me.lucko.luckperms.common.model.UserIdentifier;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.util.ExpiringSet;
@ -67,21 +66,19 @@ public class UserHousekeeper implements Runnable {
@Override
public void run() {
for (UserIdentifier entry : this.userManager.getAll().keySet()) {
for (UUID entry : this.userManager.getAll().keySet()) {
cleanup(entry);
}
}
public void cleanup(UserIdentifier identifier) {
UUID uuid = identifier.getUuid();
public void cleanup(UUID uuid) {
// unload users which aren't online and who haven't been online (or tried to login) recently
if (this.recentlyUsed.contains(uuid) || this.recentlyUsedApi.contains(uuid) || this.plugin.getBootstrap().isPlayerOnline(uuid)) {
return;
}
// unload them
this.userManager.unload(identifier);
this.userManager.unload(uuid);
}
public static TimeoutSettings timeoutSettings(long duration, TimeUnit unit) {

View File

@ -27,13 +27,14 @@ package me.lucko.luckperms.common.model.manager.user;
import me.lucko.luckperms.common.calculator.PermissionCalculator;
import me.lucko.luckperms.common.model.User;
import me.lucko.luckperms.common.model.UserIdentifier;
import me.lucko.luckperms.common.model.manager.Manager;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
public interface UserManager<T extends User> extends Manager<UserIdentifier, User, T> {
public interface UserManager<T extends User> extends Manager<UUID, User, T> {
T getOrMake(UUID id, String username);
/**
* Get a user object by name

View File

@ -1,85 +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.node.utils;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.Tristate;
import net.luckperms.api.node.metadata.types.InheritanceOriginMetadata;
import java.util.Objects;
import java.util.Optional;
/**
* The result of an inheritance lookup
*/
public final class InheritanceInfo {
public static InheritanceInfo of(Node node) {
Objects.requireNonNull(node, "node");
return new InheritanceInfo(Tristate.of(node.getValue()), node.metadata(InheritanceOriginMetadata.KEY).getOrigin());
}
public static InheritanceInfo empty() {
return new InheritanceInfo(Tristate.UNDEFINED, null);
}
private final Tristate result;
private final String location;
private InheritanceInfo(Tristate result, String location) {
this.result = result;
this.location = location;
}
public Optional<String> getLocation() {
return Optional.ofNullable(this.location);
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof InheritanceInfo)) return false;
final InheritanceInfo other = (InheritanceInfo) o;
return this.result == other.result && this.getLocation().equals(other.getLocation());
}
@Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
result = result * PRIME + this.result.hashCode();
result = result * PRIME + this.getLocation().hashCode();
return result;
}
@Override
public String toString() {
return "InheritanceInfo(result=" + this.result + ", location=" + this.getLocation() + ")";
}
public Tristate getResult() {
return this.result;
}
}

View File

@ -1,68 +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.node.utils;
import net.luckperms.api.node.Node;
import net.luckperms.api.node.NodeEqualityPredicate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public final class NodeTools {
private NodeTools() {}
public static <T extends Node> void removeEqual(Iterator<T> it, NodeEqualityPredicate equalityPredicate) {
List<T> alreadyIn = new ArrayList<>();
iterate:
while (it.hasNext()) {
T next = it.next();
for (T other : alreadyIn) {
if (next.equals(other, equalityPredicate)) {
it.remove();
continue iterate;
}
}
alreadyIn.add(next);
}
}
public static <T extends Node> void removeSamePermission(Iterator<T> it) {
Set<String> alreadyIn = new HashSet<>();
while (it.hasNext()) {
T next = it.next();
if (!alreadyIn.add(next.getKey())) {
it.remove();
}
}
}
}

View File

@ -78,8 +78,6 @@ public final class ShorthandParser {
}
private static Set<String> captureResults(String s) {
s = s.replace('(', '{').replace(')', '}');
int openingIndex = s.indexOf('{');
if (openingIndex == -1) {
return null;
@ -113,7 +111,6 @@ public final class ShorthandParser {
@Override
public Iterable<String> apply(String s) {
s = s.replace('|', ',');
if (!s.contains(",")) {
return Collections.singleton(s);
}
@ -134,13 +131,19 @@ public final class ShorthandParser {
@Override
public Iterable<String> apply(String s) {
int index = s.indexOf("-");
if (index == -1) return null;
if (index == -1) {
return null;
}
Integer before = parseInt(s.substring(0, index));
if (before == null) return null;
if (before == null) {
return null;
}
Integer after = parseInt(s.substring(index + 1));
if (after == null) return null;
if (after == null) {
return null;
}
return IntStream.rangeClosed(before, after).mapToObj(Integer::toString).collect(Collectors.toList());
}
@ -159,13 +162,19 @@ public final class ShorthandParser {
@Override
public Iterable<String> apply(String s) {
int index = s.indexOf("-");
if (index == -1) return null;
if (index == -1) {
return null;
}
String before = s.substring(0, index);
if (before.length() != 1) return null;
if (before.length() != 1) {
return null;
}
String after = s.substring(index + 1);
if (after.length() != 1) return null;
if (after.length() != 1) {
return null;
}
return getCharRange(before.charAt(0), after.charAt(0));
}

View File

@ -163,10 +163,10 @@ public interface LuckPermsBootstrap {
* Gets a player object linked to this User. The returned object must be the same type
* as the instance used in the platforms ContextManager
*
* @param uuid the users unique id
* @param uniqueId the users unique id
* @return a player object, or null, if one couldn't be found.
*/
Optional<?> getPlayer(UUID uuid);
Optional<?> getPlayer(UUID uniqueId);
/**
* Lookup a uuid from a username, using the servers internal uuid cache.
@ -174,15 +174,15 @@ public interface LuckPermsBootstrap {
* @param username the username to lookup
* @return an optional uuid, if found
*/
Optional<UUID> lookupUuid(String username);
Optional<UUID> lookupUniqueId(String username);
/**
* Lookup a username from a uuid, using the servers internal uuid cache.
*
* @param uuid the uuid to lookup
* @param uniqueId the uuid to lookup
* @return an optional username, if found
*/
Optional<String> lookupUsername(UUID uuid);
Optional<String> lookupUsername(UUID uniqueId);
/**
* Gets the number of users online on the platform
@ -208,9 +208,9 @@ public interface LuckPermsBootstrap {
/**
* Checks if a user is online
*
* @param uuid the users external uuid
* @param uniqueId the users external uuid
* @return true if the user is online
*/
boolean isPlayerOnline(UUID uuid);
boolean isPlayerOnline(UUID uniqueId);
}

View File

@ -56,22 +56,22 @@ public abstract class AbstractConnectionListener {
return this.uniqueConnections;
}
protected void recordConnection(UUID uuid) {
this.uniqueConnections.add(uuid);
protected void recordConnection(UUID uniqueId) {
this.uniqueConnections.add(uniqueId);
}
public User loadUser(UUID uuid, String username) {
public User loadUser(UUID uniqueId, String username) {
final long startTime = System.currentTimeMillis();
// register with the housekeeper to avoid accidental unloads
this.plugin.getUserManager().getHouseKeeper().registerUsage(uuid);
this.plugin.getUserManager().getHouseKeeper().registerUsage(uniqueId);
// save uuid data.
PlayerSaveResult saveResult = this.plugin.getStorage().savePlayerData(uuid, username).join();
PlayerSaveResult saveResult = this.plugin.getStorage().savePlayerData(uniqueId, username).join();
// fire UserFirstLogin event
if (saveResult.includes(PlayerSaveResult.Outcome.CLEAN_INSERT)) {
this.plugin.getEventFactory().handleUserFirstLogin(uuid, username);
this.plugin.getEventFactory().handleUserFirstLogin(uniqueId, username);
}
// most likely because ip forwarding is not setup correctly
@ -80,9 +80,9 @@ public abstract class AbstractConnectionListener {
Set<UUID> otherUuids = saveResult.getOtherUniqueIds();
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 " + otherUuids + " but is now connecting with '" + uuid + "'");
this.plugin.getLogger().warn("'" + username + "' has previously used the unique ids " + otherUuids + " but is now connecting with '" + uniqueId + "'");
if (uuid.version() == 4) {
if (uniqueId.version() == 4) {
if (this.plugin.getBootstrap().getType() == Platform.Type.BUNGEECORD) {
this.plugin.getLogger().warn("The UUID the player is connecting with now is Mojang-assigned (type 4). This implies that BungeeCord's IP-Forwarding has not been setup correctly on one (or more) of the backend servers.");
} if (this.plugin.getBootstrap().getType() == Platform.Type.VELOCITY) {
@ -92,14 +92,14 @@ public abstract class AbstractConnectionListener {
this.plugin.getLogger().warn("If you're using BungeeCord/Velocity, please ensure that IP-Forwarding is setup correctly on all of your backend servers!");
}
} else {
this.plugin.getLogger().warn("The UUID the player is connecting with now is NOT Mojang-assigned (type " + uuid.version() + "). This implies that THIS server is not authenticating correctly, but one (or more) of the other servers/proxies in the network are.");
this.plugin.getLogger().warn("The UUID the player is connecting with now is NOT Mojang-assigned (type " + uniqueId.version() + "). This implies that THIS server is not authenticating correctly, but one (or more) of the other servers/proxies in the network are.");
this.plugin.getLogger().warn("If you're using BungeeCord/Velocity, please ensure that IP-Forwarding is setup correctly on all of your backend servers!");
}
this.plugin.getLogger().warn("See here for more info: https://github.com/lucko/LuckPerms/wiki/Network-Installation#pre-setup");
}
User user = this.plugin.getStorage().loadUser(uuid, username).join();
User user = this.plugin.getStorage().loadUser(uniqueId, username).join();
if (user == null) {
throw new NullPointerException("User is null");
}
@ -112,16 +112,16 @@ public abstract class AbstractConnectionListener {
return user;
}
public void handleDisconnect(UUID uuid) {
public void handleDisconnect(UUID uniqueId) {
// Register with the housekeeper, so the User's instance will stick
// around for a bit after they disconnect
this.plugin.getUserManager().getHouseKeeper().registerUsage(uuid);
this.plugin.getUserManager().getHouseKeeper().registerUsage(uniqueId);
// force a clear of transient nodes
this.plugin.getBootstrap().getScheduler().executeAsync(() -> {
User user = this.plugin.getUserManager().getIfLoaded(uuid);
User user = this.plugin.getUserManager().getIfLoaded(uniqueId);
if (user != null) {
user.clearNodes(DataType.TRANSIENT, null);
user.clearNodes(DataType.TRANSIENT, null, false);
}
});
}

View File

@ -45,7 +45,7 @@ public class ParentsByWeightHolder extends ContextualHolder {
@Override
protected @NonNull Optional<String> calculateValue(QueryOptions queryOptions) {
Set<Group> groups = new LinkedHashSet<>();
for (InheritanceNode node : this.user.getOwnGroupNodes(queryOptions)) {
for (InheritanceNode node : this.user.getOwnInheritanceNodes(queryOptions)) {
Group group = this.user.getPlugin().getGroupManager().getIfLoaded(node.getGroupName());
if (group != null) {
groups.add(group);

View File

@ -48,14 +48,14 @@ public final class AbstractSender<T> implements Sender {
private final SenderFactory<T> factory;
private final WeakReference<T> sender;
private final UUID uuid;
private final UUID uniqueId;
private final String name;
AbstractSender(LuckPermsPlugin platform, SenderFactory<T> factory, T t) {
this.platform = platform;
this.factory = factory;
this.sender = new WeakReference<>(t);
this.uuid = factory.getUuid(t);
this.uniqueId = factory.getUniqueId(t);
this.name = factory.getName(t);
}
@ -65,8 +65,8 @@ public final class AbstractSender<T> implements Sender {
}
@Override
public UUID getUuid() {
return this.uuid;
public UUID getUniqueId() {
return this.uniqueId;
}
@Override
@ -135,11 +135,11 @@ public final class AbstractSender<T> implements Sender {
if (o == this) return true;
if (!(o instanceof AbstractSender)) return false;
final AbstractSender that = (AbstractSender) o;
return this.getUuid().equals(that.getUuid());
return this.getUniqueId().equals(that.getUniqueId());
}
@Override
public int hashCode() {
return this.uuid.hashCode();
return this.uniqueId.hashCode();
}
}

View File

@ -36,12 +36,12 @@ import java.util.UUID;
public abstract class DummySender implements Sender {
private final LuckPermsPlugin platform;
private final UUID uuid;
private final UUID uniqueId;
private final String name;
public DummySender(LuckPermsPlugin plugin, UUID uuid, String name) {
public DummySender(LuckPermsPlugin plugin, UUID uniqueId, String name) {
this.platform = plugin;
this.uuid = uuid;
this.uniqueId = uniqueId;
this.name = name;
}
@ -77,8 +77,8 @@ public abstract class DummySender implements Sender {
}
@Override
public UUID getUuid() {
return this.uuid;
public UUID getUniqueId() {
return this.uniqueId;
}
@Override

View File

@ -107,7 +107,7 @@ public interface Sender {
*
* @return the sender's uuid
*/
UUID getUuid();
UUID getUniqueId();
/**
* Send a message to the Sender.
@ -157,7 +157,7 @@ public interface Sender {
* @return if the sender is the console
*/
default boolean isConsole() {
return CONSOLE_UUID.equals(getUuid()) || IMPORT_UUID.equals(getUuid());
return CONSOLE_UUID.equals(getUniqueId()) || IMPORT_UUID.equals(getUniqueId());
}
/**
@ -166,7 +166,7 @@ public interface Sender {
* @return if the sender is an import process
*/
default boolean isImport() {
return IMPORT_UUID.equals(getUuid());
return IMPORT_UUID.equals(getUniqueId());
}
/**

View File

@ -50,7 +50,7 @@ public abstract class SenderFactory<T> {
return this.plugin;
}
protected abstract UUID getUuid(T t);
protected abstract UUID getUniqueId(T t);
protected abstract String getName(T t);

View File

@ -132,9 +132,9 @@ public class Storage {
return makeFuture(() -> this.implementation.applyBulkUpdate(bulkUpdate));
}
public CompletableFuture<User> loadUser(UUID uuid, String username) {
public CompletableFuture<User> loadUser(UUID uniqueId, String username) {
return makeFuture(() -> {
User user = this.implementation.loadUser(uuid, username);
User user = this.implementation.loadUser(uniqueId, username);
if (user != null) {
this.plugin.getEventFactory().handleUserLoad(user);
}
@ -242,21 +242,21 @@ public class Storage {
});
}
public CompletableFuture<PlayerSaveResult> savePlayerData(UUID uuid, String username) {
public CompletableFuture<PlayerSaveResult> savePlayerData(UUID uniqueId, String username) {
return makeFuture(() -> {
PlayerSaveResult result = this.implementation.savePlayerData(uuid, username);
PlayerSaveResult result = this.implementation.savePlayerData(uniqueId, username);
if (result != null) {
this.plugin.getEventFactory().handlePlayerDataSave(uuid, username, result);
this.plugin.getEventFactory().handlePlayerDataSave(uniqueId, username, result);
}
return result;
});
}
public CompletableFuture<UUID> getPlayerUuid(String username) {
return makeFuture(() -> this.implementation.getPlayerUuid(username));
public CompletableFuture<UUID> getPlayerUniqueId(String username) {
return makeFuture(() -> this.implementation.getPlayerUniqueId(username));
}
public CompletableFuture<String> getPlayerName(UUID uuid) {
return makeFuture(() -> this.implementation.getPlayerName(uuid));
public CompletableFuture<String> getPlayerName(UUID uniqueId) {
return makeFuture(() -> this.implementation.getPlayerName(uniqueId));
}
}

View File

@ -65,7 +65,7 @@ public interface StorageImplementation {
void applyBulkUpdate(BulkUpdate bulkUpdate) throws Exception;
User loadUser(UUID uuid, String username) throws Exception;
User loadUser(UUID uniqueId, String username) throws Exception;
void saveUser(User user) throws Exception;
@ -95,9 +95,9 @@ public interface StorageImplementation {
void deleteTrack(Track track) throws Exception;
PlayerSaveResult savePlayerData(UUID uuid, String username) throws Exception;
PlayerSaveResult savePlayerData(UUID uniqueId, String username) throws Exception;
@Nullable UUID getPlayerUuid(String username) throws Exception;
@Nullable UUID getPlayerUniqueId(String username) throws Exception;
@Nullable String getPlayerName(UUID uuid) throws Exception;
@Nullable String getPlayerName(UUID uniqueId) throws Exception;
}

View File

@ -36,7 +36,6 @@ import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl;
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.model.UserIdentifier;
import me.lucko.luckperms.common.model.manager.group.GroupManager;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
import me.lucko.luckperms.common.node.types.Inheritance;
@ -196,35 +195,35 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio
}
@Override
public User loadUser(UUID uuid, String username) {
User user = this.plugin.getUserManager().getOrMake(UserIdentifier.of(uuid, username));
public User loadUser(UUID uniqueId, String username) {
User user = this.plugin.getUserManager().getOrMake(uniqueId, username);
user.getIoLock().lock();
try {
ConfigurationNode object = readFile(StorageLocation.USER, uuid.toString());
ConfigurationNode object = readFile(StorageLocation.USER, uniqueId.toString());
if (object != null) {
String name = object.getNode("name").getString();
user.getPrimaryGroup().setStoredValue(object.getNode(this.loader instanceof JsonLoader ? "primaryGroup" : "primary-group").getString());
user.setNodes(DataType.NORMAL, readNodes(object));
user.setName(name, true);
user.setUsername(name, true);
boolean save = this.plugin.getUserManager().giveDefaultIfNeeded(user, false);
if (user.getName().isPresent() && (name == null || !user.getName().get().equalsIgnoreCase(name))) {
if (user.getUsername().isPresent() && (name == null || !user.getUsername().get().equalsIgnoreCase(name))) {
save = true;
}
if (save | user.auditTemporaryPermissions()) {
if (save | user.auditTemporaryNodes()) {
saveUser(user);
}
} else {
if (this.plugin.getUserManager().shouldSave(user)) {
user.clearEnduringNodes();
user.clearNodes(DataType.NORMAL, null, true);
user.getPrimaryGroup().setStoredValue(null);
this.plugin.getUserManager().giveDefaultIfNeeded(user, false);
}
}
} catch (Exception e) {
throw reportException(uuid.toString(), e);
throw reportException(uniqueId.toString(), e);
} finally {
user.getIoLock().unlock();
}
@ -236,20 +235,20 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio
user.getIoLock().lock();
try {
if (!this.plugin.getUserManager().shouldSave(user)) {
saveFile(StorageLocation.USER, user.getUuid().toString(), null);
saveFile(StorageLocation.USER, user.getUniqueId().toString(), null);
} else {
ConfigurationNode data = SimpleConfigurationNode.root();
if (this instanceof SeparatedConfigurateStorage) {
data.getNode("uuid").setValue(user.getUuid().toString());
data.getNode("uuid").setValue(user.getUniqueId().toString());
}
data.getNode("name").setValue(user.getName().orElse("null"));
data.getNode("name").setValue(user.getUsername().orElse("null"));
data.getNode(this.loader instanceof JsonLoader ? "primaryGroup" : "primary-group").setValue(user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME));
writeNodes(data, user.normalData().immutable().values());
saveFile(StorageLocation.USER, user.getUuid().toString(), data);
saveFile(StorageLocation.USER, user.getUniqueId().toString(), data);
}
} catch (Exception e) {
throw reportException(user.getUuid().toString(), e);
throw reportException(user.getUniqueId().toString(), e);
} finally {
user.getIoLock().unlock();
}
@ -340,7 +339,7 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio
} finally {
group.getIoLock().unlock();
}
this.plugin.getGroupManager().unload(group);
this.plugin.getGroupManager().unload(group.getName());
}
@Override
@ -435,22 +434,22 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio
} finally {
track.getIoLock().unlock();
}
this.plugin.getTrackManager().unload(track);
this.plugin.getTrackManager().unload(track.getName());
}
@Override
public PlayerSaveResult savePlayerData(UUID uuid, String username) {
return this.uuidCache.addMapping(uuid, username);
public PlayerSaveResult savePlayerData(UUID uniqueId, String username) {
return this.uuidCache.addMapping(uniqueId, username);
}
@Override
public UUID getPlayerUuid(String username) {
public UUID getPlayerUniqueId(String username) {
return this.uuidCache.lookupUuid(username);
}
@Override
public String getPlayerName(UUID uuid) {
return this.uuidCache.lookupUsername(uuid);
public String getPlayerName(UUID uniqueId) {
return this.uuidCache.lookupUsername(uniqueId);
}
private static ImmutableContextSet readContexts(ConfigurationNode attributes) {

View File

@ -27,6 +27,8 @@ package me.lucko.luckperms.common.storage.implementation.file;
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
import me.lucko.luckperms.common.bulkupdate.comparison.Constraint;
import me.lucko.luckperms.common.model.Group;
import me.lucko.luckperms.common.model.Track;
import me.lucko.luckperms.common.model.manager.group.GroupManager;
import me.lucko.luckperms.common.model.manager.track.TrackManager;
import me.lucko.luckperms.common.node.model.HeldNodeImpl;
@ -312,7 +314,8 @@ public class CombinedConfigurateStorage extends AbstractConfigurateStorage {
GroupManager<?> gm = this.plugin.getGroupManager();
gm.getAll().values().stream()
.filter(g -> !groups.contains(g.getName()))
.map(Group::getName)
.filter(g -> !groups.contains(g))
.forEach(gm::unload);
}
@ -366,7 +369,8 @@ public class CombinedConfigurateStorage extends AbstractConfigurateStorage {
TrackManager<?> tm = this.plugin.getTrackManager();
tm.getAll().values().stream()
.filter(t -> !tracks.contains(t.getName()))
.map(Track::getName)
.filter(t -> !tracks.contains(t))
.forEach(tm::unload);
}

View File

@ -27,6 +27,8 @@ package me.lucko.luckperms.common.storage.implementation.file;
import me.lucko.luckperms.common.bulkupdate.BulkUpdate;
import me.lucko.luckperms.common.bulkupdate.comparison.Constraint;
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.model.manager.group.GroupManager;
import me.lucko.luckperms.common.model.manager.track.TrackManager;
@ -305,7 +307,8 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
GroupManager<?> gm = this.plugin.getGroupManager();
gm.getAll().values().stream()
.filter(g -> !groups.contains(g.getName()))
.map(Group::getName)
.filter(g -> !groups.contains(g))
.forEach(gm::unload);
}
@ -361,7 +364,8 @@ public class SeparatedConfigurateStorage extends AbstractConfigurateStorage {
TrackManager<?> tm = this.plugin.getTrackManager();
tm.getAll().values().stream()
.filter(t -> !tracks.contains(t.getName()))
.map(Track::getName)
.filter(t -> !tracks.contains(t))
.forEach(tm::unload);
}

View File

@ -45,7 +45,6 @@ import me.lucko.luckperms.common.context.contextset.MutableContextSetImpl;
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.model.UserIdentifier;
import me.lucko.luckperms.common.model.manager.group.GroupManager;
import me.lucko.luckperms.common.model.manager.track.TrackManager;
import me.lucko.luckperms.common.node.factory.NodeBuilders;
@ -297,12 +296,12 @@ public class MongoStorage implements StorageImplementation {
}
@Override
public User loadUser(UUID uuid, String username) {
User user = this.plugin.getUserManager().getOrMake(UserIdentifier.of(uuid, username));
public User loadUser(UUID uniqueId, String username) {
User user = this.plugin.getUserManager().getOrMake(uniqueId, username);
user.getIoLock().lock();
try {
MongoCollection<Document> c = this.database.getCollection(this.prefix + "users");
try (MongoCursor<Document> cursor = c.find(new Document("_id", user.getUuid())).iterator()) {
try (MongoCursor<Document> cursor = c.find(new Document("_id", user.getUniqueId())).iterator()) {
if (cursor.hasNext()) {
// User exists, let's load.
Document d = cursor.next();
@ -310,19 +309,19 @@ public class MongoStorage implements StorageImplementation {
String name = d.getString("name");
user.getPrimaryGroup().setStoredValue(d.getString("primaryGroup"));
user.setNodes(DataType.NORMAL, nodesFromDoc(d));
user.setName(name, true);
user.setUsername(name, true);
boolean save = this.plugin.getUserManager().giveDefaultIfNeeded(user, false);
if (user.getName().isPresent() && (name == null || !user.getName().get().equalsIgnoreCase(name))) {
if (user.getUsername().isPresent() && (name == null || !user.getUsername().get().equalsIgnoreCase(name))) {
save = true;
}
if (save | user.auditTemporaryPermissions()) {
c.replaceOne(new Document("_id", user.getUuid()), userToDoc(user));
if (save | user.auditTemporaryNodes()) {
c.replaceOne(new Document("_id", user.getUniqueId()), userToDoc(user));
}
} else {
if (this.plugin.getUserManager().shouldSave(user)) {
user.clearEnduringNodes();
user.clearNodes(DataType.NORMAL, null, true);
user.getPrimaryGroup().setStoredValue(null);
this.plugin.getUserManager().giveDefaultIfNeeded(user, false);
}
@ -340,9 +339,9 @@ public class MongoStorage implements StorageImplementation {
try {
MongoCollection<Document> c = this.database.getCollection(this.prefix + "users");
if (!this.plugin.getUserManager().shouldSave(user)) {
c.deleteOne(new Document("_id", user.getUuid()));
c.deleteOne(new Document("_id", user.getUniqueId()));
} else {
c.replaceOne(new Document("_id", user.getUuid()), userToDoc(user), new ReplaceOptions().upsert(true));
c.replaceOne(new Document("_id", user.getUniqueId()), userToDoc(user), new ReplaceOptions().upsert(true));
}
} finally {
user.getIoLock().unlock();
@ -459,7 +458,8 @@ public class MongoStorage implements StorageImplementation {
GroupManager<?> gm = this.plugin.getGroupManager();
gm.getAll().values().stream()
.filter(g -> !groups.contains(g.getName()))
.map(Group::getName)
.filter(g -> !groups.contains(g))
.forEach(gm::unload);
}
@ -585,7 +585,8 @@ public class MongoStorage implements StorageImplementation {
TrackManager<?> tm = this.plugin.getTrackManager();
tm.getAll().values().stream()
.filter(t -> !tracks.contains(t.getName()))
.map(Track::getName)
.filter(t -> !tracks.contains(t))
.forEach(tm::unload);
}
@ -612,16 +613,16 @@ public class MongoStorage implements StorageImplementation {
}
@Override
public PlayerSaveResult savePlayerData(UUID uuid, String username) {
public PlayerSaveResult savePlayerData(UUID uniqueId, String username) {
username = username.toLowerCase();
MongoCollection<Document> c = this.database.getCollection(this.prefix + "uuid");
// find any existing mapping
String oldUsername = getPlayerName(uuid);
String oldUsername = getPlayerName(uniqueId);
// do the insert
if (!username.equalsIgnoreCase(oldUsername)) {
c.replaceOne(new Document("_id", uuid), new Document("_id", uuid).append("name", username), new ReplaceOptions().upsert(true));
c.replaceOne(new Document("_id", uniqueId), new Document("_id", uniqueId).append("name", username), new ReplaceOptions().upsert(true));
}
PlayerSaveResultImpl result = PlayerSaveResultImpl.determineBaseResult(username, oldUsername);
@ -632,7 +633,7 @@ public class MongoStorage implements StorageImplementation {
conflicting.add(cursor.next().get("_id", UUID.class));
}
}
conflicting.remove(uuid);
conflicting.remove(uniqueId);
if (!conflicting.isEmpty()) {
// remove the mappings for conflicting uuids
@ -644,7 +645,7 @@ public class MongoStorage implements StorageImplementation {
}
@Override
public UUID getPlayerUuid(String username) {
public UUID getPlayerUniqueId(String username) {
MongoCollection<Document> c = this.database.getCollection(this.prefix + "uuid");
Document doc = c.find(new Document("name", username.toLowerCase())).first();
if (doc != null) {
@ -654,9 +655,9 @@ public class MongoStorage implements StorageImplementation {
}
@Override
public String getPlayerName(UUID uuid) {
public String getPlayerName(UUID uniqueId) {
MongoCollection<Document> c = this.database.getCollection(this.prefix + "uuid");
Document doc = c.find(new Document("_id", uuid)).first();
Document doc = c.find(new Document("_id", uniqueId)).first();
if (doc != null) {
return doc.get("name", String.class);
}
@ -668,8 +669,8 @@ public class MongoStorage implements StorageImplementation {
.map(MongoStorage::nodeToDoc)
.collect(Collectors.toList());
return new Document("_id", user.getUuid())
.append("name", user.getName().orElse("null"))
return new Document("_id", user.getUniqueId())
.append("name", user.getUsername().orElse("null"))
.append("primaryGroup", user.getPrimaryGroup().getStoredValue().orElse(GroupManager.DEFAULT_GROUP_NAME))
.append("permissions", nodes);
}

Some files were not shown because too many files have changed in this diff Show More