Search in sources :

Example 1 with TemporaryModifier

use of me.lucko.luckperms.common.model.TemporaryModifier in project LuckPerms by lucko.

the class ParentAddTemp 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 groupName = ArgumentParser.parseName(0, args);
    long duration = ArgumentParser.parseDuration(1, args);
    TemporaryModifier modifier = ArgumentParser.parseTemporaryModifier(2, args).orElseGet(() -> plugin.getConfiguration().get(ConfigKeys.TEMPORARY_ADD_BEHAVIOUR));
    MutableContextSet context = ArgumentParser.parseContext(2, args, plugin);
    Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
    if (group == null) {
        return CommandResult.INVALID_ARGS;
    }
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (ArgumentPermissions.checkArguments(plugin, sender, permission, group.getName())) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (group.getName().equalsIgnoreCase(holder.getObjectName())) {
        Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
    Map.Entry<DataMutateResult, Node> ret = holder.setPermission(NodeFactory.buildGroupNode(group.getName()).setExpiry(duration).withExtraContext(context).build(), modifier);
    if (ret.getKey().asBoolean()) {
        duration = ret.getValue().getExpiryUnixTime();
        Message.SET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), DateUtil.formatDateDiff(duration), MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "addtemp", group.getName(), duration, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.ALREADY_TEMP_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : TemporaryModifier(me.lucko.luckperms.common.model.TemporaryModifier) Group(me.lucko.luckperms.common.model.Group) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Node(me.lucko.luckperms.api.Node) DataMutateResult(me.lucko.luckperms.api.DataMutateResult) Map(java.util.Map)

Example 2 with TemporaryModifier

use of me.lucko.luckperms.common.model.TemporaryModifier in project LuckPerms by lucko.

the class MetaAddTempChatMeta 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;
    }
    int priority = ArgumentParser.parsePriority(0, args);
    String meta = ArgumentParser.parseString(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;
    }
    Map.Entry<DataMutateResult, Node> ret = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).setExpiry(duration).withExtraContext(context).build(), modifier);
    if (ret.getKey().asBoolean()) {
        duration = ret.getValue().getExpiryUnixTime();
        TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, DateUtil.formatDateDiff(duration), MessageUtils.contextSetToString(context)), CommandManager.SECTION_CHAR).toBuilder();
        HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextUtils.fromLegacy("¥3Raw " + this.type.name().toLowerCase() + ": ¥r" + meta, '¥'));
        builder.applyDeep(c -> c.hoverEvent(event));
        sender.sendMessage(builder.build());
        ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "addtemp" + this.type.name().toLowerCase(), priority, meta, duration, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.ALREADY_HAS_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
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) DataMutateResult(me.lucko.luckperms.api.DataMutateResult) Map(java.util.Map)

Example 3 with TemporaryModifier

use of me.lucko.luckperms.common.model.TemporaryModifier 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 4 with TemporaryModifier

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

Aggregations

Node (me.lucko.luckperms.api.Node)4 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)4 TemporaryModifier (me.lucko.luckperms.common.model.TemporaryModifier)4 Map (java.util.Map)3 DataMutateResult (me.lucko.luckperms.api.DataMutateResult)3 TextComponent (net.kyori.text.TextComponent)2 HoverEvent (net.kyori.text.event.HoverEvent)2 Group (me.lucko.luckperms.common.model.Group)1