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 97cf8904..91ad02ba 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 @@ -54,20 +54,26 @@ public final class SubjectProxy implements Subject, ProxiedSubject { private final LPPermissionService service; private final LPSubjectReference ref; - private final ContextsCache contextsCache; + private ContextsCache contextsCache = null; public SubjectProxy(LPPermissionService service, LPSubjectReference ref) { this.service = service; this.ref = ref; - - ContextManager contextManager = (ContextManager) service.getPlugin().getContextManager(); - this.contextsCache = contextManager.getCacheFor(this); } private CompletableFuture handle() { return this.ref.resolveLp(); } + // lazy init + private ContextsCache getContextsCache() { + if (this.contextsCache == null) { + ContextManager contextManager = (ContextManager) this.service.getPlugin().getContextManager(); + this.contextsCache = contextManager.getCacheFor(this); + } + return this.contextsCache; + } + @Nonnull @Override public LPSubjectReference asSubjectReference() { @@ -164,7 +170,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject { @Nonnull @Override public Set getActiveContexts() { - return CompatibilityUtil.convertContexts(this.contextsCache.getContextSet()); + return CompatibilityUtil.convertContexts(getContextsCache().getContextSet()); } @Override 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 81fe9a97..c08c7f15 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 @@ -54,20 +54,26 @@ public final class SubjectProxy implements Subject, ProxiedSubject { private final LPPermissionService service; private final LPSubjectReference ref; - private final ContextsCache contextsCache; + private ContextsCache contextsCache; public SubjectProxy(LPPermissionService service, LPSubjectReference ref) { this.service = service; this.ref = ref; - - ContextManager contextManager = (ContextManager) service.getPlugin().getContextManager(); - this.contextsCache = contextManager.getCacheFor(this); } private CompletableFuture handle() { return this.ref.resolveLp(); } + // lazy init + private ContextsCache getContextsCache() { + if (this.contextsCache == null) { + ContextManager contextManager = (ContextManager) this.service.getPlugin().getContextManager(); + this.contextsCache = contextManager.getCacheFor(this); + } + return this.contextsCache; + } + @Nonnull @Override public LPSubjectReference asSubjectReference() { @@ -165,7 +171,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject { @Nonnull @Override public Set getActiveContexts() { - return CompatibilityUtil.convertContexts(this.contextsCache.getContextSet()); + return CompatibilityUtil.convertContexts(getContextsCache().getContextSet()); } @Override