Search in sources :

Example 6 with DataMutateResult

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

the class PermissionUnset 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);
    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, node)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    DataMutateResult result = holder.unsetPermission(NodeFactory.builder(node).withExtraContext(context).build());
    if (result.asBoolean()) {
        Message.UNSETPERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("permission", "unset", node, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.DOES_NOT_HAVE_PERMISSION.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)

Example 7 with DataMutateResult

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

the class PermissionUnsetTemp 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);
    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, node)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    DataMutateResult result = holder.unsetPermission(NodeFactory.builder(node).setExpiry(10L).withExtraContext(context).build());
    if (result.asBoolean()) {
        Message.UNSET_TEMP_PERMISSION_SUCCESS.send(sender, node, holder.getFriendlyName(), MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("permission", "unsettemp", node, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.DOES_NOT_HAVE_TEMP_PERMISSION.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)

Example 8 with DataMutateResult

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

the class MetaRemoveChatMeta 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.isTemporary() && n.getFullContexts().makeImmutable().equals(context.makeImmutable()));
        Message.BULK_REMOVE_CHATMETA_SUCCESS.send(sender, holder.getFriendlyName(), this.type.name().toLowerCase(), priority, MessageUtils.contextSetToString(context));
        ExtendedLogEntry.build().actor(sender).acted(holder).action("meta", "remove" + 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).withExtraContext(context).build());
    if (result.asBoolean()) {
        TextComponent.Builder builder = TextUtils.fromLegacy(Message.REMOVE_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", "remove" + this.type.name().toLowerCase(), priority, meta, context).build().submit(plugin, sender);
        StorageAssistant.save(holder, sender, plugin);
        return CommandResult.SUCCESS;
    } else {
        Message.DOES_NOT_HAVE_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 9 with DataMutateResult

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

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

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