Search in sources :

Example 26 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class CheckCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    String target = args.get(0);
    String permission = args.get(1);
    User user;
    UUID u = Uuids.parseNullable(target);
    if (u != null) {
        user = plugin.getUserManager().getIfLoaded(u);
    } else {
        user = plugin.getUserManager().getByUsername(target);
    }
    if (user == null) {
        Message.USER_NOT_ONLINE.send(sender, target);
        return CommandResult.STATE_ERROR;
    }
    Tristate tristate = user.getCachedData().getPermissionData(plugin.getContextForUser(user).orElse(plugin.getContextManager().getStaticContexts())).getPermissionValue(permission, CheckOrigin.INTERNAL);
    Message.CHECK_RESULT.send(sender, user.getFriendlyName(), permission, MessageUtils.formatTristate(tristate));
    return CommandResult.SUCCESS;
}
Also used : User(me.lucko.luckperms.common.model.User) Tristate(me.lucko.luckperms.api.Tristate) UUID(java.util.UUID)

Example 27 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class LogNotify method setIgnoring.

private static void setIgnoring(LuckPermsPlugin plugin, UUID uuid, boolean state) {
    User user = plugin.getUserManager().getIfLoaded(uuid);
    if (user == null) {
        return;
    }
    if (state) {
        // add the perm
        user.setPermission(NodeFactory.make("luckperms.log.notify.ignoring"));
    } else {
        // remove the perm
        user.removeIf(n -> n.getPermission().equalsIgnoreCase("luckperms.log.notify.ignoring"));
    }
    plugin.getStorage().noBuffer().saveUser(user).join();
}
Also used : User(me.lucko.luckperms.common.model.User)

Example 28 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class StorageAssistant method save.

public static void save(PermissionHolder holder, Sender sender, LuckPermsPlugin plugin) {
    if (holder.getType().isUser()) {
        User user = ((User) holder);
        save(user, sender, plugin);
    } else if (holder.getType().isGroup()) {
        Group group = ((Group) holder);
        save(group, sender, plugin);
    } else {
        throw new IllegalArgumentException();
    }
}
Also used : Group(me.lucko.luckperms.common.model.Group) User(me.lucko.luckperms.common.model.User)

Example 29 with User

use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.

the class ParentClearTrack 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;
    }
    final String trackName = args.get(0).toLowerCase();
    if (!DataConstraints.TRACK_NAME_TEST.test(trackName)) {
        Message.TRACK_INVALID_ENTRY.send(sender, trackName);
        return CommandResult.INVALID_ARGS;
    }
    Track track = StorageAssistant.loadTrack(trackName, sender, plugin);
    if (track == null) {
        return CommandResult.LOADING_ERROR;
    }
    if (track.getSize() <= 1) {
        Message.TRACK_EMPTY.send(sender, track.getName());
        return CommandResult.STATE_ERROR;
    }
    int before = holder.getEnduringNodes().size();
    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, track.getName())) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    if (context.isEmpty()) {
        holder.removeIf(node -> node.isGroupNode() && track.containsGroup(node.getGroupName()));
    } else {
        holder.removeIf(node -> node.isGroupNode() && node.getFullContexts().equals(context) && track.containsGroup(node.getGroupName()));
    }
    if (holder.getType().isUser()) {
        plugin.getUserManager().giveDefaultIfNeeded(((User) holder), false);
    }
    int changed = before - holder.getEnduringNodes().size();
    if (changed == 1) {
        Message.PARENT_CLEAR_TRACK_SUCCESS_SINGULAR.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(context), changed);
    } else {
        Message.PARENT_CLEAR_TRACK_SUCCESS.send(sender, holder.getFriendlyName(), track.getName(), MessageUtils.contextSetToString(context), changed);
    }
    ExtendedLogEntry.build().actor(sender).acted(holder).action("parent", "cleartrack", track.getName(), context).build().submit(plugin, sender);
    StorageAssistant.save(holder, sender, plugin);
    return CommandResult.SUCCESS;
}
Also used : User(me.lucko.luckperms.common.model.User) MutableContextSet(me.lucko.luckperms.api.context.MutableContextSet) Track(me.lucko.luckperms.common.model.Track)

Example 30 with User

use of me.lucko.luckperms.common.model.User 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)

Aggregations

User (me.lucko.luckperms.common.model.User)67 Group (me.lucko.luckperms.common.model.Group)20 UUID (java.util.UUID)16 Node (me.lucko.luckperms.api.Node)14 Contexts (me.lucko.luckperms.api.Contexts)10 List (java.util.List)9 NodeFactory (me.lucko.luckperms.common.node.NodeFactory)9 Tristate (me.lucko.luckperms.api.Tristate)8 Track (me.lucko.luckperms.common.model.Track)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)7 ProgressLogger (me.lucko.luckperms.common.logging.ProgressLogger)7 Sender (me.lucko.luckperms.common.sender.Sender)7 Map (java.util.Map)6 Set (java.util.Set)6 Collectors (java.util.stream.Collectors)6 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)6 MutableContextSet (me.lucko.luckperms.api.context.MutableContextSet)5 CommandResult (me.lucko.luckperms.common.command.CommandResult)5 SubCommand (me.lucko.luckperms.common.command.abstraction.SubCommand)5