+ * 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 super T> calculator) {
+ public void registerCalculator(ContextCalculator super S> 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 super T> calculator) {
+ public void unregisterCalculator(ContextCalculator super S> 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 super T> calculator : this.calculators) {
+ for (ContextCalculator super S> 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 super T> calculator : this.calculators) {
+ for (ContextCalculator super S> 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