Search in sources :

Example 1 with TreeView

use of me.lucko.luckperms.common.treeview.TreeView 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)

Aggregations

UUID (java.util.UUID)1 PermissionCache (me.lucko.luckperms.common.caching.type.PermissionCache)1 User (me.lucko.luckperms.common.model.User)1 TreeView (me.lucko.luckperms.common.treeview.TreeView)1 Component (net.kyori.text.Component)1 TextComponent (net.kyori.text.TextComponent)1 ClickEvent (net.kyori.text.event.ClickEvent)1 HoverEvent (net.kyori.text.event.HoverEvent)1