Search in sources :

Example 16 with MutableContextSet

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

the class MetaRemoveTempChatMeta 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.parseStringOrElse(1, args, "null");
    MutableContextSet context = ArgumentParser.parseContext(2, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    // Handle bulk removal
    if (meta.equalsIgnoreCase("null") || meta.equals("*")) {
        holder.removeIf(n -> this.type.matches(n) && this.type.getEntry(n).getKey() == priority && !n.isPermanent() && n.getFullContexts().makeImmutable().equals(context.makeImmutable()));
        Message.BULK_REMOVE_TEMP_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "removetemp" + this.type.name().toLowerCase(), priority, "*", context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    }
    DataMutateResult result = holder.unsetPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).setExpiry(10L).withExtraContext(context).build());
    if (result.asBoolean()) {
        TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_TEMP_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, 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", "removetemp" + this.type.name().toLowerCase(), priority, meta, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.DOES_NOT_HAVE_TEMP_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) DataMutateResult(me.lucko.luckperms.api.DataMutateResult)

Example 17 with MutableContextSet

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

the class MetaUnset 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, false)) {
        Message.UNSET_META_SUCCESS.send(sender, key, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "unset", key, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.DOESNT_HAVE_META.send(sender, holder.getFriendlyName(), key, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet)

Example 18 with MutableContextSet

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

the class HolderClear method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, T holder, List<String> args, String label) throws CommandException {
    if (ArgumentPermissions.checkModifyPerms(plugin, sender, getPermission().get(), holder)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    int before = holder.getEnduringNodes().size();
    MutableContextSet context = ArgumentParser.parseContext(0, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, getPermission().get(), context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (context.isEmpty()) {
        holder.clearNodes();
    } else {
        holder.clearNodes(context);
    }
    int changed = before - holder.getEnduringNodes().size();
    if (changed == 1) {
        Message.CLEAR_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
    } else {
        Message.CLEAR_SUCCESS.send(sender, holder.getFriendlyName(), MessageUtils.contextSetToString(context), changed);
    }
    ExtendedLogEntry.build().actor(sender).acted(holder).action("clear", context).build().submit(plugin, sender);
    StorageAssistant.save(holder, sender, plugin);
    return CommandResult.SUCCESS;
}
Also used : MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet)

Example 19 with MutableContextSet

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

the class MetaAddChatMeta 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);
    MutableContextSet context = ArgumentParser.parseContext(2, args, plugin);
    if (ArgumentPermissions.checkContext(plugin, sender, permission, context)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    DataMutateResult result = holder.setPermission(NodeFactory.buildChatMetaNode(this.type, priority, meta).withExtraContext(context).build());
    if (result.asBoolean()) {
        TextComponent.Builder builder = TextUtils.fromLegacy(Message.ADD_CHATMETA_SUCCESS.asString(plugin.getLocaleManager(), holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, 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", "add" + this.type.name().toLowerCase(), priority, meta, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.ALREADY_HAS_CHAT_META.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), meta, priority, MessageUtils.contextSetToString(context));
        return CommandResult.STATE_ERROR;
    }
}
Also used : TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) DataMutateResult(me.lucko.luckperms.api.DataMutateResult)

Example 20 with MutableContextSet

use of me.lucko.luckperms.api.context.MutableContextSet 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)

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