Search in sources :

Example 1 with MetaType

use of me.lucko.luckperms.common.node.MetaType in project LuckPerms by lucko.

the class MetaClear 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;
    }
    MetaType type = null;
    if (!args.isEmpty()) {
        String typeId = args.get(0).toLowerCase();
        if (typeId.equals("any") || typeId.equals("all") || typeId.equals("*")) {
            type = MetaType.ANY;
        }
        if (typeId.equals("chat") || typeId.equals("chatmeta")) {
            type = MetaType.CHAT;
        }
        if (typeId.equals(NodeFactory.META_KEY)) {
            type = MetaType.META;
        }
        if (typeId.equals(NodeFactory.PREFIX_KEY) || typeId.equals("prefixes")) {
            type = MetaType.PREFIX;
        }
        if (typeId.equals(NodeFactory.SUFFIX_KEY) || typeId.equals("suffixes")) {
            type = MetaType.SUFFIX;
        }
        if (type != null) {
            args.remove(0);
        }
    }
    if (type == null) {
        type = MetaType.ANY;
    }
    int before = holder.getEnduringNodes().size();
    MutableContextSet context = ArgumentParser.parseContext(0, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (context.isEmpty()) {
        holder.clearMeta(type);
    } else {
        holder.clearMeta(type, context);
    }
    int changed = before - holder.getEnduringNodes().size();
    if (changed == 1) {
        Message.META_CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(context), changed);
    } else {
        Message.META_CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), type.name().toLowerCase(), MessageUtils.contextSetToString(context), changed);
    }
    ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "clear", context).build().submit(plugin, sender);
    StorageAssistant.save(holder, sender, plugin);
    return CommandResult.SUCCESS;
}
Also used : MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) MetaType(me.lucko.luckperms.common.node.MetaType)

Aggregations

MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)1 MetaType (me.lucko.luckperms.common.node.MetaType)1