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