Search in sources :

Example 11 with DataMutateResult

use of me.lucko.luckperms.api.DataMutateResult 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 12 with DataMutateResult

use of me.lucko.luckperms.api.DataMutateResult 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 13 with DataMutateResult

use of me.lucko.luckperms.api.DataMutateResult in project LuckPerms by lucko.

the class ParentAdd 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);
    MutableContextSet context = ArgumentParser.parseContext(1, 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;
    }
    DataMutateResult result = holder.setPermission(NodeFactory.buildGroupNode(group.getName()).withExtraContext(context).build());
    if (result.asBoolean()) {
        Message.SET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "add", group.getName(), context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.ALREADY_INHERITS.send(sender, holder.getFriendlyName(), group.getFriendlyName(), MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) DataMutateResult(me.lucko.luckperms.api.DataMutateResult)

Example 14 with DataMutateResult

use of me.lucko.luckperms.api.DataMutateResult in project LuckPerms by lucko.

the class ParentRemoveTemp 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.parseNameWithSpace(0, args);
    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, groupName)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).setExpiry(10L).withExtraContext(context).build());
    if (result.asBoolean()) {
        Message.UNSET_TEMP_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "removetemp", groupName, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.DOES_NOT_TEMP_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) DataMutateResult(me.lucko.luckperms.api.DataMutateResult)

Example 15 with DataMutateResult

use of me.lucko.luckperms.api.DataMutateResult in project LuckPerms by lucko.

the class TrackAppend method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Track track, List<String> args, String label) {
    String groupName = args.get(0).toLowerCase();
    if (!DataConstraints.GROUP_NAME_TEST.test(groupName)) {
        sendDetailedUsage(sender, label);
        return CommandResult.INVALID_ARGS;
    }
    Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
    if (group == null) {
        return CommandResult.LOADING_ERROR;
    }
    DataMutateResult result = track.appendGroup(group);
    if (result.asBoolean()) {
        Message.TRACK_APPEND_SUCCESS.send(sender, group.getName(), track.getName());
        if (track.getGroups().size() > 1) {
            Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), group.getName()));
        }
        ExtendedLogEntry.build().actor(sender).acted(track).action("append", group.getName()).build().submit(plugin, sender);
        StorageAssistant.save(track, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.TRACK_ALREADY_CONTAINS.send(sender, track.getName(), group.getName());
        return CommandResult.STATE_ERROR;
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) DataMutateResult(me.lucko.luckperms.api.DataMutateResult)

Aggregations

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