Search in sources :

Example 21 with MutableContextSet

use of me.lucko.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class PermissionCheckInherits method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    String node = ArgumentParser.parseString(0, args);
    MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
    InheritanceInfo result = holder.searchForInheritedMatch(NodeFactory.builder(node).withExtraContext(context).build(), StandardNodeEquality.IGNORE_VALUE_OR_IF_TEMPORARY);
    String location = result.getLocation().orElse(null);
    if (location == null || location.equalsIgnoreCase(holder.getObjectName())) {
        location = "self";
    }
    String s = MessageUtils.formatTristate(result.getResult());
    Message.CHECK_INHERITS_PERMISSION.send(sender, holder.getFriendlyName(), node, s, MessageUtils.contextSetToString(context), String.valueOf(location));
    return CommandResult.SUCCESS;
}
Also used : InheritanceInfo(me.lucko.luckperms.common.node.InheritanceInfo) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet)

Example 22 with MutableContextSet

use of me.lucko.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class PermissionSetTemp method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    String node = ArgumentParser.parseString(0, args);
    boolean value = ArgumentParser.parseBoolean(1, args);
    long duration = ArgumentParser.parseDuration(2, args);
    TemporaryModifier modifier = ArgumentParser.parseTemporaryModifier(3, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
    MutableContextSet context = ArgumentParser.parseContext(3, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (ArgumentPermissions.checkArguments(plugin, sender, permission, node)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Map.Entry<DataMutateResult, Node> result = holder.setPermission(NodeFactory.builder(node).setValue(value).withExtraContext(context).setExpiry(duration).build(), modifier);
    if (result.getKey().asBoolean()) {
        duration = result.getValue().getExpiryUnixTime();
        Message.SETPERMISSION_TEMP_SUCCESS.send(sender, node, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration), MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("permission", "settemp", node, value, duration, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.ALREADY_HAS_TEMP_PERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : TemporaryModifier(me.lucko.luckperms.common.model.TemporaryModifier) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Node(me.lucko.luckperms.api.Node) DataMutateResult(me.lucko.luckperms.api.DataMutateResult) Map(java.util.Map)

Example 23 with MutableContextSet

use of me.lucko.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class MetaSet method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    String key = args.get(0);
    String value = args.get(1);
    MutableContextSet context = ArgumentParser.parseContext(2, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).build();
    if (holder.hasPermission(n).asBoolean()) {
        Message.ALREADY_HAS_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
    holder.clearMetaKeys(key, context, false);
    holder.setPermission(n);
    TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), MessageUtils.contextSetToString(context))).toBuilder();
    HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), '¥'));
    builder.applyDeep(c -> c.hoverEvent(event));
    sender.sendMessage(builder.build());
    ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "set", key, value, context).build().submit(plugin, sender);
    StorageAssistant.save(holder, sender, plugin);
    return CommandResult.SUCCESS;
}
Also used : TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Node(me.lucko.luckperms.api.Node)

Example 24 with MutableContextSet

use of me.lucko.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class MetaSetTemp method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    String key = args.get(0);
    String value = args.get(1);
    long duration = ArgumentParser.parseDuration(2, args);
    TemporaryModifier modifier = ArgumentParser.parseTemporaryModifier(3, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
    MutableContextSet context = ArgumentParser.parseContext(3, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Node n = NodeFactory.buildMetaNode(key, value).withExtraContext(context).setExpiry(duration).build();
    if (holder.hasPermission(n).asBoolean()) {
        Message.ALREADY_HAS_TEMP_META.send(sender, holder.getFriendlyName(), key, value, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
    holder.clearMetaKeys(key, context, true);
    duration = holder.setPermission(n, modifier).getValue().getExpiryUnixTime();
    TextComponent.Builder builder = TextUtils.fromLegacy(Message.SET_META_TEMP_SUCCESS.asString(plugin.getLocaleManager(), key, value, holder.getFriendlyName(), DateUtil.formatDateDiff(duration), MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
    HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy(TextUtils.joinNewline("¥3Raw key: ¥r" + key, "¥3Raw value: ¥r" + value), '¥'));
    builder.applyDeep(c -> c.hoverEvent(event));
    sender.sendMessage(builder.build());
    ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "settemp", key, value, duration, context).build().submit(plugin, sender);
    StorageAssistant.save(holder, sender, plugin);
    return CommandResult.SUCCESS;
}
Also used : TemporaryModifier(me.lucko.luckperms.common.model.TemporaryModifier) TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Node(me.lucko.luckperms.api.Node)

Example 25 with MutableContextSet

use of me.lucko.luckperms.api.context.MutableContextSet in project LuckPerms by lucko.

the class MetaUnsetTemp method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, PermissionHolder holder, List<String> args, String label, CommandPermission permission) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, permission, holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    String key = args.get(0);
    MutableContextSet context = ArgumentParser.parseContext(1, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (ArgumentPermissions.checkArguments(plugin, sender, permission, key)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (holder.clearMetaKeys(key, context, true)) {
        Message.UNSET_META_TEMP_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "unsettemp", key, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.DOESNT_HAVE_TEMP_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet)

Aggregations

MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)31 DataMutateResult (me.lucko.luckperms.api.DataMutateResult)12 Node (me.lucko.luckperms.api.Node)7 Group (me.lucko.luckperms.common.model.Group)6 TextComponent (net.kyori.text.TextComponent)6 HoverEvent (net.kyori.text.event.HoverEvent)6 Map (java.util.Map)5 TemporaryModifier (me.lucko.luckperms.common.model.TemporaryModifier)4 Track (me.lucko.luckperms.common.model.Track)4 User (me.lucko.luckperms.common.model.User)4 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 ExtendedLogEntry (me.lucko.luckperms.common.actionlog.ExtendedLogEntry)2 CommandResult (me.lucko.luckperms.common.command.CommandResult)2 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)2 SubCommand (me.lucko.luckperms.common.command.abstraction.SubCommand)2 ArgumentPermissions (me.lucko.luckperms.common.command.access.ArgumentPermissions)2 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)2 ArgumentParser (me.lucko.luckperms.common.command.utils.ArgumentParser)2