diff --git a/api/src/main/java/net/luckperms/api/LuckPerms.java b/api/src/main/java/net/luckperms/api/LuckPerms.java index a230e3d55..eb34dfa00 100644 --- a/api/src/main/java/net/luckperms/api/LuckPerms.java +++ b/api/src/main/java/net/luckperms/api/LuckPerms.java @@ -42,6 +42,7 @@ import net.luckperms.api.node.NodeBuilderRegistry; import net.luckperms.api.node.matcher.NodeMatcherFactory; import net.luckperms.api.platform.Platform; import net.luckperms.api.platform.PluginMetadata; +import net.luckperms.api.player.PlayerAdapter; import net.luckperms.api.query.QueryOptionsRegistry; import net.luckperms.api.track.Track; import net.luckperms.api.track.TrackManager; @@ -116,6 +117,32 @@ public interface LuckPerms { */ @NonNull TrackManager getTrackManager(); + /** + * Gets the {@link PlayerAdapter} instance, a utility class for adapting platform Player + * instances to {@link User}s. + * + *

The {@code playerClass} parameter must be equal to the class or interface used by the + * server platform to represent players.

+ * + *

Specifically:

+ * + *

+ * + * + * @param playerClass the class used by the platform to represent players + * @param the player class type + * @return the player adapter + * @throws IllegalArgumentException if the player class is not correct + * @since 5.1 + */ + @NonNull PlayerAdapter getPlayerAdapter(Class playerClass); + /** * Gets the {@link Platform}, which represents the server platform the * plugin is running on. diff --git a/api/src/main/java/net/luckperms/api/cacheddata/CachedDataManager.java b/api/src/main/java/net/luckperms/api/cacheddata/CachedDataManager.java index 7c5cd4bd3..8c735dc5b 100644 --- a/api/src/main/java/net/luckperms/api/cacheddata/CachedDataManager.java +++ b/api/src/main/java/net/luckperms/api/cacheddata/CachedDataManager.java @@ -25,7 +25,10 @@ package net.luckperms.api.cacheddata; +import net.luckperms.api.context.ContextManager; import net.luckperms.api.model.PermissionHolder; +import net.luckperms.api.model.group.Group; +import net.luckperms.api.model.user.User; import net.luckperms.api.query.QueryOptions; import org.checkerframework.checker.nullness.qual.NonNull; @@ -56,23 +59,57 @@ public interface CachedDataManager { @NonNull Container metaData(); /** - * Gets PermissionData from the cache, given a specified context. + * Gets PermissionData from the cache, using the given query options. * * @param queryOptions the query options * @return a permission data instance - * @throws NullPointerException if contexts is null */ @NonNull CachedPermissionData getPermissionData(@NonNull QueryOptions queryOptions); /** - * Gets MetaData from the cache, given a specified context. + * Gets MetaData from the cache, using the given query options. * * @param queryOptions the query options * @return a meta data instance - * @throws NullPointerException if contexts is null */ @NonNull CachedMetaData getMetaData(@NonNull QueryOptions queryOptions); + /** + * Gets PermissionData from the cache, using the most appropriate query options + * available at the time. + * + *

For {@link User}s, the most appropriate query options will be their + * {@link ContextManager#getQueryOptions(User) current active query options} if the + * corresponding player is online, and otherwise, will fallback to + * {@link ContextManager#getStaticQueryOptions() the current static query options} + * if they are offline.

+ * + *

For {@link Group}s, the most appropriate query options will always be + * {@link ContextManager#getStaticQueryOptions()} the current static query options.

+ * + * @return a permission data instance + * @since 5.1 + */ + @NonNull CachedPermissionData getPermissionData(); + + /** + * Gets MetaData from the cache, using the most appropriate query options + * available at the time. + * + *

For {@link User}s, the most appropriate query options will be their + * {@link ContextManager#getQueryOptions(User) current active query options} if the + * corresponding player is online, and otherwise, will fallback to + * {@link ContextManager#getStaticQueryOptions() the current static query options} + * if they are offline.

+ * + *

For {@link Group}s, the most appropriate query options will always be + * {@link ContextManager#getStaticQueryOptions()} the current static query options.

+ * + * @return a meta data instance + * @since 5.1 + */ + @NonNull CachedMetaData getMetaData(); + /** * Invalidates all cached {@link CachedPermissionData} and {@link CachedMetaData} * instances. diff --git a/api/src/main/java/net/luckperms/api/context/ContextManager.java b/api/src/main/java/net/luckperms/api/context/ContextManager.java index d97618e5f..5ce4935af 100644 --- a/api/src/main/java/net/luckperms/api/context/ContextManager.java +++ b/api/src/main/java/net/luckperms/api/context/ContextManager.java @@ -37,11 +37,11 @@ import java.util.Optional; * Manages {@link ContextCalculator}s, and calculates applicable contexts for a * given type. * - * This interface accepts {@link Object} types as a parameter to avoid having to depend + *

This interface accepts {@link Object} types as a parameter to avoid having to depend * on specific server implementations. In all cases, the "player" or "subject" type for - * the platform must be used. + * the platform must be used.

* - * Specifically: + *

Specifically:

* *

*
    diff --git a/api/src/main/java/net/luckperms/api/player/PlayerAdapter.java b/api/src/main/java/net/luckperms/api/player/PlayerAdapter.java new file mode 100644 index 000000000..7fda69d1a --- /dev/null +++ b/api/src/main/java/net/luckperms/api/player/PlayerAdapter.java @@ -0,0 +1,115 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package net.luckperms.api.player; + +import net.luckperms.api.cacheddata.CachedDataManager; +import net.luckperms.api.cacheddata.CachedMetaData; +import net.luckperms.api.cacheddata.CachedPermissionData; +import net.luckperms.api.context.ContextManager; +import net.luckperms.api.context.ImmutableContextSet; +import net.luckperms.api.model.user.User; +import net.luckperms.api.model.user.UserManager; +import net.luckperms.api.query.QueryOptions; + +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.UUID; + +/** + * A utility class for adapting platform Player instances to LuckPerms {@link User}s. + * + *

    Note: this class will only work for online players.

    + * + *

    The "player type" parameter must be equal to the class or interface used by the + * server platform to represent players.

    + * + *

    Specifically:

    + * + *

    + *
      + *
    • {@code org.bukkit.entity.Player}
    • + *
    • {@code net.md_5.bungee.api.connection.ProxiedPlayer}
    • + *
    • {@code org.spongepowered.api/entity.living.player.Player}
    • + *
    • {@code cn.nukkit.Player}
    • + *
    • {@code com.velocitypowered.api.proxy.Player}
    • + *
    + * + * @param the player type + * @since 5.1 + */ +public interface PlayerAdapter { + + /** + * Gets the {@link User} instance for the given {@code player}. + * + * @param player the player + * @return the user + * @see UserManager#getUser(UUID) + */ + @NonNull User getUser(@NonNull T player); + + /** + * Gets current {@link ImmutableContextSet active context} for the {@code player}. + * + * @param player the player + * @return the active context for the player + * @see ContextManager#getContext(Object) + */ + @NonNull ImmutableContextSet getContext(@NonNull T player); + + /** + * Gets current {@link QueryOptions active query options} for the {@code player}. + * + * @param player the player + * @return the active query options for the player + * @see ContextManager#getQueryOptions(Object) + */ + @NonNull QueryOptions getQueryOptions(@NonNull T player); + + /** + * Gets the current {@link CachedPermissionData} for the {@code player}, + * using their {@link #getQueryOptions(Object) active query options}. + * + * @param player the player + * @return the cached permission data for the player + * @see CachedDataManager#getPermissionData() + */ + default @NonNull CachedPermissionData getPermissionData(@NonNull T player) { + return getUser(player).getCachedData().getPermissionData(getQueryOptions(player)); + } + /** + * Gets the current {@link CachedMetaData} for the {@code player}, + * using their {@link #getQueryOptions(Object) active query options}. + * + * @param player the player + * @return the cached meta data for the player + * @see CachedDataManager#getMetaData() + */ + default @NonNull CachedMetaData getMetaData(@NonNull T player) { + return getUser(player).getCachedData().getMetaData(getQueryOptions(player)); + } + +} diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/context/BukkitContextManager.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/context/BukkitContextManager.java index 79ed300e1..32c2212e6 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/context/BukkitContextManager.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/context/BukkitContextManager.java @@ -40,9 +40,10 @@ import net.luckperms.api.query.QueryOptions; import org.bukkit.entity.Player; +import java.util.UUID; import java.util.concurrent.TimeUnit; -public class BukkitContextManager extends ContextManager { +public class BukkitContextManager extends ContextManager { public static final OptionKey OP_OPTION = OptionKey.of("op", Boolean.class); @@ -61,13 +62,18 @@ public class BukkitContextManager extends ContextManager { }); public BukkitContextManager(LPBukkitPlugin plugin) { - super(plugin, Player.class); + super(plugin, Player.class, Player.class); } public void onPlayerQuit(Player player) { this.onlineSubjectCaches.remove(player); } + @Override + public UUID getUniqueId(Player player) { + return player.getUniqueId(); + } + @Override public QueryOptionsCache getCacheFor(Player subject) { if (subject == null) { diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index 3021acbba..7168d805f 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -36,7 +36,6 @@ import me.lucko.luckperms.common.api.LuckPermsApiProvider; import me.lucko.luckperms.common.calculator.CalculatorFactory; import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; -import me.lucko.luckperms.common.context.ContextManager; import me.lucko.luckperms.common.dependencies.Dependency; import me.lucko.luckperms.common.event.AbstractEventBus; import me.lucko.luckperms.common.messaging.MessagingFactory; @@ -52,7 +51,6 @@ import me.lucko.luckperms.common.tasks.ExpireTemporaryTask; import net.luckperms.api.LuckPerms; import net.luckperms.api.query.QueryOptions; -import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; import java.io.IOException; @@ -75,7 +73,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin { private StandardUserManager userManager; private StandardGroupManager groupManager; private StandardTrackManager trackManager; - private ContextManager contextManager; + private BungeeContextManager contextManager; public LPBungeePlugin(LPBungeeBootstrap bootstrap) { this.bootstrap = bootstrap; @@ -236,7 +234,7 @@ public class LPBungeePlugin extends AbstractLuckPermsPlugin { } @Override - public ContextManager getContextManager() { + public BungeeContextManager getContextManager() { return this.contextManager; } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/context/BungeeContextManager.java b/bungee/src/main/java/me/lucko/luckperms/bungee/context/BungeeContextManager.java index 4891efcc9..ff8072b70 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/context/BungeeContextManager.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/context/BungeeContextManager.java @@ -36,16 +36,22 @@ import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.query.QueryOptions; import net.md_5.bungee.api.connection.ProxiedPlayer; +import java.util.UUID; import java.util.concurrent.TimeUnit; -public class BungeeContextManager extends ContextManager { +public class BungeeContextManager extends ContextManager { private final LoadingCache contextsCache = CaffeineFactory.newBuilder() .expireAfterWrite(50, TimeUnit.MILLISECONDS) .build(this::calculate); public BungeeContextManager(LPBungeePlugin plugin) { - super(plugin, ProxiedPlayer.class); + super(plugin, ProxiedPlayer.class, ProxiedPlayer.class); + } + + @Override + public UUID getUniqueId(ProxiedPlayer player) { + return player.getUniqueId(); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java b/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java index a1211fd57..6cc0e34d8 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/LuckPermsApiProvider.java @@ -33,6 +33,7 @@ import me.lucko.luckperms.common.api.implementation.ApiMetaStackFactory; import me.lucko.luckperms.common.api.implementation.ApiNodeBuilderRegistry; import me.lucko.luckperms.common.api.implementation.ApiNodeMatcherFactory; import me.lucko.luckperms.common.api.implementation.ApiPlatform; +import me.lucko.luckperms.common.api.implementation.ApiPlayerAdapter; import me.lucko.luckperms.common.api.implementation.ApiQueryOptionsRegistry; import me.lucko.luckperms.common.api.implementation.ApiTrackManager; import me.lucko.luckperms.common.api.implementation.ApiUserManager; @@ -53,11 +54,13 @@ import net.luckperms.api.node.NodeBuilderRegistry; import net.luckperms.api.node.matcher.NodeMatcherFactory; import net.luckperms.api.platform.Platform; import net.luckperms.api.platform.PluginMetadata; +import net.luckperms.api.player.PlayerAdapter; import net.luckperms.api.query.QueryOptionsRegistry; import net.luckperms.api.track.TrackManager; import org.checkerframework.checker.nullness.qual.NonNull; +import java.util.Objects; import java.util.Optional; import java.util.concurrent.CompletableFuture; @@ -72,6 +75,7 @@ public class LuckPermsApiProvider implements LuckPerms { private final UserManager userManager; private final GroupManager groupManager; private final TrackManager trackManager; + private final PlayerAdapter playerAdapter; private final ActionLogger actionLogger; private final ContextManager contextManager; private final MetaStackFactory metaStackFactory; @@ -83,6 +87,7 @@ public class LuckPermsApiProvider implements LuckPerms { this.userManager = new ApiUserManager(plugin, plugin.getUserManager()); this.groupManager = new ApiGroupManager(plugin, plugin.getGroupManager()); this.trackManager = new ApiTrackManager(plugin, plugin.getTrackManager()); + this.playerAdapter = new ApiPlayerAdapter<>(plugin.getUserManager(), plugin.getContextManager()); this.actionLogger = new ApiActionLogger(plugin); this.contextManager = new ApiContextManager(plugin, plugin.getContextManager()); this.metaStackFactory = new ApiMetaStackFactory(plugin); @@ -118,6 +123,17 @@ public class LuckPermsApiProvider implements LuckPerms { return this.trackManager; } + @SuppressWarnings("unchecked") + @Override + public @NonNull PlayerAdapter getPlayerAdapter(Class playerClass) { + Objects.requireNonNull(playerClass, "playerClass"); + Class expectedClass = this.plugin.getContextManager().getPlayerClass(); + if (!expectedClass.equals(playerClass)) { + throw new IllegalArgumentException("Player class " + playerClass.getName() + " does not equal " + expectedClass.getName()); + } + return (PlayerAdapter) this.playerAdapter; + } + @Override public @NonNull CompletableFuture runUpdateTask() { return this.plugin.getSyncTaskBuffer().request(); diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiContextManager.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiContextManager.java index ad10a72c9..0bd646c93 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiContextManager.java @@ -46,7 +46,7 @@ public class ApiContextManager implements net.luckperms.api.context.ContextManag private final LuckPermsPlugin plugin; private final ContextManager handle; - public ApiContextManager(LuckPermsPlugin plugin, ContextManager handle) { + public ApiContextManager(LuckPermsPlugin plugin, ContextManager handle) { this.plugin = plugin; this.handle = handle; } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPlayerAdapter.java b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPlayerAdapter.java new file mode 100644 index 000000000..ff85554d1 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/api/implementation/ApiPlayerAdapter.java @@ -0,0 +1,76 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.lucko.luckperms.common.api.implementation; + +import me.lucko.luckperms.common.context.ContextManager; +import me.lucko.luckperms.common.model.manager.user.UserManager; + +import net.luckperms.api.context.ImmutableContextSet; +import net.luckperms.api.model.user.User; +import net.luckperms.api.player.PlayerAdapter; +import net.luckperms.api.query.QueryOptions; + +import org.checkerframework.checker.nullness.qual.NonNull; + +import java.util.Objects; + +@SuppressWarnings({"unchecked", "rawtypes"}) +public class ApiPlayerAdapter implements PlayerAdapter

    { + private final UserManager userManager; + private final ContextManager contextManager; + + public ApiPlayerAdapter(UserManager userManager, ContextManager contextManager) { + this.userManager = userManager; + this.contextManager = contextManager; + } + + private P checkType(P player) { + if (!this.contextManager.getPlayerClass().isAssignableFrom(player.getClass())) { + throw new IllegalStateException("Player class " + player.getClass() + " is not assignable from " + this.contextManager.getPlayerClass()); + } + return player; + } + + @Override + public @NonNull User getUser(@NonNull P player) { + Objects.requireNonNull(player, "player"); + me.lucko.luckperms.common.model.User user = this.userManager.getIfLoaded(this.contextManager.getUniqueId(checkType(player))); + Objects.requireNonNull(user, "user"); + return user.getApiProxy(); + } + + @Override + public @NonNull ImmutableContextSet getContext(@NonNull P player) { + Objects.requireNonNull(player, "player"); + return this.contextManager.getContext(checkType(player)); + } + + @Override + public @NonNull QueryOptions getQueryOptions(@NonNull P player) { + Objects.requireNonNull(player, "player"); + return this.contextManager.getQueryOptions(checkType(player)); + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/AbstractCachedDataManager.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/AbstractCachedDataManager.java index db37f3d1f..3e58d6e1b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/AbstractCachedDataManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/AbstractCachedDataManager.java @@ -97,6 +97,16 @@ public abstract class AbstractCachedDataManager implements CachedDataManager { return this.metaDataManager.get(queryOptions); } + @Override + public @NonNull PermissionCache getPermissionData() { + return getPermissionData(getQueryOptions()); + } + + @Override + public @NonNull MetaCache getMetaData() { + return getMetaData(getQueryOptions()); + } + /** * Returns a {@link CacheMetadata} instance for the given {@link QueryOptions}. * @@ -105,6 +115,13 @@ public abstract class AbstractCachedDataManager implements CachedDataManager { */ protected abstract CacheMetadata getMetadataForQueryOptions(QueryOptions queryOptions); + /** + * Gets the most appropriate active query options instance for the holder. + * + * @return the query options + */ + protected abstract QueryOptions getQueryOptions(); + /** * Gets the {@link CalculatorFactory} used to build {@link PermissionCalculator}s. * diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java index 3bb2fec91..0b8d73fdf 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/GroupCachedDataManager.java @@ -44,4 +44,9 @@ public class GroupCachedDataManager extends HolderCachedDataManager imple protected CacheMetadata getMetadataForQueryOptions(QueryOptions queryOptions) { return new CacheMetadata(HolderType.GROUP, this.holder.getPlainDisplayName(), queryOptions); } + + @Override + protected QueryOptions getQueryOptions() { + return getPlugin().getContextManager().getStaticQueryOptions(); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java index 49c055ecf..432049ece 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/UserCachedDataManager.java @@ -44,4 +44,14 @@ public class UserCachedDataManager extends HolderCachedDataManager impleme protected CacheMetadata getMetadataForQueryOptions(QueryOptions queryOptions) { return new CacheMetadata(HolderType.USER, this.holder.getPlainDisplayName(), queryOptions); } + + @Override + protected QueryOptions getQueryOptions() { + QueryOptions queryOptions = getPlugin().getQueryOptionsForUser(this.holder).orElse(null); + if (queryOptions != null) { + return queryOptions; + } + + return getPlugin().getContextManager().getStaticQueryOptions(); + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java b/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java index 02a8ca3f4..b9de1f4fc 100644 --- a/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/context/ContextManager.java @@ -39,41 +39,50 @@ import net.luckperms.api.query.QueryOptions; import org.checkerframework.checker.nullness.qual.NonNull; import java.util.List; +import java.util.UUID; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; /** * Base implementation of {@link ContextManager} which caches content lookups. * - * @param the calculator type + * @param the calculator type */ -public abstract class ContextManager { +public abstract class ContextManager { protected final LuckPermsPlugin plugin; - private final Class subjectClass; + private final Class subjectClass; + private final Class

    playerClass; - private final List> calculators = new CopyOnWriteArrayList<>(); + private final List> calculators = new CopyOnWriteArrayList<>(); private final List staticCalculators = new CopyOnWriteArrayList<>(); // caches static context lookups private final StaticLookupCache staticLookupCache = new StaticLookupCache(); - protected ContextManager(LuckPermsPlugin plugin, Class subjectClass) { + protected ContextManager(LuckPermsPlugin plugin, Class subjectClass, Class

    playerClass) { this.plugin = plugin; this.subjectClass = subjectClass; + this.playerClass = playerClass; } - public Class getSubjectClass() { + public Class getSubjectClass() { return this.subjectClass; } - public abstract QueryOptionsSupplier getCacheFor(T subject); + public Class

    getPlayerClass() { + return this.playerClass; + } - public QueryOptions getQueryOptions(T subject) { + public abstract UUID getUniqueId(P player); + + public abstract QueryOptionsSupplier getCacheFor(S subject); + + public QueryOptions getQueryOptions(S subject) { return getCacheFor(subject).getQueryOptions(); } - public ImmutableContextSet getContext(T subject) { + public ImmutableContextSet getContext(S subject) { return getCacheFor(subject).getContextSet(); } @@ -89,11 +98,11 @@ public abstract class ContextManager { return this.plugin.getConfiguration().get(ConfigKeys.GLOBAL_QUERY_OPTIONS).toBuilder().context(contextSet).build(); } - public abstract QueryOptions formQueryOptions(T subject, ImmutableContextSet contextSet); + public abstract QueryOptions formQueryOptions(S subject, ImmutableContextSet contextSet); - public abstract void invalidateCache(T subject); + public abstract void invalidateCache(S subject); - public void registerCalculator(ContextCalculator calculator) { + public void registerCalculator(ContextCalculator calculator) { // calculators registered first should have priority (and be checked last.) this.calculators.add(0, calculator); @@ -103,16 +112,16 @@ public abstract class ContextManager { } } - public void unregisterCalculator(ContextCalculator calculator) { + public void unregisterCalculator(ContextCalculator calculator) { this.calculators.remove(calculator); if (calculator instanceof StaticContextCalculator) { this.staticCalculators.remove(calculator); } } - protected QueryOptions calculate(T subject) { + protected QueryOptions calculate(S subject) { ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl(); - for (ContextCalculator calculator : this.calculators) { + for (ContextCalculator calculator : this.calculators) { try { calculator.calculate(subject, accumulator::add); } catch (Throwable e) { @@ -138,7 +147,7 @@ public abstract class ContextManager { public ImmutableContextSet getPotentialContexts() { ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); - for (ContextCalculator calculator : this.calculators) { + for (ContextCalculator calculator : this.calculators) { ContextSet potentialContexts; try { potentialContexts = calculator.estimatePotentialContexts(); diff --git a/common/src/main/java/me/lucko/luckperms/common/context/QueryOptionsCache.java b/common/src/main/java/me/lucko/luckperms/common/context/QueryOptionsCache.java index f919370f8..457969b70 100644 --- a/common/src/main/java/me/lucko/luckperms/common/context/QueryOptionsCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/context/QueryOptionsCache.java @@ -41,9 +41,9 @@ import java.util.concurrent.TimeUnit; */ public final class QueryOptionsCache extends ExpiringCache implements QueryOptionsSupplier { private final T subject; - private final ContextManager contextManager; + private final ContextManager contextManager; - public QueryOptionsCache(T subject, ContextManager contextManager) { + public QueryOptionsCache(T subject, ContextManager contextManager) { super(50L, TimeUnit.MILLISECONDS); // expire roughly every tick this.subject = subject; this.contextManager = contextManager; diff --git a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java index 430891462..4b707309f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java +++ b/common/src/main/java/me/lucko/luckperms/common/plugin/LuckPermsPlugin.java @@ -188,7 +188,7 @@ public interface LuckPermsPlugin { * * @return the context manager */ - ContextManager getContextManager(); + ContextManager getContextManager(); /** * Gets the inheritance handler diff --git a/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java b/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java index 92684371c..5c616326b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java +++ b/common/src/main/java/me/lucko/luckperms/common/sender/Sender.java @@ -72,7 +72,7 @@ public interface Sender { default String getNameWithLocation() { String name = getName(); - ContextManager contextManager = getPlugin().getContextManager(); + ContextManager contextManager = getPlugin().getContextManager(); if (contextManager == null) { return name; } diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/context/NukkitContextManager.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/context/NukkitContextManager.java index d3941cab7..420050523 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/context/NukkitContextManager.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/context/NukkitContextManager.java @@ -40,9 +40,10 @@ import net.luckperms.api.query.QueryOptions; import cn.nukkit.Player; +import java.util.UUID; import java.util.concurrent.TimeUnit; -public class NukkitContextManager extends ContextManager { +public class NukkitContextManager extends ContextManager { public static final OptionKey OP_OPTION = OptionKey.of("op", Boolean.class); @@ -61,13 +62,18 @@ public class NukkitContextManager extends ContextManager { }); public NukkitContextManager(LPNukkitPlugin plugin) { - super(plugin, Player.class); + super(plugin, Player.class, Player.class); } public void onPlayerQuit(Player player) { this.onlineSubjectCaches.remove(player); } + @Override + public UUID getUniqueId(Player player) { + return player.getUniqueId(); + } + @Override public QueryOptionsCache getCacheFor(Player subject) { if (subject == null) { diff --git a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectProxy.java b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectProxy.java index b08a990eb..1457784cb 100644 --- a/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectProxy.java +++ b/sponge/sponge-service-api6/src/main/java/me/lucko/luckperms/sponge/service/proxy/api6/SubjectProxy.java @@ -34,7 +34,7 @@ import me.lucko.luckperms.sponge.service.model.LPSubjectReference; import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject; import me.lucko.luckperms.sponge.service.model.ProxiedSubject; -import net.luckperms.api.context.ImmutableContextSet; +import net.luckperms.api.query.QueryOptions; import org.checkerframework.checker.nullness.qual.NonNull; import org.spongepowered.api.command.CommandSource; @@ -78,6 +78,11 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi return this.ref; } + @Override + public @NonNull QueryOptions getQueryOptions() { + return getContextsCache().getQueryOptions(); + } + @Override public @NonNull Optional getCommandSource() { return handle().thenApply(LPSubject::getCommandSource).join(); @@ -105,7 +110,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi @Override public boolean hasPermission(@NonNull String permission) { - return handle().thenApply(handle -> handle.getPermissionValue(getActiveContextSet(), permission).asBoolean()).join(); + return handle().thenApply(handle -> handle.getPermissionValue(getContextsCache().getContextSet(), permission).asBoolean()).join(); } @Override @@ -116,7 +121,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi @Override public boolean isChildOf(@NonNull Subject parent) { return handle().thenApply(handle -> handle.isChildOf( - getActiveContextSet(), + getContextsCache().getContextSet(), this.service.getReferenceFactory().obtain(parent) )).join(); } @@ -132,7 +137,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi @SuppressWarnings("rawtypes") @Override public @NonNull List getParents() { - return (List) handle().thenApply(handle -> handle.getParents(getActiveContextSet()).stream() + return (List) handle().thenApply(handle -> handle.getParents(getContextsCache().getContextSet()).stream() .map(s -> new SubjectProxy(this.service, s)) .collect(ImmutableCollectors.toList())).join(); } @@ -152,7 +157,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi @Override public @NonNull Optional getOption(@NonNull String key) { - return handle().thenApply(handle -> handle.getOption(getActiveContextSet(), key)).join(); + return handle().thenApply(handle -> handle.getOption(getContextsCache().getContextSet(), key)).join(); } @Override @@ -165,11 +170,6 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi return CompatibilityUtil.convertContexts(getContextsCache().getContextSet()); } - @Override - public ImmutableContextSet getActiveContextSet() { - return getContextsCache().getContextSet(); - } - @Override public boolean equals(Object o) { return o == this || o instanceof SubjectProxy && this.ref.equals(((SubjectProxy) o).ref); diff --git a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectProxy.java b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectProxy.java index b81138bc6..91d30e85d 100644 --- a/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectProxy.java +++ b/sponge/sponge-service-api7/src/main/java/me/lucko/luckperms/sponge/service/proxy/api7/SubjectProxy.java @@ -33,7 +33,7 @@ import me.lucko.luckperms.sponge.service.model.LPSubjectReference; import me.lucko.luckperms.sponge.service.model.ProxiedServiceObject; import me.lucko.luckperms.sponge.service.model.ProxiedSubject; -import net.luckperms.api.context.ImmutableContextSet; +import net.luckperms.api.query.QueryOptions; import org.checkerframework.checker.nullness.qual.NonNull; import org.spongepowered.api.command.CommandSource; @@ -78,6 +78,11 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi return this.ref; } + @Override + public @NonNull QueryOptions getQueryOptions() { + return queryOptionsCache().getQueryOptions(); + } + @Override public @NonNull Optional getCommandSource() { return handle().thenApply(LPSubject::getCommandSource).join(); @@ -110,7 +115,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi @Override public boolean hasPermission(@NonNull String permission) { - return handle().thenApply(handle -> handle.getPermissionValue(getActiveContextSet(), permission).asBoolean()).join(); + return handle().thenApply(handle -> handle.getPermissionValue(queryOptionsCache().getContextSet(), permission).asBoolean()).join(); } @Override @@ -120,7 +125,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi @Override public boolean isChildOf(@NonNull SubjectReference parent) { - return handle().thenApply(handle -> handle.isChildOf(getActiveContextSet(), this.service.getReferenceFactory().obtain(parent))).join(); + return handle().thenApply(handle -> handle.isChildOf(queryOptionsCache().getContextSet(), this.service.getReferenceFactory().obtain(parent))).join(); } @Override @@ -131,7 +136,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi @SuppressWarnings("rawtypes") @Override public @NonNull List getParents() { - return (List) handle().thenApply(handle -> handle.getParents(getActiveContextSet())).join(); + return (List) handle().thenApply(handle -> handle.getParents(queryOptionsCache().getContextSet())).join(); } @SuppressWarnings("rawtypes") @@ -147,7 +152,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi @Override public @NonNull Optional getOption(@NonNull String key) { - return handle().thenApply(handle -> handle.getOption(getActiveContextSet(), key)).join(); + return handle().thenApply(handle -> handle.getOption(queryOptionsCache().getContextSet(), key)).join(); } @Override @@ -165,11 +170,6 @@ public final class SubjectProxy implements Subject, ProxiedSubject, ProxiedServi return CompatibilityUtil.convertContexts(queryOptionsCache().getContextSet()); } - @Override - public ImmutableContextSet getActiveContextSet() { - return queryOptionsCache().getContextSet(); - } - @Override public boolean equals(Object o) { return o == this || o instanceof SubjectProxy && this.ref.equals(((SubjectProxy) o).ref); diff --git a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java index 62eb48913..74ea0d264 100644 --- a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPPermissionService.java @@ -32,6 +32,7 @@ import me.lucko.luckperms.common.context.ContextManager; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory; +import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.service.context.ContextCalculator; import org.spongepowered.api.service.permission.PermissionService; @@ -48,7 +49,7 @@ public interface LPPermissionService { LuckPermsPlugin getPlugin(); - ContextManager getContextManager(); + ContextManager getContextManager(); SubjectReferenceFactory getReferenceFactory(); diff --git a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java index 939893428..153fb7531 100644 --- a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/LPSubject.java @@ -41,7 +41,7 @@ import java.util.Optional; */ public interface LPSubject { - Subject sponge(); + ProxiedSubject sponge(); LPPermissionService getService(); diff --git a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/ProxiedSubject.java b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/ProxiedSubject.java index a5f80a00d..0c72e6afc 100644 --- a/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/ProxiedSubject.java +++ b/sponge/sponge-service/src/main/java/me/lucko/luckperms/sponge/service/model/ProxiedSubject.java @@ -25,7 +25,7 @@ package me.lucko.luckperms.sponge.service.model; -import net.luckperms.api.context.ImmutableContextSet; +import net.luckperms.api.query.QueryOptions; import org.checkerframework.checker.nullness.qual.NonNull; import org.spongepowered.api.service.permission.Subject; @@ -33,11 +33,10 @@ import org.spongepowered.api.service.permission.Subject; /** * Marks that an object is a proxied representation of a {@link Subject}. */ -public interface ProxiedSubject extends ProxiedServiceObject { +public interface ProxiedSubject extends Subject, ProxiedServiceObject { - @NonNull - LPSubjectReference asSubjectReference(); + @NonNull LPSubjectReference asSubjectReference(); - ImmutableContextSet getActiveContextSet(); + @NonNull QueryOptions getQueryOptions(); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index bc94789d9..b1196a3dc 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -30,7 +30,6 @@ import me.lucko.luckperms.common.calculator.CalculatorFactory; import me.lucko.luckperms.common.command.abstraction.Command; import me.lucko.luckperms.common.command.access.CommandPermission; import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; -import me.lucko.luckperms.common.context.ContextManager; import me.lucko.luckperms.common.dependencies.Dependency; import me.lucko.luckperms.common.event.AbstractEventBus; import me.lucko.luckperms.common.messaging.MessagingFactory; @@ -64,7 +63,6 @@ import net.luckperms.api.query.QueryOptions; import org.spongepowered.api.service.permission.PermissionDescription; import org.spongepowered.api.service.permission.PermissionService; -import org.spongepowered.api.service.permission.Subject; import java.io.IOException; import java.io.InputStream; @@ -90,7 +88,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin { private SpongeUserManager userManager; private SpongeGroupManager groupManager; private StandardTrackManager trackManager; - private ContextManager contextManager; + private SpongeContextManager contextManager; private me.lucko.luckperms.sponge.service.LuckPermsService service; private UpdateEventHandler updateEventHandler; @@ -311,7 +309,7 @@ public class LPSpongePlugin extends AbstractLuckPermsPlugin { } @Override - public ContextManager getContextManager() { + public SpongeContextManager getContextManager() { return this.contextManager; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/context/SpongeContextManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/context/SpongeContextManager.java index c19c8ea7a..b3518b32e 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/context/SpongeContextManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/context/SpongeContextManager.java @@ -36,18 +36,25 @@ import me.lucko.luckperms.sponge.LPSpongePlugin; import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.query.QueryOptions; +import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.service.permission.Subject; +import java.util.UUID; import java.util.concurrent.TimeUnit; -public class SpongeContextManager extends ContextManager { +public class SpongeContextManager extends ContextManager { private final LoadingCache> subjectCaches = CaffeineFactory.newBuilder() .expireAfterAccess(1, TimeUnit.MINUTES) .build(key -> new QueryOptionsCache<>(key, this)); public SpongeContextManager(LPSpongePlugin plugin) { - super(plugin, Subject.class); + super(plugin, Subject.class, Player.class); + } + + @Override + public UUID getUniqueId(Player player) { + return player.getUniqueId(); } @Override diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java index 19ca718e1..f0bc30992 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java @@ -46,6 +46,7 @@ import me.lucko.luckperms.sponge.service.model.persisted.PersistedCollection; import me.lucko.luckperms.sponge.service.model.persisted.SubjectStorage; import me.lucko.luckperms.sponge.service.reference.SubjectReferenceFactory; +import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.service.context.ContextCalculator; import org.spongepowered.api.service.permission.PermissionService; @@ -143,7 +144,7 @@ public class LuckPermsService implements LPPermissionService { } @Override - public ContextManager getContextManager() { + public ContextManager getContextManager() { return this.plugin.getContextManager(); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java index 1c4c6461a..f72b2aa4b 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/ProxyFactory.java @@ -30,6 +30,7 @@ import me.lucko.luckperms.sponge.service.model.LPPermissionService; import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubjectCollection; import me.lucko.luckperms.sponge.service.model.LPSubjectData; +import me.lucko.luckperms.sponge.service.model.ProxiedSubject; import net.luckperms.api.model.data.DataType; @@ -67,7 +68,7 @@ public final class ProxyFactory { new me.lucko.luckperms.sponge.service.proxy.api6.SubjectCollectionProxy(luckPerms.getService(), luckPerms); } - public static Subject toSponge(LPSubject luckPerms) { + public static ProxiedSubject toSponge(LPSubject luckPerms) { return IS_API_7 ? new me.lucko.luckperms.sponge.service.proxy.api7.SubjectProxy(luckPerms.getService(), luckPerms.toReference()) : new me.lucko.luckperms.sponge.service.proxy.api6.SubjectProxy(luckPerms.getService(), luckPerms.toReference()); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectCachedDataManager.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectCachedDataManager.java index d6f8b49a9..a5ee5e735 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectCachedDataManager.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/calculated/CalculatedSubjectCachedDataManager.java @@ -67,6 +67,11 @@ public class CalculatedSubjectCachedDataManager extends AbstractCachedDataManage return new CacheMetadata(null, this.subject.getParentCollection().getIdentifier() + "/" + this.subject.getIdentifier(), queryOptions); } + @Override + protected QueryOptions getQueryOptions() { + return this.subject.sponge().getQueryOptions(); + } + @Override protected CalculatorFactory getCalculatorFactory() { return this; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubject.java index 846820751..f04a8e511 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/permissionholder/PermissionHolderSubject.java @@ -43,6 +43,7 @@ import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.ProxyFactory; import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubjectReference; +import me.lucko.luckperms.sponge.service.model.ProxiedSubject; import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.model.data.DataType; @@ -50,7 +51,6 @@ import net.luckperms.api.query.QueryOptions; import net.luckperms.api.util.Tristate; import org.spongepowered.api.service.permission.PermissionService; -import org.spongepowered.api.service.permission.Subject; import java.util.Optional; @@ -64,7 +64,7 @@ public abstract class PermissionHolderSubject implem private final PermissionHolderSubjectData subjectData; private final PermissionHolderSubjectData transientSubjectData; - private Subject spongeSubject = null; + private ProxiedSubject spongeSubject = null; PermissionHolderSubject(LPSpongePlugin plugin, T parent) { this.parent = parent; @@ -83,7 +83,7 @@ public abstract class PermissionHolderSubject implem } @Override - public synchronized Subject sponge() { + public synchronized ProxiedSubject sponge() { if (this.spongeSubject == null) { this.spongeSubject = ProxyFactory.toSponge(this); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubject.java index 485e3c6c0..8e70a492b 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/model/persisted/PersistedSubject.java @@ -31,6 +31,7 @@ import me.lucko.luckperms.sponge.service.LuckPermsService; import me.lucko.luckperms.sponge.service.ProxyFactory; import me.lucko.luckperms.sponge.service.model.LPSubject; import me.lucko.luckperms.sponge.service.model.LPSubjectData; +import me.lucko.luckperms.sponge.service.model.ProxiedSubject; import me.lucko.luckperms.sponge.service.model.calculated.CalculatedSubject; import me.lucko.luckperms.sponge.service.model.calculated.CalculatedSubjectData; import me.lucko.luckperms.sponge.service.model.calculated.MonitoredSubjectData; @@ -38,7 +39,6 @@ import me.lucko.luckperms.sponge.service.model.calculated.MonitoredSubjectData; import net.luckperms.api.model.data.DataType; import org.spongepowered.api.command.CommandSource; -import org.spongepowered.api.service.permission.Subject; import java.io.IOException; import java.util.Optional; @@ -64,7 +64,7 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject { private final PersistedSubjectData subjectData; private final CalculatedSubjectData transientSubjectData; - private Subject spongeSubject = null; + private ProxiedSubject spongeSubject = null; /** * The save buffer instance for saving changes to disk @@ -147,7 +147,7 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject { } @Override - public Subject sponge() { + public ProxiedSubject sponge() { if (this.spongeSubject == null) { this.spongeSubject = ProxyFactory.toSponge(this); } diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java b/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java index 5c9d0ffa1..ce32c8699 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/LPVelocityPlugin.java @@ -25,13 +25,10 @@ package me.lucko.luckperms.velocity; -import com.velocitypowered.api.proxy.Player; - import me.lucko.luckperms.common.api.LuckPermsApiProvider; import me.lucko.luckperms.common.calculator.CalculatorFactory; import me.lucko.luckperms.common.command.CommandManager; import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; -import me.lucko.luckperms.common.context.ContextManager; import me.lucko.luckperms.common.dependencies.Dependency; import me.lucko.luckperms.common.event.AbstractEventBus; import me.lucko.luckperms.common.messaging.MessagingFactory; @@ -76,7 +73,7 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin { private StandardUserManager userManager; private StandardGroupManager groupManager; private StandardTrackManager trackManager; - private ContextManager contextManager; + private VelocityContextManager contextManager; public LPVelocityPlugin(LPVelocityBootstrap bootstrap) { this.bootstrap = bootstrap; @@ -238,7 +235,7 @@ public class LPVelocityPlugin extends AbstractLuckPermsPlugin { } @Override - public ContextManager getContextManager() { + public VelocityContextManager getContextManager() { return this.contextManager; } diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/context/VelocityContextManager.java b/velocity/src/main/java/me/lucko/luckperms/velocity/context/VelocityContextManager.java index ce94cd2d4..b619da2ed 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/context/VelocityContextManager.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/context/VelocityContextManager.java @@ -37,16 +37,22 @@ import me.lucko.luckperms.velocity.LPVelocityPlugin; import net.luckperms.api.context.ImmutableContextSet; import net.luckperms.api.query.QueryOptions; +import java.util.UUID; import java.util.concurrent.TimeUnit; -public class VelocityContextManager extends ContextManager { +public class VelocityContextManager extends ContextManager { private final LoadingCache> subjectCaches = CaffeineFactory.newBuilder() .expireAfterAccess(1, TimeUnit.MINUTES) .build(key -> new QueryOptionsCache<>(key, this)); public VelocityContextManager(LPVelocityPlugin plugin) { - super(plugin, Player.class); + super(plugin, Player.class, Player.class); + } + + @Override + public UUID getUniqueId(Player player) { + return player.getUniqueId(); } @Override