Search in sources :

Example 1 with LPSubjectCollection

use of me.lucko.luckperms.sponge.service.model.LPSubjectCollection in project LuckPerms by lucko.

the class SpongeMainCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, Void v, List<String> args, String label) {
    LuckPermsService service = this.plugin.getService();
    if (args.size() < 1) {
        MessageUtils.sendPluginMessage(sender, "&aCurrent Subject Collections:\n" + MessageUtils.toCommaSep(service.getLoadedCollections().keySet().stream().filter(s -> !s.equalsIgnoreCase("user") && !s.equalsIgnoreCase("group")).sorted().collect(Collectors.toList())));
        return CommandResult.SUCCESS;
    }
    String subjectCollection = args.get(0);
    if (subjectCollection.equalsIgnoreCase("user") || subjectCollection.equalsIgnoreCase("group")) {
        MessageUtils.sendPluginMessage(sender, "Please use the main LuckPerms commands to edit users and groups.");
        return CommandResult.STATE_ERROR;
    }
    if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(subjectCollection))) {
        MessageUtils.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + subjectCollection + "&c' doesn't already exist. Creating it now.");
    }
    LPSubjectCollection collection = service.getCollection(subjectCollection);
    if (args.size() < 2) {
        List<String> subjects = collection.getLoadedSubjects().stream().map(LPSubject::getIdentifier).collect(Collectors.toList());
        if (subjects.size() > 50) {
            List<String> extra = subjects.subList(50, subjects.size());
            int overflow = extra.size();
            extra.clear();
            MessageUtils.sendPluginMessage(sender, "&aCurrent Subjects:\n" + MessageUtils.toCommaSep(subjects) + "&b ... and &a" + overflow + " &bmore.");
        } else {
            MessageUtils.sendPluginMessage(sender, "&aCurrent Subjects:\n" + MessageUtils.toCommaSep(subjects));
        }
        return CommandResult.SUCCESS;
    }
    if (args.size() < 4) {
        sendDetailedUsage(sender, label);
        return CommandResult.SUCCESS;
    }
    boolean persistent = true;
    if (args.get(2).toLowerCase().startsWith("-t")) {
        persistent = false;
        args.remove(2);
    }
    String type = args.get(2).toLowerCase();
    if (!type.equals("permission") && !type.equals("parent") && !type.equals("option")) {
        sendDetailedUsage(sender, label);
        return CommandResult.INVALID_ARGS;
    }
    String cmd = args.get(3);
    Optional<Command<LPSubjectData, ?>> o = this.subCommands.get(type).stream().filter(s -> s.getName().equalsIgnoreCase(cmd)).findAny();
    if (!o.isPresent()) {
        sendDetailedUsage(sender, label);
        return CommandResult.INVALID_ARGS;
    }
    final Command<LPSubjectData, ?> sub = o.get();
    if (!sub.isAuthorized(sender)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    List<String> strippedArgs = new ArrayList<>();
    if (args.size() > 4) {
        strippedArgs.addAll(args.subList(4, args.size()));
    }
    if (sub.getArgumentCheck().test(strippedArgs.size())) {
        sub.sendDetailedUsage(sender, label);
        return CommandResult.INVALID_ARGS;
    }
    String subjectId = args.get(1);
    if (!collection.hasRegistered(subjectId).join()) {
        MessageUtils.sendPluginMessage(sender, "Warning: Subject '&4" + subjectId + "&c' doesn't already exist. Creating it now.");
    }
    LPSubject subject = collection.loadSubject(subjectId).join();
    LPSubjectData subjectData = persistent ? subject.getSubjectData() : subject.getTransientSubjectData();
    CommandResult result;
    try {
        result = sub.execute(plugin, sender, subjectData, strippedArgs, label);
    } catch (CommandException e) {
        result = CommandManager.handleException(e, sender, label, sub);
    }
    return result;
}
Also used : CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) Arrays(java.util.Arrays) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) Command(me.lucko.luckperms.common.command.abstraction.Command) ArrayList(java.util.ArrayList) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) Nonnull(javax.annotation.Nonnull) CommandManager(me.lucko.luckperms.common.command.CommandManager) ImmutableMap(com.google.common.collect.ImmutableMap) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) Sender(me.lucko.luckperms.common.sender.Sender) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) ImmutableCollectors(me.lucko.luckperms.common.utils.ImmutableCollectors) List(java.util.List) Optional(java.util.Optional) LPSpongePlugin(me.lucko.luckperms.sponge.LPSpongePlugin) Predicates(me.lucko.luckperms.common.utils.Predicates) LPSubjectData(me.lucko.luckperms.sponge.service.model.LPSubjectData) ArrayList(java.util.ArrayList) CommandException(me.lucko.luckperms.common.command.abstraction.CommandException) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection) CommandResult(me.lucko.luckperms.common.command.CommandResult) LuckPermsService(me.lucko.luckperms.sponge.service.LuckPermsService) Command(me.lucko.luckperms.common.command.abstraction.Command) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject)

