Java Code Examples for net.luckperms.api.context.ImmutableContextSet#isEmpty()

The following examples show how to use net.luckperms.api.context.ImmutableContextSet#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParentClear.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
    ImmutableContextSet contextSet = args.getContextOrEmpty(0);
    if (contextSet.isEmpty()) {
        subjectData.clearParents();
        Message.BLANK.send(sender, "&aCleared parents matching contexts &bANY&a.");
    } else {
        subjectData.clearParents(contextSet);
        Message.BLANK.send(sender, "&aCleared parents matching contexts &b" + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
    }
    return CommandResult.SUCCESS;
}
 
Example 2
Source File: OptionClear.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
    ImmutableContextSet contextSet = args.getContextOrEmpty(0);
    if (contextSet.isEmpty()) {
        subjectData.clearOptions();
        Message.BLANK.send(sender, "&aCleared options matching contexts &bANY&a.");
    } else {
        subjectData.clearOptions(contextSet);
        Message.BLANK.send(sender, "&aCleared options matching contexts &b" + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
    }
    return CommandResult.SUCCESS;
}
 
Example 3
Source File: PermissionClear.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, LPSubjectData subjectData, ArgumentList args, String label) {
    ImmutableContextSet contextSet = args.getContextOrEmpty(0);
    if (contextSet.isEmpty()) {
        subjectData.clearPermissions();
        Message.BLANK.send(sender, "&aCleared permissions matching contexts &bANY&a.");
    } else {
        subjectData.clearPermissions(contextSet);
        Message.BLANK.send(sender, "&aCleared permissions matching contexts &b" + SpongeCommandUtils.contextToString(contextSet, plugin.getLocaleManager()));
    }
    return CommandResult.SUCCESS;
}
 
Example 4
Source File: Sender.java    From LuckPerms with MIT License 5 votes vote down vote up
/**
 * Gets a string representing the senders username, and their current location
 * within the network.
 *
 * @return a friendly identifier for the sender
 */
default String getNameWithLocation() {
    String name = getName();

    ContextManager<?, ?> contextManager = getPlugin().getContextManager();
    if (contextManager == null) {
        return name;
    }

    ImmutableContextSet staticContext = contextManager.getStaticContext();

    String location;
    if (staticContext.isEmpty()) {
        return name;
    } else if (staticContext.size() == 1) {
        location = staticContext.iterator().next().getValue();
    } else {
        Set<String> servers = staticContext.getValues(DefaultContextKeys.SERVER_KEY);
        if (servers.size() == 1) {
            location = servers.iterator().next();
        } else {
            location = staticContext.toSet().stream().map(pair -> pair.getKey() + "=" + pair.getValue()).collect(Collectors.joining(";"));
        }
    }

    return name + "@" + location;
}