use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.
the class PermissionInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3> " + (node.getValuePrimitive() ? "¥a" : "¥c") + node.getPermission(), " ", "¥7Click to remove this node from " + holder.getFriendlyName()), '¥'));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.
the class ParentInfo method makeFancy.
private static Consumer<BuildableComponent.Builder<?, ?>> makeFancy(PermissionHolder holder, String label, Node node) {
HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("&3> &f" + node.getGroupName(), " ", "&7Click to remove this parent from " + holder.getFriendlyName()), CommandManager.AMPERSAND_CHAR));
String command = "/" + label + " " + NodeFactory.nodeAsCommand(node, holder.getType().isGroup() ? holder.getObjectName() : holder.getFriendlyName(), holder.getType(), false);
ClickEvent clickEvent = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command);
return component -> {
component.hoverEvent(hoverEvent);
component.clickEvent(clickEvent);
};
}
use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.
the class AssignmentExpression method parse.
public boolean parse(PermissionHolder holder, Tristate tristate) throws IllegalArgumentException {
ScriptEngine engine = Scripting.getScriptEngine();
if (engine == null) {
throw new NullPointerException("script engine");
}
Predicate<Node> checker = node -> holder.hasPermission(node, StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY) == tristate;
String exp = this.expression.stream().map(t -> t.forExpression(checker)).collect(Collectors.joining()).replace("&", "&&").replace("|", "||");
try {
String result = engine.eval(exp).toString();
if (!result.equals("true") && !result.equals("false")) {
throw new IllegalArgumentException();
}
return Boolean.parseBoolean(result);
} catch (Throwable t) {
throw new IllegalArgumentException(exp, t);
}
}
use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.
the class EditorCommand method execute.
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
Type type = Type.ALL;
// parse type
String typeString = ArgumentParser.parseStringOrElse(0, args, null);
if (typeString != null) {
try {
type = Type.valueOf(typeString.toUpperCase());
} catch (IllegalArgumentException e) {
// ignored
}
}
// collect holders
List<PermissionHolder> holders = new ArrayList<>();
if (type.includingGroups) {
plugin.getGroupManager().getAll().values().stream().sorted((o1, o2) -> {
int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
}).forEach(holders::add);
}
if (type.includingUsers) {
plugin.getUserManager().getAll().values().stream().sorted((o1, o2) -> o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName())).forEach(holders::add);
}
// remove holders which the sender doesn't have perms to view
holders.removeIf(holder -> ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder));
// they don't have perms to view any of them
if (holders.isEmpty()) {
Message.COMMAND_NO_PERMISSION.send(sender);
return CommandResult.NO_PERMISSION;
}
Message.EDITOR_START.send(sender);
// form the payload data
JsonObject payload = WebEditor.formPayload(holders, sender, label, plugin);
// upload the payload data to gist
String pasteId = StandardPastebin.BYTEBIN.postJson(payload, true).id();
if (pasteId == null) {
Message.EDITOR_UPLOAD_FAILURE.send(sender);
return CommandResult.STATE_ERROR;
}
// form a url for the editor
String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + "?" + pasteId;
Message.EDITOR_URL.send(sender);
Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the editor.").color(TextColor.GRAY))).build();
sender.sendMessage(message);
return CommandResult.SUCCESS;
}
use of me.lucko.luckperms.common.model.PermissionHolder in project LuckPerms by lucko.
the class VaultChatHook method setChatMeta.
private void setChatMeta(PermissionHolder holder, ChatMetaType type, String value, String world) {
if (log()) {
logMsg("#setChatMeta: %s - %s - %s - %s", holder.getFriendlyName(), type, value, world);
}
this.permissionHook.getExecutor().execute(() -> {
// remove all prefixes/suffixes directly set on the user/group
holder.removeIf(type::matches);
if (value == null) {
this.permissionHook.holderSave(holder);
return;
}
// find the max inherited priority & add 10
MetaAccumulator metaAccumulator = holder.accumulateMeta(null, createContextForWorldSet(world));
int priority = (type == ChatMetaType.PREFIX ? metaAccumulator.getPrefixes() : metaAccumulator.getSuffixes()).keySet().stream().mapToInt(e -> e).max().orElse(0) + 10;
Node.Builder chatMetaNode = NodeFactory.buildChatMetaNode(type, priority, value);
chatMetaNode.setServer(this.permissionHook.getVaultServer());
chatMetaNode.setWorld(world);
holder.setPermission(chatMetaNode.build());
this.permissionHook.holderSave(holder);
});
}
Aggregations