Example 2 with LPSubjectCollection

use of me.lucko.luckperms.sponge.service.model.LPSubjectCollection in project LuckPerms by lucko.

the class ParentAdd method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
    String collection = args.get(0);
    String name = args.get(1);
    ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
    LPPermissionService service = Sponge.getServiceManager().provideUnchecked(LPPermissionService.class);
    if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
        MessageUtils.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't already exist.");
    }
    LPSubjectCollection c = service.getCollection(collection);
    if (!c.hasRegistered(name).join()) {
        MessageUtils.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't already exist.");
    }
    LPSubject subject = c.loadSubject(name).join();
    if (subjectData.addParent(contextSet, subject.toReference()).join()) {
        MessageUtils.sendPluginMessage(sender, "&aAdded parent &b" + subject.getParentCollection().getIdentifier() + "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
    } else {
        MessageUtils.sendPluginMessage(sender, "Unable to add parent. Does the Subject already have it added?");
    }
    return CommandResult.SUCCESS;
}
Also used : LPPermissionService(me.lucko.luckperms.sponge.service.model.LPPermissionService) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection)

Example 3 with LPSubjectCollection

use of me.lucko.luckperms.sponge.service.model.LPSubjectCollection in project LuckPerms by lucko.

the class DescriptionBuilder method register.

@Nonnull
@Override
public PermissionDescription register() throws IllegalStateException {
    if (this.id == null) {
        throw new IllegalStateException("id cannot be null");
    }
    LPPermissionDescription description = this.service.registerPermissionDescription(this.id, this.description, this.container);
    // Set role-templates
    LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
    for (Map.Entry<String, Tristate> assignment : this.roles.entrySet()) {
        LPSubject roleSubject = subjects.loadSubject(assignment.getKey()).join();
        roleSubject.getTransientSubjectData().setPermission(ContextSet.empty(), this.id, assignment.getValue());
    }
    this.service.getPlugin().getPermissionVault().offer(this.id);
    // null stuff so this instance can be reused
    this.roles.clear();
    this.id = null;
    this.description = null;
    return description.sponge();
}
Also used : Tristate(me.lucko.luckperms.api.Tristate) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection) HashMap(java.util.HashMap) Map(java.util.Map) LPPermissionDescription(me.lucko.luckperms.sponge.service.model.LPPermissionDescription) Nonnull(javax.annotation.Nonnull)

Example 4 with LPSubjectCollection

use of me.lucko.luckperms.sponge.service.model.LPSubjectCollection in project LuckPerms by lucko.

the class DescriptionBuilder method register.

