Search in sources :

Example 1 with DataMutateResult

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

the class TrackInsert 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;
    }
    int pos;
    try {
        pos = Integer.parseInt(args.get(1));
    } catch (NumberFormatException e) {
        Message.TRACK_INSERT_ERROR_NUMBER.send(sender, args.get(1));
        return CommandResult.INVALID_ARGS;
    }
    Group group = StorageAssistant.loadGroup(groupName, sender, plugin, false);
    if (group == null) {
        return CommandResult.LOADING_ERROR;
    }
    try {
        DataMutateResult result = track.insertGroup(group, pos - 1);
        if (result.asBoolean()) {
            Message.TRACK_INSERT_SUCCESS.send(sender, group.getName(), track.getName(), pos);
            if (track.getGroups().size() > 1) {
                Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups(), group.getName()));
            }
            ExtendedLogEntry.build().actor(sender).acted(track).action("insert", group.getName(), pos).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;
        }
    } catch (IndexOutOfBoundsException e) {
        Message.TRACK_INSERT_ERROR_INVALID_POS.send(sender, pos);
        return CommandResult.INVALID_ARGS;
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) DataMutateResult(me.lucko.luckperms.api.DataMutateResult)

Example 2 with DataMutateResult

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

the class TrackRemove 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;
    }
    DataMutateResult result = track.removeGroup(groupName);
    if (result.asBoolean()) {
        Message.TRACK_REMOVE_SUCCESS.send(sender, groupName, track.getName());
        if (track.getGroups().size() > 1) {
            Message.EMPTY.send(sender, MessageUtils.listToArrowSep(track.getGroups()));
        }
        ExtendedLogEntry.build().actor(sender).acted(track).action("remove", groupName).build().submit(plugin, sender);
        StorageAssistant.save(track, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.TRACK_DOES_NOT_CONTAIN.send(sender, track.getName(), groupName);
        return CommandResult.STATE_ERROR;
    }
}
Also used : DataMutateResult(me.lucko.luckperms.api.DataMutateResult)

Example 3 with DataMutateResult

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

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

the class ParentRemove 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;
    }
    if (holder.getType().isUser()) {
        User user = (User) holder;
        boolean shouldPrevent = plugin.getConfiguration().get(ConfigKeys.PREVENT_PRIMARY_GROUP_REMOVAL) && context.isEmpty() && plugin.getConfiguration().get(ConfigKeys.PRIMARY_GROUP_CALCULATION_METHOD).equals("stored") && user.getPrimaryGroup().getStoredValue().orElse(NodeFactory.DEFAULT_GROUP_NAME).equalsIgnoreCase(groupName);
        if (shouldPrevent) {
            Message.USER_REMOVEGROUP_ERROR_PRIMARY.send(sender);
            return CommandResult.STATE_ERROR;
        }
    }
    DataMutateResult result = holder.unsetPermission(NodeFactory.buildGroupNode(groupName).withExtraContext(context).build());
    if (result.asBoolean()) {
        Message.UNSET_INHERIT_SUCCESS.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "remove", groupName, context).build().submit(plugin, sender);
        if (holder.getType().isUser()) {
            plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
        }
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.DOES_NOT_INHERIT.send(sender, holder.getFriendlyName(), groupName, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : User(me.lucko.luckperms.common.model.User) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) DataMutateResult(me.lucko.luckperms.api.DataMutateResult)

Example 5 with DataMutateResult

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

the class PermissionSet 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);
    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, node)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    DataMutateResult result = holder.setPermission(NodeFactory.builder(node).setValue(value).withExtraContext(context).build());
    if (result.asBoolean()) {
        Message.SETPERMISSION_SUCCESS.send(sender, node, value, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("permission", "set", node, value, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.ALREADY_HASPERMISSION.send(sender, holder.getFriendlyName(), node, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) 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