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;
}
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();
}
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;
}
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)));
}
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();
}
Aggregations