@Nonnull
@Override
public PermissionDescription register() throws IllegalStateException {
    if (this.id == null) {
        throw new IllegalStateException("id cannot be null");
    }
    LPPermissionDescription description = this.service.registerPermissionDescription(this.id, this.description, this.container);
    // Set role-templates
    LPSubjectCollection subjects = this.service.getCollection(PermissionService.SUBJECTS_ROLE_TEMPLATE);
    for (Map.Entry<String, Tristate> assignment : this.roles.entrySet()) {
        LPSubject roleSubject = subjects.loadSubject(assignment.getKey()).join();
        roleSubject.getTransientSubjectData().setPermission(ContextSet.empty(), this.id, assignment.getValue());
    }
    this.service.getPlugin().getPermissionVault().offer(this.id);
    // null stuff so this instance can be reused
    this.roles.clear();
    this.id = null;
    this.description = null;
    return description.sponge();
}
Also used : Tristate(me.lucko.luckperms.api.Tristate) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection) HashMap(java.util.HashMap) Map(java.util.Map) LPPermissionDescription(me.lucko.luckperms.sponge.service.model.LPPermissionDescription) Nonnull(javax.annotation.Nonnull)

Example 5 with LPSubjectCollection

use of me.lucko.luckperms.sponge.service.model.LPSubjectCollection in project LuckPerms by lucko.

the class ParentRemove method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, List<String> args, String label) {
    String collection = args.get(0);
    String name = args.get(1);
    ImmutableContextSet contextSet = ArgumentParser.parseContextSponge(2, args);
    LPPermissionService service = Sponge.getServiceManager().provideUnchecked(LPPermissionService.class);
    if (service.getLoadedCollections().keySet().stream().map(String::toLowerCase).noneMatch(s -> s.equalsIgnoreCase(collection))) {
        MessageUtils.sendPluginMessage(sender, "Warning: SubjectCollection '&4" + collection + "&c' doesn't exist.");
    }
    LPSubjectCollection c = service.getCollection(collection);
    if (!c.hasRegistered(name).join()) {
        MessageUtils.sendPluginMessage(sender, "Warning: Subject '&4" + name + "&c' doesn't exist.");
    }
    LPSubject subject = c.loadSubject(name).join();
    if (subjectData.removeParent(contextSet, subject.toReference()).join()) {
        MessageUtils.sendPluginMessage(sender, "&aRemoved parent &b" + subject.getParentCollection().getIdentifier() + "&a/&b" + subject.getIdentifier() + "&a in context " + SpongeCommandUtils.contextToString(contextSet));
    } else {
        MessageUtils.sendPluginMessage(sender, "Unable to remove parent. Are you sure the Subject has it added?");
    }
    return CommandResult.SUCCESS;
}
Also used : LPPermissionService(me.lucko.luckperms.sponge.service.model.LPPermissionService) LPSubject(me.lucko.luckperms.sponge.service.model.LPSubject) ImmutableContextSet(me.lucko.luckperms.api.context.ImmutableContextSet) LPSubjectCollection(me.lucko.luckperms.sponge.service.model.LPSubjectCollection)

Aggregations

LPSubject (me.lucko.luckperms.sponge.service.model.LPSubject)5 LPSubjectCollection (me.lucko.luckperms.sponge.service.model.LPSubjectCollection)5 Map (java.util.Map)3 Nonnull (javax.annotation.Nonnull)3 HashMap (java.util.HashMap)2 Tristate (me.lucko.luckperms.api.Tristate)2 ImmutableContextSet (me.lucko.luckperms.api.context.ImmutableContextSet)2 LPPermissionDescription (me.lucko.luckperms.sponge.service.model.LPPermissionDescription)2 LPPermissionService (me.lucko.luckperms.sponge.service.model.LPPermissionService)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 CommandManager (me.lucko.luckperms.common.command.CommandManager)1 CommandResult (me.lucko.luckperms.common.command.CommandResult)1 Command (me.lucko.luckperms.common.command.abstraction.Command)1 CommandException (me.lucko.luckperms.common.command.abstraction.CommandException)1