Search in sources :

Example 1 with PermissionCache

use of me.lucko.luckperms.common.caching.type.PermissionCache in project LuckPerms by lucko.

the class TreeCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    String selection = ".";
    String player = null;
    if (!args.isEmpty()) {
        selection = args.get(0);
    }
    if (args.size() > 1) {
        player = args.get(1);
    }
    User user;
    if (player != null) {
        UUID u = Uuids.parseNullable(player);
        if (u != null) {
            user = plugin.getUserManager().getIfLoaded(u);
        } else {
            user = plugin.getUserManager().getByUsername(player);
        }
        if (user == null) {
            Message.USER_NOT_ONLINE.send(sender, player);
            return CommandResult.STATE_ERROR;
        }
    } else {
        user = null;
    }
    TreeView view = new TreeView(plugin.getPermissionVault(), selection);
    if (!view.hasData()) {
        Message.TREE_EMPTY.send(sender);
        return CommandResult.FAILURE;
    }
    Message.TREE_UPLOAD_START.send(sender);
    PermissionCache permissionData = user == null ? null : user.getCachedData().getPermissionData(plugin.getContextForUser(user).orElse(plugin.getContextManager().getStaticContexts()));
    String id = view.uploadPasteData(sender, user, permissionData);
    String url = plugin.getConfiguration().get(ConfigKeys.TREE_VIEWER_URL_PATTERN) + "?" + id;
    Message.TREE_URL.send(sender);
    Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(url))).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the tree view.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : HoverEvent(net.kyori.text.event.HoverEvent) User(me.lucko.luckperms.common.model.User) ClickEvent(net.kyori.text.event.ClickEvent) TreeView(me.lucko.luckperms.common.treeview.TreeView) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) UUID(java.util.UUID) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component)

Example 2 with PermissionCache

use of me.lucko.luckperms.common.caching.type.PermissionCache in project LuckPerms by lucko.

the class VaultPermissionHook method groupHasPermission.

@Override
public boolean groupHasPermission(String world, String name, String permission) {
    Objects.requireNonNull(name, "name");
    Objects.requireNonNull(permission, "permission");
    Group group = getGroup(name);
    if (group == null) {
        return false;
    }
    Contexts contexts = contextForLookup(null, world);
    PermissionCache permissionData = group.getCachedData().getPermissionData(contexts);
    Tristate result = permissionData.getPermissionValue(permission, CheckOrigin.INTERNAL);
    if (log()) {
        logMsg("#groupHasPermission: %s - %s - %s - %s", group.getName(), contexts.getContexts().toMultimap(), permission, result);
    }
    return result.asBoolean();
}
Also used : Group(me.lucko.luckperms.common.model.Group) Tristate(me.lucko.luckperms.api.Tristate) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Contexts(me.lucko.luckperms.api.Contexts)

Example 3 with PermissionCache

use of me.lucko.luckperms.common.caching.type.PermissionCache in project LuckPerms by lucko.

the class AbstractCachedData method calculatePermissions.

/**
 * Calculates a {@link PermissionCache} instance.
 *
 * @param contexts the contexts to calculate in
 * @param data an old data instance to try to reuse - ignored if null
 * @return the calculated instance
 */
private PermissionCache calculatePermissions(Contexts contexts, PermissionCache data) {
    Objects.requireNonNull(contexts, "contexts");
    if (data == null) {
        PermissionCalculatorMetadata metadata = getMetadataForContexts(contexts);
        data = new PermissionCache(contexts, metadata, getCalculatorFactory());
    }
    if (contexts == Contexts.allowAll()) {
        data.setPermissions(resolvePermissions());
    } else {
        data.setPermissions(resolvePermissions(contexts));
    }
    return data;
}
Also used : PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) PermissionCalculatorMetadata(me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata)

Example 4 with PermissionCache

use of me.lucko.luckperms.common.caching.type.PermissionCache in project LuckPerms by lucko.

the class AbstractCachedData method reloadPermissions.

@Nonnull
@Override
public CompletableFuture<PermissionCache> reloadPermissions(@Nonnull Contexts contexts) {
    Objects.requireNonNull(contexts, "contexts");
    // get the previous value - to use when recalculating
    PermissionCache previous = this.permission.getIfPresent(contexts);
    // invalidate the entry
    this.permission.invalidate(contexts);
    // repopulate the cache
    return CompletableFuture.supplyAsync(() -> this.permission.get(contexts, c -> calculatePermissions(c, previous)));
}
Also used : PermissionCalculatorMetadata(me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) FullySatisfiedContexts(me.lucko.luckperms.api.FullySatisfiedContexts) CacheLoader(com.github.benmanes.caffeine.cache.CacheLoader) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) Contexts(me.lucko.luckperms.api.Contexts) PermissionCalculator(me.lucko.luckperms.common.calculators.PermissionCalculator) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Set(java.util.Set) CachedData(me.lucko.luckperms.api.caching.CachedData) CompletableFuture(java.util.concurrent.CompletableFuture) MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) CalculatorFactory(me.lucko.luckperms.common.calculators.CalculatorFactory) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache) HashSet(java.util.HashSet) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) SimpleMetaStack(me.lucko.luckperms.common.metastacking.SimpleMetaStack) Map(java.util.Map) ChatMetaType(me.lucko.luckperms.api.ChatMetaType) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Nonnull(javax.annotation.Nonnull) MetaAccumulator(me.lucko.luckperms.common.caching.type.MetaAccumulator) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Nonnull(javax.annotation.Nonnull)

Example 5 with PermissionCache

use of me.lucko.luckperms.common.caching.type.PermissionCache in project LuckPerms by lucko.

the class VaultPermissionHook method userHasPermission.

@Override
public boolean userHasPermission(String world, UUID uuid, String permission) {
    if (uuid == null) {
        return false;
    }
    Objects.requireNonNull(permission, "permission");
    User user = getUser(uuid);
    if (user == null) {
        return false;
    }
    Contexts contexts = contextForLookup(user, world);
    PermissionCache permissionData = user.getCachedData().getPermissionData(contexts);
    Tristate result = permissionData.getPermissionValue(permission, CheckOrigin.INTERNAL);
    if (log()) {
        logMsg("#userHasPermission: %s - %s - %s - %s", user.getFriendlyName(), contexts.getContexts().toMultimap(), permission, result);
    }
    return result.asBoolean();
}
Also used : User(me.lucko.luckperms.common.model.User) Tristate(me.lucko.luckperms.api.Tristate) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Contexts(me.lucko.luckperms.api.Contexts)

Aggregations

PermissionCache (me.lucko.luckperms.common.caching.type.PermissionCache)5 Contexts (me.lucko.luckperms.api.Contexts)3 Tristate (me.lucko.luckperms.api.Tristate)2 PermissionCalculatorMetadata (me.lucko.luckperms.common.calculators.PermissionCalculatorMetadata)2 User (me.lucko.luckperms.common.model.User)2 CacheLoader (com.github.benmanes.caffeine.cache.CacheLoader)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 LoadingCache (com.github.benmanes.caffeine.cache.LoadingCache)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 Nonnull (javax.annotation.Nonnull)1 ChatMetaType (me.lucko.luckperms.api.ChatMetaType)1 FullySatisfiedContexts (me.lucko.luckperms.api.FullySatisfiedContexts)1 CachedData (me.lucko.luckperms.api.caching.CachedData)1 MetaContexts (me.lucko.luckperms.api.caching.MetaContexts)1