diff --git a/api/src/main/java/net/luckperms/api/model/PlayerSaveResult.java b/api/src/main/java/net/luckperms/api/model/PlayerSaveResult.java index 8eca9fb60..80f13bf3c 100644 --- a/api/src/main/java/net/luckperms/api/model/PlayerSaveResult.java +++ b/api/src/main/java/net/luckperms/api/model/PlayerSaveResult.java @@ -61,15 +61,15 @@ public interface PlayerSaveResult { } /** - * Gets the old username involved in the result. + * Gets the previous username involved in the result. * *

Returns null when the result doesn't {@link #includes(Outcome) include} the * {@link Outcome#USERNAME_UPDATED} status.

* - * @return the old username + * @return the previous username * @see Outcome#USERNAME_UPDATED */ - @Nullable String getOldUsername(); + @Nullable String getPreviousUsername(); /** * Gets the other uuids involved in the result. diff --git a/api/src/main/java/net/luckperms/api/node/ChatMetaType.java b/api/src/main/java/net/luckperms/api/node/ChatMetaType.java index 6657d067b..87a85c177 100644 --- a/api/src/main/java/net/luckperms/api/node/ChatMetaType.java +++ b/api/src/main/java/net/luckperms/api/node/ChatMetaType.java @@ -26,6 +26,8 @@ package net.luckperms.api.node; import net.luckperms.api.node.types.ChatMetaNode; +import net.luckperms.api.node.types.PrefixNode; +import net.luckperms.api.node.types.SuffixNode; import org.checkerframework.checker.nullness.qual.NonNull; @@ -37,12 +39,32 @@ public enum ChatMetaType { /** * Represents a prefix */ - PREFIX(NodeType.PREFIX), + PREFIX(NodeType.PREFIX) { + @Override + public ChatMetaNode.@NonNull Builder builder() { + return PrefixNode.builder(); + } + + @Override + public ChatMetaNode.@NonNull Builder builder(@NonNull String prefix, int priority) { + return PrefixNode.builder(prefix, priority); + } + }, /** * Represents a suffix */ - SUFFIX(NodeType.SUFFIX); + SUFFIX(NodeType.SUFFIX) { + @Override + public ChatMetaNode.@NonNull Builder builder() { + return SuffixNode.builder(); + } + + @Override + public ChatMetaNode.@NonNull Builder builder(@NonNull String suffix, int priority) { + return SuffixNode.builder(suffix, priority); + } + }; private final String name; private final NodeType> nodeType; @@ -61,6 +83,22 @@ public enum ChatMetaType { return this.nodeType; } + /** + * Creates a {@link ChatMetaNode.Builder} for the {@link ChatMetaType}. + * + * @return a builder + */ + public abstract ChatMetaNode.@NonNull Builder builder(); + + /** + * Creates a {@link ChatMetaNode.Builder} for the {@link ChatMetaType}. + * + * @param value the value to set + * @param priority the priority to set + * @return a builder + */ + public abstract ChatMetaNode.@NonNull Builder builder(@NonNull String value, int priority); + @Override public String toString() { return this.name; diff --git a/api/src/main/java/net/luckperms/api/node/Node.java b/api/src/main/java/net/luckperms/api/node/Node.java index 257724b4c..f2ebc85f6 100644 --- a/api/src/main/java/net/luckperms/api/node/Node.java +++ b/api/src/main/java/net/luckperms/api/node/Node.java @@ -26,7 +26,6 @@ package net.luckperms.api.node; import net.luckperms.api.LuckPermsProvider; -import net.luckperms.api.context.ContextSet; import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.node.metadata.NodeMetadataKey; import net.luckperms.api.node.types.DisplayNameNode; @@ -42,7 +41,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import java.time.Instant; -import java.util.List; +import java.util.Collection; import java.util.Optional; import java.util.stream.Stream; @@ -134,21 +133,6 @@ public interface Node { return !getValue(); } - /** - * Gets if this node applies globally, and therefore has no specific context. - * - * @return true if this node applies globally, and has no specific context - */ - boolean appliesGlobally(); - - /** - * Gets if this node should apply in the given context - * - * @param contextSet the context set - * @return true if the node should apply - */ - boolean shouldApplyWithContext(@NonNull ContextSet contextSet); - /** * Resolves any shorthand parts of this node and returns the full list of * resolved nodes. @@ -157,7 +141,7 @@ public interface Node { * * @return a list of full nodes */ - @NonNull List resolveShorthand(); + @NonNull Collection resolveShorthand(); /** * Gets if this node is assigned temporarily. @@ -172,7 +156,7 @@ public interface Node { * @return the {@link Instant} when this node will expire, or null if it * doesn't have an expiry time */ - @Nullable Instant getExpiry() throws IllegalStateException; + @Nullable Instant getExpiry(); /** * Gets if the node has expired. diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java index 04f26a175..58a6b331e 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationBPermissions.java @@ -173,7 +173,7 @@ public class MigrationBPermissions extends SubCommand { migrateHolder(world, user, lpUser); plugin.getStorage().saveUser(lpUser); - plugin.getUserManager().cleanup(lpUser); + plugin.getUserManager().getHouseKeeper().cleanup(lpUser.getUniqueId()); log.logProgress("Migrated {} users so far.", userCount.incrementAndGet(), ProgressLogger.DEFAULT_NOTIFY_FREQUENCY); }); @@ -220,12 +220,12 @@ public class MigrationBPermissions extends SubCommand { } if (meta.getKey().equalsIgnoreCase("prefix")) { - holder.setNode(DataType.NORMAL, Prefix.builder(c.getPriority(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true); + holder.setNode(DataType.NORMAL, Prefix.builder(meta.getValue(), c.getPriority()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true); continue; } if (meta.getKey().equalsIgnoreCase("suffix")) { - holder.setNode(DataType.NORMAL, Suffix.builder(c.getPriority(), meta.getValue()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true); + holder.setNode(DataType.NORMAL, Suffix.builder(meta.getValue(), c.getPriority()).withContext(DefaultContextKeys.WORLD_KEY, world.getName()).build(), true); continue; } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java index fcaefdd92..d9dcbeab4 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationGroupManager.java @@ -156,9 +156,9 @@ public class MigrationGroupManager extends SubCommand { if (key.equals("build")) continue; if (key.equals("prefix")) { - groups.get(groupName).add(Prefix.builder(50, value).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); + groups.get(groupName).add(Prefix.builder(value, 50).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); } else if (key.equals("suffix")) { - groups.get(groupName).add(Suffix.builder(50, value).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); + groups.get(groupName).add(Suffix.builder(value, 50).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); } else { groups.get(groupName).add(Meta.builder(key, value).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); } @@ -209,9 +209,9 @@ public class MigrationGroupManager extends SubCommand { if (key.equals("build")) continue; if (key.equals("prefix")) { - users.get(id).add(Prefix.builder(100, value).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); + users.get(id).add(Prefix.builder(value, 100).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); } else if (key.equals("suffix")) { - users.get(id).add(Suffix.builder(100, value).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); + users.get(id).add(Suffix.builder(value, 100).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); } else { users.get(id).add(Meta.builder(key, value).withContext(DefaultContextKeys.WORLD_KEY, worldMappingFunc.apply(world)).build()); } @@ -256,7 +256,7 @@ public class MigrationGroupManager extends SubCommand { } plugin.getStorage().saveUser(user); - plugin.getUserManager().cleanup(user); + plugin.getUserManager().getHouseKeeper().cleanup(user.getUniqueId()); log.logProgress("Migrated {} users so far.", userCount.incrementAndGet(), ProgressLogger.DEFAULT_NOTIFY_FREQUENCY); }); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java index bee4f35bc..e001fd89c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsBukkit.java @@ -116,7 +116,7 @@ public class MigrationPermissionsBukkit extends SubCommand { migrate(lpUser, usersSection.getConfigurationSection(key)); } - plugin.getUserManager().cleanup(lpUser); + plugin.getUserManager().getHouseKeeper().cleanup(lpUser.getUniqueId()); plugin.getStorage().saveUser(lpUser); log.logProgress("Migrated {} users so far.", userCount.incrementAndGet(), ProgressLogger.DEFAULT_NOTIFY_FREQUENCY); }); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java index d3d3eaf98..df88d820e 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPermissionsEx.java @@ -180,7 +180,7 @@ public class MigrationPermissionsEx extends SubCommand { // migrate data migrateEntity(user, lpUser, userWeight); - plugin.getUserManager().cleanup(lpUser); + plugin.getUserManager().getHouseKeeper().cleanup(lpUser.getUniqueId()); plugin.getStorage().saveUser(lpUser); log.logProgress("Migrated {} users so far.", userCount.incrementAndGet(), ProgressLogger.DEFAULT_NOTIFY_FREQUENCY); }); @@ -278,11 +278,11 @@ public class MigrationPermissionsEx extends SubCommand { String suffix = entity.getOwnSuffix(); if (prefix != null && !prefix.isEmpty()) { - holder.setNode(DataType.NORMAL, Prefix.builder(weight, prefix).build(), true); + holder.setNode(DataType.NORMAL, Prefix.builder(prefix, weight).build(), true); } if (suffix != null && !suffix.isEmpty()) { - holder.setNode(DataType.NORMAL, Suffix.builder(weight, suffix).build(), true); + holder.setNode(DataType.NORMAL, Suffix.builder(suffix, weight).build(), true); } // migrate options diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java index d69b21eb1..f8b929576 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationPowerfulPerms.java @@ -190,9 +190,9 @@ public class MigrationPowerfulPerms extends SubCommand { } if (server != null) { - group.setNode(DataType.NORMAL, Prefix.builder(g.getRank(), prefix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true); + group.setNode(DataType.NORMAL, Prefix.builder(prefix.getValue(), g.getRank()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true); } else { - group.setNode(DataType.NORMAL, Prefix.builder(g.getRank(), prefix.getValue()).build(), true); + group.setNode(DataType.NORMAL, Prefix.builder(prefix.getValue(), g.getRank()).build(), true); } } @@ -205,9 +205,9 @@ public class MigrationPowerfulPerms extends SubCommand { } if (server != null) { - group.setNode(DataType.NORMAL, Suffix.builder(g.getRank(), suffix.getValue()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true); + group.setNode(DataType.NORMAL, Suffix.builder(suffix.getValue(), g.getRank()).withContext(DefaultContextKeys.SERVER_KEY, server).build(), true); } else { - group.setNode(DataType.NORMAL, Suffix.builder(g.getRank(), suffix.getValue()).build(), true); + group.setNode(DataType.NORMAL, Suffix.builder(suffix.getValue(), g.getRank()).build(), true); } } @@ -252,11 +252,11 @@ public class MigrationPowerfulPerms extends SubCommand { String suffix = joinFuture(pm.getPlayerOwnSuffix(uuid)); if (prefix != null && !prefix.isEmpty()) { - user.setNode(DataType.NORMAL, Prefix.builder(maxWeight.get(), prefix).build(), true); + user.setNode(DataType.NORMAL, Prefix.builder(prefix, maxWeight.get()).build(), true); } if (suffix != null && !suffix.isEmpty()) { - user.setNode(DataType.NORMAL, Suffix.builder(maxWeight.get(), suffix).build(), true); + user.setNode(DataType.NORMAL, Suffix.builder(suffix, maxWeight.get()).build(), true); } Group primaryGroup = joinFuture(pm.getPlayerPrimaryGroup(uuid)); @@ -268,7 +268,7 @@ public class MigrationPowerfulPerms extends SubCommand { } } - plugin.getUserManager().cleanup(user); + plugin.getUserManager().getHouseKeeper().cleanup(user.getUniqueId()); plugin.getStorage().saveUser(user); log.logProgress("Migrated {} users so far.", userCount.incrementAndGet(), ProgressLogger.DEFAULT_NOTIFY_FREQUENCY); }); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java index 88591f3ba..0f1c7baa6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/migration/MigrationZPermissions.java @@ -186,7 +186,7 @@ public class MigrationZPermissions extends SubCommand { user.getPrimaryGroup().setStoredValue(MigrationUtils.standardizeName(service.getPlayerPrimaryGroup(u))); - plugin.getUserManager().cleanup(user); + plugin.getUserManager().getHouseKeeper().cleanup(user.getUniqueId()); plugin.getStorage().saveUser(user); log.logProgress("Migrated {} users so far.", userCount.incrementAndGet(), ProgressLogger.DEFAULT_NOTIFY_FREQUENCY); }); @@ -226,9 +226,9 @@ public class MigrationZPermissions extends SubCommand { if (valueString.isEmpty()) continue; if (key.equals("prefix")) { - holder.setNode(DataType.NORMAL, Prefix.builder(weight, valueString).build(), true); + holder.setNode(DataType.NORMAL, Prefix.builder(valueString, weight).build(), true); } else if (key.equals("suffix")) { - holder.setNode(DataType.NORMAL, Suffix.builder(weight, valueString).build(), true); + holder.setNode(DataType.NORMAL, Suffix.builder(valueString, weight).build(), true); } else { holder.setNode(DataType.NORMAL, Meta.builder(key, valueString).build(), true); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java index bd24889ef..e900e62b0 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultChat.java @@ -278,7 +278,7 @@ public class LuckPermsVaultChat extends AbstractVaultChat { metaAccumulator.complete(); int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0) + 10; - NodeBuilder chatMetaNode = type == ChatMetaType.PREFIX ? Prefix.builder(priority, value) : Suffix.builder(priority, value); + NodeBuilder chatMetaNode = type == ChatMetaType.PREFIX ? Prefix.builder(value, priority) : Suffix.builder(value, priority); chatMetaNode.withContext(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer()); chatMetaNode.withContext(DefaultContextKeys.WORLD_KEY, world); @@ -301,9 +301,9 @@ public class LuckPermsVaultChat extends AbstractVaultChat { NodeBuilder metaNode; if (key.equalsIgnoreCase("prefix")) { - metaNode = Prefix.builder(100, value.toString()); + metaNode = Prefix.builder(value.toString(), 100); } else if (key.equalsIgnoreCase("suffix")) { - metaNode = Suffix.builder(100, value.toString()); + metaNode = Suffix.builder(value.toString(), 100); } else { metaNode = Meta.builder(key, value.toString()); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java index 850e972ae..0968483f5 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/LuckPermsVaultPermission.java @@ -264,7 +264,7 @@ public class LuckPermsVaultPermission extends AbstractVaultPermission { ContextSet contexts = getQueryOptions(uuid, world).context(); String[] ret = user.normalData().immutableInheritance().values().stream() - .filter(n -> n.shouldApplyWithContext(contexts)) + .filter(n -> n.getContexts().isSatisfiedBy(contexts)) .map(n -> { Group group = this.plugin.getGroupManager().getIfLoaded(n.getGroupName()); if (group != null) { diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java index adde1ed8a..316d99ef3 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/migration/MigrationBungeePerms.java @@ -121,7 +121,7 @@ public class MigrationBungeePerms extends SubCommand { migrateHolder(u, u.getGroupsString(), userWeight, user); plugin.getStorage().saveUser(user); - plugin.getUserManager().cleanup(user); + plugin.getUserManager().getHouseKeeper().cleanup(user.getUniqueId()); log.logProgress("Migrated {} users so far.", userCount.incrementAndGet(), ProgressLogger.DEFAULT_NOTIFY_FREQUENCY); }); @@ -165,10 +165,10 @@ public class MigrationBungeePerms extends SubCommand { String suffix = entity.getSuffix(); if (prefix != null && !prefix.isEmpty()) { - holder.setNode(DataType.NORMAL, Prefix.builder(weight, prefix).build(), true); + holder.setNode(DataType.NORMAL, Prefix.builder(prefix, weight).build(), true); } if (suffix != null && !suffix.isEmpty()) { - holder.setNode(DataType.NORMAL, Suffix.builder(weight, suffix).build(), true); + holder.setNode(DataType.NORMAL, Suffix.builder(suffix, weight).build(), true); } } } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java index 70524cda0..11783f205 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPermissionHolder.java @@ -93,12 +93,12 @@ public class ApiPermissionHolder implements net.luckperms.api.model.PermissionHo } @Override - public @NonNull net.luckperms.api.model.PermissionHolder.NodeMap data() { + public @NonNull NodeMap data() { return this.normalData; } @Override - public @NonNull net.luckperms.api.model.PermissionHolder.NodeMap transientData() { + public @NonNull NodeMap transientData() { return this.transientData; } diff --git a/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java b/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java index c95776d4c..6e8d2c24d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java +++ b/common/src/main/java/me/lucko/luckperms/common/backup/Exporter.java @@ -183,7 +183,7 @@ public class Exporter implements Runnable { }) .add("nodes", NodeJsonSerializer.serializeNodes(user.normalData().asSet())) .toJson()); - this.plugin.getUserManager().cleanup(user); + this.plugin.getUserManager().getHouseKeeper().cleanup(user.getUniqueId()); userCount.incrementAndGet(); }, executor)); } diff --git a/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java b/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java index 21e0fb0b2..6973091aa 100644 --- a/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java +++ b/common/src/main/java/me/lucko/luckperms/common/backup/Importer.java @@ -109,7 +109,7 @@ public class Importer implements Runnable { } user.setNodes(DataType.NORMAL, userData.nodes); this.plugin.getStorage().saveUser(user).join(); - this.plugin.getUserManager().cleanup(user); + this.plugin.getUserManager().getHouseKeeper().cleanup(user.getUniqueId()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/calculator/processor/RegexProcessor.java b/common/src/main/java/me/lucko/luckperms/common/calculator/processor/RegexProcessor.java index e01d2fcd6..dda7cd8ed 100644 --- a/common/src/main/java/me/lucko/luckperms/common/calculator/processor/RegexProcessor.java +++ b/common/src/main/java/me/lucko/luckperms/common/calculator/processor/RegexProcessor.java @@ -29,11 +29,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import me.lucko.luckperms.common.calculator.result.TristateResult; -import me.lucko.luckperms.common.node.factory.NodeBuilders; +import me.lucko.luckperms.common.node.types.RegexPermission; -import net.luckperms.api.node.Node; import net.luckperms.api.node.Tristate; -import net.luckperms.api.node.types.RegexPermissionNode; import java.util.Collections; import java.util.List; @@ -59,12 +57,12 @@ public class RegexProcessor extends AbstractPermissionProcessor implements Permi public void refresh() { ImmutableList.Builder> builder = ImmutableList.builder(); for (Map.Entry e : this.sourceMap.entrySet()) { - Node builtNode = NodeBuilders.determineMostApplicable(e.getKey()).build(); - if (!(builtNode instanceof RegexPermissionNode)) { + RegexPermission.Builder regexPerm = RegexPermission.parse(e.getKey()); + if (regexPerm == null) { continue; } - Pattern pattern = ((RegexPermissionNode) builtNode).getPattern().orElse(null); + Pattern pattern = regexPerm.build().getPattern().orElse(null); if (pattern == null) { continue; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java index a004b73b2..aebf101eb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddChatMeta.java @@ -40,8 +40,6 @@ 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.types.Prefix; -import me.lucko.luckperms.common.node.types.Suffix; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.util.Predicates; @@ -87,7 +85,7 @@ public class MetaAddChatMeta extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - DataMutateResult result = holder.setNode(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.builder(meta, priority).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( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java index 8a9a6c901..8176cf527 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaAddTempChatMeta.java @@ -41,8 +41,6 @@ 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.types.Prefix; -import me.lucko.luckperms.common.node.types.Suffix; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.util.DurationFormatter; @@ -56,7 +54,6 @@ import net.luckperms.api.model.DataType; import net.luckperms.api.model.TemporaryDataMutateResult; import net.luckperms.api.model.TemporaryMergeBehaviour; import net.luckperms.api.node.ChatMetaType; -import net.luckperms.api.util.Result; import java.util.List; @@ -93,9 +90,9 @@ public class MetaAddTempChatMeta extends SharedSubCommand { return CommandResult.NO_PERMISSION; } - TemporaryDataMutateResult ret = holder.setNode(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.builder(meta, priority).expiry(duration).withContext(context).build(), modifier); - if (((Result) ret.getResult()).wasSuccessful()) { + if (ret.getResult().wasSuccessful()) { duration = ret.getMergedNode().getExpiry().getEpochSecond(); TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java index 0bb3e53c5..7ff38a1d2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveChatMeta.java @@ -40,8 +40,6 @@ 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.types.Prefix; -import me.lucko.luckperms.common.node.types.Suffix; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.util.Predicates; @@ -100,7 +98,7 @@ public class MetaRemoveChatMeta extends SharedSubCommand { return CommandResult.SUCCESS; } - DataMutateResult result = holder.unsetNode(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.builder(meta, priority).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(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java index 1ca633f8d..c9808aec4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaRemoveTempChatMeta.java @@ -40,8 +40,6 @@ 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.types.Prefix; -import me.lucko.luckperms.common.node.types.Suffix; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.util.Predicates; @@ -100,7 +98,7 @@ public class MetaRemoveTempChatMeta extends SharedSubCommand { return CommandResult.SUCCESS; } - DataMutateResult result = holder.unsetNode(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.builder(meta, priority).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(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java index 2e9cc4552..824dbcf3f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetChatMeta.java @@ -42,8 +42,6 @@ import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.PermissionHolder; -import me.lucko.luckperms.common.node.types.Prefix; -import me.lucko.luckperms.common.node.types.Suffix; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.util.Predicates; @@ -123,7 +121,7 @@ public class MetaSetChatMeta extends SharedSubCommand { } } - DataMutateResult result = holder.setNode(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.builder(meta, priority).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( diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java index 1f5872e60..613bf5ac4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/meta/MetaSetTempChatMeta.java @@ -43,8 +43,6 @@ import me.lucko.luckperms.common.locale.command.CommandSpec; import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.Group; import me.lucko.luckperms.common.model.PermissionHolder; -import me.lucko.luckperms.common.node.types.Prefix; -import me.lucko.luckperms.common.node.types.Suffix; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.util.DurationFormatter; @@ -59,7 +57,6 @@ import net.luckperms.api.model.TemporaryDataMutateResult; import net.luckperms.api.model.TemporaryMergeBehaviour; import net.luckperms.api.node.ChatMetaType; import net.luckperms.api.query.QueryOptions; -import net.luckperms.api.util.Result; import java.util.List; import java.util.OptionalInt; @@ -133,9 +130,9 @@ public class MetaSetTempChatMeta extends SharedSubCommand { } } - TemporaryDataMutateResult ret = holder.setNode(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.builder(meta, priority).expiry(duration).withContext(context).build(), modifier); - if (((Result) ret.getResult()).wasSuccessful()) { + if (ret.getResult().wasSuccessful()) { duration = ret.getMergedNode().getExpiry().getEpochSecond(); TextComponent.Builder builder = Message.ADD_TEMP_CHATMETA_SUCCESS.asComponent(plugin.getLocaleManager(), holder.getFormattedDisplayName(), this.type.name().toLowerCase(), meta, priority, DurationFormatter.LONG.formatDateDiff(duration), MessageUtils.contextSetToString(plugin.getLocaleManager(), context)).toBuilder(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderEditor.java b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderEditor.java index e06ebb747..9db6e57c5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderEditor.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/generic/other/HolderEditor.java @@ -31,7 +31,6 @@ import me.lucko.luckperms.common.command.CommandResult; import me.lucko.luckperms.common.command.abstraction.SubCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; -import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.context.contextset.ImmutableContextSetImpl; import me.lucko.luckperms.common.locale.LocaleManager; import me.lucko.luckperms.common.locale.command.CommandSpec; @@ -40,24 +39,10 @@ import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.util.Predicates; -import me.lucko.luckperms.common.util.gson.GsonProvider; -import me.lucko.luckperms.common.web.AbstractHttpClient; import me.lucko.luckperms.common.web.WebEditor; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.event.ClickEvent; -import net.kyori.text.event.HoverEvent; -import net.kyori.text.format.TextColor; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; -import java.util.zip.GZIPOutputStream; public class HolderEditor extends SubCommand { public HolderEditor(LocaleManager locale, boolean user) { @@ -73,37 +58,8 @@ public class HolderEditor extends SubCommand { Message.EDITOR_START.send(sender); - // form the payload data JsonObject payload = WebEditor.formPayload(Collections.singletonList(holder), Collections.emptyList(), sender, label, plugin); - - // upload the payload data to gist - ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); - try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(bytesOut), StandardCharsets.UTF_8)) { - GsonProvider.prettyPrinting().toJson(payload, writer); - } catch (IOException e) { - e.printStackTrace(); - } - - String pasteId; - try { - pasteId = plugin.getBytebin().postContent(bytesOut.toByteArray(), AbstractHttpClient.JSON_TYPE, false).key(); - } catch (IOException e) { - Message.EDITOR_UPLOAD_FAILURE.send(sender); - return CommandResult.STATE_ERROR; - } - - // form a url for the editor - String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + "#" + pasteId; - - Message.EDITOR_URL.send(sender); - - Component message = TextComponent.builder(url).color(TextColor.AQUA) - .clickEvent(ClickEvent.openUrl(url)) - .hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the editor.").color(TextColor.GRAY))) - .build(); - - sender.sendMessage(message); - return CommandResult.SUCCESS; + return WebEditor.post(payload, sender, plugin); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/EditorCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/EditorCommand.java index 23c9611e0..66fef3307 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/EditorCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/EditorCommand.java @@ -32,35 +32,26 @@ import me.lucko.luckperms.common.command.abstraction.SingleCommand; import me.lucko.luckperms.common.command.access.ArgumentPermissions; import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.command.utils.ArgumentParser; -import me.lucko.luckperms.common.config.ConfigKeys; 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.model.Track; +import me.lucko.luckperms.common.model.User; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.sender.Sender; import me.lucko.luckperms.common.util.Predicates; -import me.lucko.luckperms.common.util.gson.GsonProvider; -import me.lucko.luckperms.common.web.AbstractHttpClient; import me.lucko.luckperms.common.web.WebEditor; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.event.ClickEvent; -import net.kyori.text.event.HoverEvent; -import net.kyori.text.format.TextColor; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; -import java.util.zip.GZIPOutputStream; +import java.util.Set; +import java.util.UUID; public class EditorCommand extends SingleCommand { + private static final int MAX_USERS = 500; + public EditorCommand(LocaleManager locale) { super(CommandSpec.EDITOR.localize(locale), "Editor", CommandPermission.EDITOR, Predicates.notInRange(0, 1)); } @@ -83,6 +74,9 @@ public class EditorCommand extends SingleCommand { List holders = new ArrayList<>(); List tracks = new ArrayList<>(); if (type.includingGroups) { + // run a sync task + plugin.getSyncTaskBuffer().requestDirectly(); + plugin.getGroupManager().getAll().values().stream() .sorted((o1, o2) -> { int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0)); @@ -92,9 +86,29 @@ public class EditorCommand extends SingleCommand { tracks = new ArrayList<>(plugin.getTrackManager().getAll().values()); } if (type.includingUsers) { + Set users = new LinkedHashSet<>(); + + // online players first plugin.getUserManager().getAll().values().stream() .sorted((o1, o2) -> o1.getFormattedDisplayName().compareToIgnoreCase(o2.getFormattedDisplayName())) - .forEach(holders::add); + .map(User::getUniqueId) + .forEach(users::add); + + // then fill up with other users + users.addAll(plugin.getStorage().getUniqueUsers().join()); + + users.stream().limit(MAX_USERS).forEach(uuid -> { + User user = plugin.getUserManager().getIfLoaded(uuid); + if (user != null) { + holders.add(user); + } else { + user = plugin.getStorage().loadUser(uuid, null).join(); + if (user != null) { + holders.add(user); + } + plugin.getUserManager().getHouseKeeper().cleanup(uuid); + } + }); } if (holders.isEmpty()) { @@ -114,37 +128,8 @@ public class EditorCommand extends SingleCommand { Message.EDITOR_START.send(sender); - // form the payload data JsonObject payload = WebEditor.formPayload(holders, tracks, sender, label, plugin); - - // upload the payload data to gist - ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); - try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(bytesOut), StandardCharsets.UTF_8)) { - GsonProvider.prettyPrinting().toJson(payload, writer); - } catch (IOException e) { - e.printStackTrace(); - } - - String pasteId; - try { - pasteId = plugin.getBytebin().postContent(bytesOut.toByteArray(), AbstractHttpClient.JSON_TYPE, false).key(); - } catch (IOException e) { - Message.EDITOR_UPLOAD_FAILURE.send(sender); - return CommandResult.STATE_ERROR; - } - - // form a url for the editor - String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + "#" + pasteId; - - Message.EDITOR_URL.send(sender); - - Component message = TextComponent.builder(url).color(TextColor.AQUA) - .clickEvent(ClickEvent.openUrl(url)) - .hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the editor.").color(TextColor.GRAY))) - .build(); - - sender.sendMessage(message); - return CommandResult.SUCCESS; + return WebEditor.post(payload, sender, plugin); } private enum Type { diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/TreeCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/TreeCommand.java index 57f432f20..272316e6f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/TreeCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/TreeCommand.java @@ -92,7 +92,7 @@ public class TreeCommand extends SingleCommand { Message.TREE_UPLOAD_START.send(sender); PermissionCache permissionData = user == null ? null : user.getCachedData().getPermissionData(plugin.getQueryOptionsForUser(user).orElse(plugin.getContextManager().getStaticQueryOptions())); String id = view.uploadPasteData(plugin.getBytebin(), sender, user, permissionData); - String url = plugin.getConfiguration().get(ConfigKeys.TREE_VIEWER_URL_PATTERN) + "#" + id; + String url = plugin.getConfiguration().get(ConfigKeys.TREE_VIEWER_URL_PATTERN) + id; Message.TREE_URL.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java index f55d80421..928e28b23 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/VerboseCommand.java @@ -113,7 +113,7 @@ public class VerboseCommand extends SingleCommand { } else { Message.VERBOSE_UPLOAD_START.send(sender); String id = listener.uploadPasteData(plugin.getBytebin()); - String url = plugin.getConfiguration().get(ConfigKeys.VERBOSE_VIEWER_URL_PATTERN) + "#" + id; + String url = plugin.getConfiguration().get(ConfigKeys.VERBOSE_VIEWER_URL_PATTERN) + id; Message.VERBOSE_RESULTS_URL.send(sender); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java index 126a22e5b..e5ad76cac 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserClone.java @@ -82,7 +82,7 @@ public class UserClone extends SubCommand { .build().submit(plugin, sender); StorageAssistant.save(otherUser, sender, plugin); - plugin.getUserManager().cleanup(otherUser); + plugin.getUserManager().getHouseKeeper().cleanup(otherUser.getUniqueId()); return CommandResult.SUCCESS; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java index c7f1b698d..f3e985812 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/user/UserMainCommand.java @@ -138,7 +138,7 @@ public class UserMainCommand extends MainCommand { @Override protected void cleanup(User user, LuckPermsPlugin plugin) { - plugin.getUserManager().cleanup(user); + plugin.getUserManager().getHouseKeeper().cleanup(user.getUniqueId()); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java index 54d8a1774..d75269230 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -528,17 +528,17 @@ public final class ConfigKeys { /** * The URL of the web editor */ - public static final ConfigKey WEB_EDITOR_URL_PATTERN = stringKey("web-editor-url", "https://luckperms.github.io/editor/"); + public static final ConfigKey WEB_EDITOR_URL_PATTERN = stringKey("web-editor-url", "https://editor.luckperms.net/"); /** * The URL of the verbose viewer */ - public static final ConfigKey VERBOSE_VIEWER_URL_PATTERN = stringKey("verbose-viewer-url", "https://luckperms.github.io/verbose/"); + public static final ConfigKey VERBOSE_VIEWER_URL_PATTERN = stringKey("verbose-viewer-url", "https://luckperms.net/verbose/#"); /** * The URL of the tree viewer */ - public static final ConfigKey TREE_VIEWER_URL_PATTERN = stringKey("tree-viewer-url", "https://luckperms.github.io/treeview/"); + public static final ConfigKey TREE_VIEWER_URL_PATTERN = stringKey("tree-viewer-url", "https://luckperms.net/treeview/#"); private static final Map> KEYS; private static final int SIZE; diff --git a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java index bf03a2330..a7e717386 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/PermissionHolder.java @@ -319,7 +319,7 @@ public abstract class PermissionHolder { if (resolveShorthand) { for (Node node : entries) { - List shorthand = node.resolveShorthand(); + Collection shorthand = node.resolveShorthand(); for (String s : shorthand) { if (convertToLowercase) { perms.putIfAbsent(s.toLowerCase(), node.getValue()); diff --git a/common/src/main/java/me/lucko/luckperms/common/model/manager/user/AbstractUserManager.java b/common/src/main/java/me/lucko/luckperms/common/model/manager/user/AbstractUserManager.java index 3636119cf..a824c15b7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/manager/user/AbstractUserManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/manager/user/AbstractUserManager.java @@ -129,11 +129,6 @@ public abstract class AbstractUserManager extends AbstractManage return this.housekeeper; } - @Override - public void cleanup(User user) { - this.housekeeper.cleanup(user.getUniqueId()); - } - @Override public CompletableFuture updateAllUsers() { return CompletableFuture.runAsync( diff --git a/common/src/main/java/me/lucko/luckperms/common/model/manager/user/UserManager.java b/common/src/main/java/me/lucko/luckperms/common/model/manager/user/UserManager.java index bda7e1f50..73b62f429 100644 --- a/common/src/main/java/me/lucko/luckperms/common/model/manager/user/UserManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/model/manager/user/UserManager.java @@ -74,13 +74,6 @@ public interface UserManager extends Manager { */ UserHousekeeper getHouseKeeper(); - /** - * Unloads the user if a corresponding player is not online - * - * @param user the user - */ - void cleanup(User user); - /** * Reloads the data of all *online* users */ diff --git a/common/src/main/java/me/lucko/luckperms/common/node/AbstractNode.java b/common/src/main/java/me/lucko/luckperms/common/node/AbstractNode.java index aa57ca0dd..c2e376fdb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/AbstractNode.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/AbstractNode.java @@ -29,19 +29,19 @@ import com.google.common.collect.ImmutableList; import me.lucko.luckperms.common.node.utils.ShorthandParser; -import net.luckperms.api.context.ContextSet; import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.node.Node; import net.luckperms.api.node.NodeBuilder; import net.luckperms.api.node.NodeEqualityPredicate; import net.luckperms.api.node.ScopedNode; import net.luckperms.api.node.metadata.NodeMetadataKey; -import net.luckperms.api.node.types.RegexPermissionNode; +import net.luckperms.api.node.types.PermissionNode; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import java.time.Instant; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; @@ -74,7 +74,7 @@ public abstract class AbstractNode, B extends NodeBui this.contexts = contexts; this.metadata = metadata; - this.resolvedShorthand = this instanceof RegexPermissionNode ? ImmutableList.of() : ImmutableList.copyOf(ShorthandParser.parseShorthand(this.key)); + this.resolvedShorthand = this instanceof PermissionNode ? ImmutableList.copyOf(ShorthandParser.parseShorthand(this.key)) : ImmutableList.of(); this.hashCode = calculateHashCode(); } @@ -101,16 +101,6 @@ public abstract class AbstractNode, B extends NodeBui return Optional.ofNullable(value); } - @Override - public boolean appliesGlobally() { - return this.contexts.isEmpty(); - } - - @Override - public boolean shouldApplyWithContext(@NonNull ContextSet contextSet) { - return this.contexts.isSatisfiedBy(contextSet); - } - @Override public boolean hasExpiry() { return this.expireAt != 0L; @@ -127,7 +117,7 @@ public abstract class AbstractNode, B extends NodeBui } @Override - public @NonNull List resolveShorthand() { + public @NonNull Collection resolveShorthand() { return this.resolvedShorthand; } diff --git a/common/src/main/java/me/lucko/luckperms/common/node/types/Prefix.java b/common/src/main/java/me/lucko/luckperms/common/node/types/Prefix.java index a69fe4752..11c07eca1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/types/Prefix.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/types/Prefix.java @@ -53,7 +53,7 @@ public class Prefix extends AbstractNode impleme return new Builder(); } - public static Builder builder(int priority, String prefix) { + public static Builder builder(String prefix, int priority) { return builder().prefix(prefix).priority(priority); } diff --git a/common/src/main/java/me/lucko/luckperms/common/node/types/Suffix.java b/common/src/main/java/me/lucko/luckperms/common/node/types/Suffix.java index 2729ac93d..c093d59e6 100644 --- a/common/src/main/java/me/lucko/luckperms/common/node/types/Suffix.java +++ b/common/src/main/java/me/lucko/luckperms/common/node/types/Suffix.java @@ -53,7 +53,7 @@ public class Suffix extends AbstractNode impleme return new Builder(); } - public static Builder builder(int priority, String suffix) { + public static Builder builder(String suffix, int priority) { return builder().suffix(suffix).priority(priority); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java index be2154059..f7f1c731e 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/implementation/file/AbstractConfigurateStorage.java @@ -590,7 +590,7 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio if (entry == null) { continue; } - nodes.add(readMetaAttributes(entry.getValue(), c -> Prefix.builder(c.getNode("priority").getInt(0), entry.getKey()))); + nodes.add(readMetaAttributes(entry.getValue(), c -> Prefix.builder(entry.getKey(), c.getNode("priority").getInt(0)))); } } @@ -601,7 +601,7 @@ public abstract class AbstractConfigurateStorage implements StorageImplementatio if (entry == null) { continue; } - nodes.add(readMetaAttributes(entry.getValue(), c -> Suffix.builder(c.getNode("priority").getInt(0), entry.getKey()))); + nodes.add(readMetaAttributes(entry.getValue(), c -> Suffix.builder(entry.getKey(), c.getNode("priority").getInt(0)))); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/misc/PlayerSaveResultImpl.java b/common/src/main/java/me/lucko/luckperms/common/storage/misc/PlayerSaveResultImpl.java index 14afd95a4..e8c899d73 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/misc/PlayerSaveResultImpl.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/misc/PlayerSaveResultImpl.java @@ -69,12 +69,12 @@ public final class PlayerSaveResultImpl implements PlayerSaveResult { } private final Set outcomes; - private final @Nullable String oldUsername; + private final @Nullable String previousUsername; private final @Nullable Set otherUuids; - private PlayerSaveResultImpl(EnumSet outcomes, @Nullable String oldUsername, @Nullable Set otherUuids) { + private PlayerSaveResultImpl(EnumSet outcomes, @Nullable String previousUsername, @Nullable Set otherUuids) { this.outcomes = ImmutableSet.copyOf(outcomes); - this.oldUsername = oldUsername; + this.previousUsername = previousUsername; this.otherUuids = otherUuids; } @@ -92,7 +92,7 @@ public final class PlayerSaveResultImpl implements PlayerSaveResult { public PlayerSaveResultImpl withOtherUuidsPresent(@NonNull Set otherUuids) { EnumSet outcomes = EnumSet.copyOf(this.outcomes); outcomes.add(Outcome.OTHER_UNIQUE_IDS_PRESENT_FOR_USERNAME); - return new PlayerSaveResultImpl(outcomes, this.oldUsername, ImmutableSet.copyOf(otherUuids)); + return new PlayerSaveResultImpl(outcomes, this.previousUsername, ImmutableSet.copyOf(otherUuids)); } @Override @@ -101,8 +101,8 @@ public final class PlayerSaveResultImpl implements PlayerSaveResult { } @Override - public @Nullable String getOldUsername() { - return this.oldUsername; + public @Nullable String getPreviousUsername() { + return this.previousUsername; } @Override @@ -116,17 +116,17 @@ public final class PlayerSaveResultImpl implements PlayerSaveResult { if (that == null || getClass() != that.getClass()) return false; PlayerSaveResultImpl result = (PlayerSaveResultImpl) that; return Objects.equals(this.outcomes, result.outcomes) && - Objects.equals(this.oldUsername, result.oldUsername) && + Objects.equals(this.previousUsername, result.previousUsername) && Objects.equals(this.otherUuids, result.otherUuids); } @Override public int hashCode() { - return Objects.hash(this.outcomes, this.oldUsername, this.otherUuids); + return Objects.hash(this.outcomes, this.previousUsername, this.otherUuids); } @Override public String toString() { - return "PlayerSaveResult(outcomes=" + this.outcomes + ", oldUsername=" + this.oldUsername + ", otherUuids=" + this.otherUuids + ")"; + return "PlayerSaveResult(outcomes=" + this.outcomes + ", previousUsername=" + this.previousUsername + ", otherUuids=" + this.otherUuids + ")"; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/web/WebEditor.java b/common/src/main/java/me/lucko/luckperms/common/web/WebEditor.java index 3f454d08e..d9c6fdab9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/web/WebEditor.java +++ b/common/src/main/java/me/lucko/luckperms/common/web/WebEditor.java @@ -28,7 +28,10 @@ package me.lucko.luckperms.common.web; import com.google.common.base.Preconditions; import com.google.gson.JsonObject; +import me.lucko.luckperms.common.command.CommandResult; +import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.context.ContextSetJsonSerializer; +import me.lucko.luckperms.common.locale.message.Message; import me.lucko.luckperms.common.model.PermissionHolder; import me.lucko.luckperms.common.model.Track; import me.lucko.luckperms.common.node.utils.NodeJsonSerializer; @@ -38,16 +41,26 @@ import me.lucko.luckperms.common.util.gson.GsonProvider; import me.lucko.luckperms.common.util.gson.JArray; import me.lucko.luckperms.common.util.gson.JObject; +import net.kyori.text.Component; +import net.kyori.text.TextComponent; +import net.kyori.text.event.ClickEvent; +import net.kyori.text.event.HoverEvent; +import net.kyori.text.format.TextColor; + import okhttp3.Request; import okhttp3.Response; import okhttp3.ResponseBody; import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.nio.charset.StandardCharsets; import java.util.List; +import java.util.zip.GZIPOutputStream; /** * Utility methods for interacting with the LuckPerms web permission editor. @@ -111,6 +124,37 @@ public final class WebEditor { .toJson(); } + public static CommandResult post(JsonObject payload, Sender sender, LuckPermsPlugin plugin) { + // upload the payload data to gist + ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); + try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(bytesOut), StandardCharsets.UTF_8)) { + GsonProvider.prettyPrinting().toJson(payload, writer); + } catch (IOException e) { + e.printStackTrace(); + } + + String pasteId; + try { + pasteId = plugin.getBytebin().postContent(bytesOut.toByteArray(), AbstractHttpClient.JSON_TYPE, false).key(); + } catch (IOException e) { + Message.EDITOR_UPLOAD_FAILURE.send(sender); + return CommandResult.STATE_ERROR; + } + + // form a url for the editor + String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + pasteId; + + Message.EDITOR_URL.send(sender); + + Component message = TextComponent.builder(url).color(TextColor.AQUA) + .clickEvent(ClickEvent.openUrl(url)) + .hoverEvent(HoverEvent.showText(TextComponent.of("Click to open the editor.").color(TextColor.GRAY))) + .build(); + + sender.sendMessage(message); + return CommandResult.SUCCESS; + } + public static JsonObject readDataFromBytebin(BytebinClient bytebin, String id) { Request request = new Request.Builder() .header("User-Agent", bytebin.getUserAgent()) diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubjectData.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubjectData.java index ac0c9ef95..73b7662ef 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubjectData.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubjectData.java @@ -50,7 +50,6 @@ import net.luckperms.api.node.ChatMetaType; import net.luckperms.api.node.Node; import net.luckperms.api.node.NodeType; import net.luckperms.api.node.Tristate; -import net.luckperms.api.node.types.ChatMetaNode; import net.luckperms.api.node.types.InheritanceNode; import net.luckperms.api.node.types.MetaNode; import net.luckperms.api.node.types.PrefixNode; @@ -313,8 +312,7 @@ public class PermissionHolderSubjectData implements LPSubjectData { int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0); priority += 10; - ChatMetaNode.Builder builder = type == ChatMetaType.PREFIX ? Prefix.builder(priority, value) : Suffix.builder(priority, value); - node = builder.withContext(contexts).build(); + node = type.builder(value, priority).withContext(contexts).build(); } else { // standard remove this.holder.removeIf(this.type, contexts, NodeType.META.predicate(n -> n.getMetaKey().equals(key)), false);