use of me.lucko.luckperms.sponge.service.model.LPSubject in project LuckPerms by lucko.
the class CachedSubjectReference method fillCache.
void fillCache(LPSubject subject) {
LPSubject sub = tryCache();
if (sub == null) {
// if no value is currently cached, populate with the passed value
this.lastLookup = System.currentTimeMillis();
this.cache = new WeakReference<>(subject);
} else if (sub == subject) {
// if equal, reset the cache timeout
this.lastLookup = System.currentTimeMillis();
}
}
use of me.lucko.luckperms.sponge.service.model.LPSubject in project LuckPerms by lucko.
the class ParentRemove method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
String collection = args.get(0);
String name = args.get(1);
ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
LPPermissionService service = Sponge.getServiceManager().provideUnchecked(LPPermissionService.class);
if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
MessageUtils.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't exist.");
}
LPSubjectCollection c = service.getCollection(collection);
if (!c.hasRegistered(name).join()) {
MessageUtils.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't exist.");
}
LPSubject subject = c.loadSubject(name).join();
if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
MessageUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() + "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
} else {
MessageUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?");
}
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.sponge.service.model.LPSubject in project LuckPerms by lucko.
the class CachedSubjectReference method resolveDirectly.
private synchronized LPSubject resolveDirectly() {
/* As this method is synchronized, it's possible that since this was invoked
the subject has been cached.
Therefore, we check the cache again, and return if there's a value present.
This effectively means all calls to this method block, but all return the same value
at the same time once the data is loaded :) */
LPSubject s = tryCache();
if (s != null) {
return s;
}
// subject isn't cached, so make a call to load it
s = this.service.getCollection(this.collectionIdentifier).loadSubject(this.subjectIdentifier).join();
// cache the result
this.lastLookup = System.currentTimeMillis();
this.cache = new WeakReference<>(s);
return s;
}
use of me.lucko.luckperms.sponge.service.model.LPSubject in project LuckPerms by lucko.
the class SpongeUserManager method loadSubjects.
@Override
public CompletableFuture<ImmutableCollection<LPSubject>> loadSubjects(Set<String> identifiers) {
return CompletableFuture.supplyAsync(() -> {
ImmutableSet.Builder<LPSubject> ret = ImmutableSet.builder();
for (String id : identifiers) {
UUID uuid = Uuids.parseNullable(id);
if (uuid == null) {
continue;
}
ret.add(loadSubject(uuid.toString()).join());
}
return ret.build();
}, this.plugin.getBootstrap().getScheduler().async());
}
Aggregations