Search in sources :

Example 1 with Message

use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.

the class DebugCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    Message.DEBUG_START.send(sender);
    StringBuilder sb = new StringBuilder();
    sb.append("LuckPerms Debug Output\n\n\n");
    BiConsumer<String, JObject> builder = (name, content) -> {
        sb.append("-- ").append(name).append(" --\n");
        sb.append(GSON.toJson(content.toJson()));
        sb.append("\n\n");
    };
    builder.accept("platform.json", getPlatformData(plugin));
    builder.accept("storage.json", getStorageData(plugin));
    builder.accept("context.json", getContextData(plugin));
    builder.accept("players.json", getPlayersData(plugin));
    Pastebin.Paste paste = StandardPastebin.HASTEBIN.postPlain(sb.toString());
    Message.DEBUG_URL.send(sender);
    Component message = TextComponent.builder(paste.url()).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, String.valueOf(paste.url()))).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the debugging data.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : LookupSetting(me.lucko.luckperms.api.LookupSetting) PermissionProcessor(me.lucko.luckperms.common.processors.PermissionProcessor) Contexts(me.lucko.luckperms.api.Contexts) MetaStackElement(me.lucko.luckperms.api.metastacking.MetaStackElement) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) HoverEvent(net.kyori.text.event.HoverEvent) GsonBuilder(com.google.gson.GsonBuilder) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) TextColor(net.kyori.text.format.TextColor) Gson(com.google.gson.Gson) ClickEvent(net.kyori.text.event.ClickEvent) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) BiConsumer(java.util.function.BiConsumer) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) JObject(me.lucko.luckperms.common.utils.gson.JObject) Pastebin(me.lucko.luckperms.common.web.Pastebin) ProxiedContextCalculator(me.lucko.luckperms.common.contexts.ProxiedContextCalculator) Collection(java.util.Collection) PermissionCache(me.lucko.luckperms.common.caching.type.PermissionCache) Set(java.util.Set) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) StaticContextCalculator(me.lucko.luckperms.api.context.StaticContextCalculator) ContextSetJsonSerializer(me.lucko.luckperms.common.contexts.ContextSetJsonSerializer) TextComponent(net.kyori.text.TextComponent) JArray(me.lucko.luckperms.common.utils.gson.JArray) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin) MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) MetaCache(me.lucko.luckperms.common.caching.type.MetaCache) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) Component(net.kyori.text.Component) MetaStackDefinition(me.lucko.luckperms.api.metastacking.MetaStackDefinition) ContextCalculator(me.lucko.luckperms.api.context.ContextCalculator) User(me.lucko.luckperms.common.model.User) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent) JObject(me.lucko.luckperms.common.utils.gson.JObject) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component) Pastebin(me.lucko.luckperms.common.web.Pastebin) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin)

Example 2 with Message

use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.

the class GroupListMembers method sendResult.

private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
    results = new ArrayList<>(results);
    // we need a deterministic sort order
    // even though we're comparing uuids here in some cases - it doesn't matter
    // the import thing is that the order is the same each time the command is executed
    results.sort((o1, o2) -> {
        Comparable h1 = (Comparable) o1.getHolder();
        Comparable h2 = (Comparable) o2.getHolder();
        // noinspection unchecked
        return h1.compareTo(h2);
    });
    int pageIndex = page - 1;
    List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
    if (pageIndex < 0 || pageIndex >= pages.size()) {
        page = 1;
        pageIndex = 0;
    }
    List<HeldPermission<T>> content = pages.get(pageIndex);
    List<Map.Entry<String, HeldPermission<T>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
    // send header
    headerMessage.send(sender, page, pages.size(), results.size());
    for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
        String s = "&3> &b" + ent.getKey() + " " + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
        TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
        sender.sendMessage(message);
    }
}
Also used : TextUtils(me.lucko.luckperms.common.utils.TextUtils) SubCommand(me.lucko.luckperms.common.command.abstraction.SubCommand) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) HoverEvent(net.kyori.text.event.HoverEvent) Function(java.util.function.Function) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) DateUtil(me.lucko.luckperms.common.utils.DateUtil) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ClickEvent(net.kyori.text.event.ClickEvent) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) HolderType(me.lucko.luckperms.common.references.HolderType) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) HeldPermission(me.lucko.luckperms.api.HeldPermission) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) CommandManager(me.lucko.luckperms.common.command.CommandManager) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) Iterators(me.lucko.luckperms.common.utils.Iterators) TextComponent(net.kyori.text.TextComponent) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) BuildableComponent(net.kyori.text.BuildableComponent) Group(me.lucko.luckperms.common.model.Group) Node(me.lucko.luckperms.api.Node) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Predicates(me.lucko.luckperms.common.utils.Predicates) TextComponent(net.kyori.text.TextComponent) HeldPermission(me.lucko.luckperms.api.HeldPermission) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with Message

use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.

the class EditorCommand method execute.

@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
    Type type = Type.ALL;
    // parse type
    String typeString = ArgumentParser.parseStringOrElse(0, args, null);
    if (typeString != null) {
        try {
            type = Type.valueOf(typeString.toUpperCase());
        } catch (IllegalArgumentException e) {
        // ignored
        }
    }
    // collect holders
    List<PermissionHolder> holders = new ArrayList<>();
    if (type.includingGroups) {
        plugin.getGroupManager().getAll().values().stream().sorted((o1, o2) -> {
            int i = Integer.compare(o2.getWeight().orElse(0), o1.getWeight().orElse(0));
            return i != 0 ? i : o1.getName().compareToIgnoreCase(o2.getName());
        }).forEach(holders::add);
    }
    if (type.includingUsers) {
        plugin.getUserManager().getAll().values().stream().sorted((o1, o2) -> o1.getFriendlyName().compareToIgnoreCase(o2.getFriendlyName())).forEach(holders::add);
    }
    // remove holders which the sender doesn't have perms to view
    holders.removeIf(holder -> ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), holder));
    // they don't have perms to view any of them
    if (holders.isEmpty()) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Message.EDITOR_START.send(sender);
    // form the payload data
    JsonObject payload = WebEditor.formPayload(holders, sender, label, plugin);
    // upload the payload data to gist
    String pasteId = StandardPastebin.BYTEBIN.postJson(payload, true).id();
    if (pasteId == null) {
        Message.EDITOR_UPLOAD_FAILURE.send(sender);
        return CommandResult.STATE_ERROR;
    }
    // form a url for the editor
    String url = plugin.getConfiguration().get(ConfigKeys.WEB_EDITOR_URL_PATTERN) + "?" + pasteId;
    Message.EDITOR_URL.send(sender);
    Component message = TextComponent.builder(url).color(TextColor.AQUA).clickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url)).hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to open the editor.").color(TextColor.GRAY))).build();
    sender.sendMessage(message);
    return CommandResult.SUCCESS;
}
Also used : JsonObject(com.google.gson.JsonObject) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) Sender(me.lucko.luckperms.common.sender.Sender) TextComponent(net.kyori.text.TextComponent) HoverEvent(net.kyori.text.event.HoverEvent) ConfigKeys(me.lucko.luckperms.common.config.ConfigKeys) CommandResult(me.lucko.luckperms.common.command.CommandResult) StandardPastebin(me.lucko.luckperms.common.web.StandardPastebin) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) TextColor(net.kyori.text.format.TextColor) List(java.util.List) Component(net.kyori.text.Component) ClickEvent(net.kyori.text.event.ClickEvent) Message(me.lucko.luckperms.common.locale.message.Message) WebEditor(me.lucko.luckperms.common.web.WebEditor) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) ArgumentPermissions(me.lucko.luckperms.common.command.access.ArgumentPermissions) Predicates(me.lucko.luckperms.common.utils.Predicates) HoverEvent(net.kyori.text.event.HoverEvent) ClickEvent(net.kyori.text.event.ClickEvent) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) PermissionHolder(me.lucko.luckperms.common.model.PermissionHolder) TextComponent(net.kyori.text.TextComponent) Component(net.kyori.text.Component)

Example 4 with Message

use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.

the class SearchCommand method sendResult.

private static <T> void sendResult(Sender sender, List<HeldPermission<T>> results, Function<T, String> lookupFunction, Message headerMessage, HolderType holderType, String label, int page) {
    results = new ArrayList<>(results);
    // we need a deterministic sort order
    // even though we're comparing uuids here in some cases - it doesn't matter
    // the import thing is that the order is the same each time the command is executed
    results.sort((o1, o2) -> {
        Comparable h1 = (Comparable) o1.getHolder();
        Comparable h2 = (Comparable) o2.getHolder();
        // noinspection unchecked
        return h1.compareTo(h2);
    });
    int pageIndex = page - 1;
    List<List<HeldPermission<T>>> pages = Iterators.divideIterable(results, 15);
    if (pageIndex < 0 || pageIndex >= pages.size()) {
        page = 1;
        pageIndex = 0;
    }
    List<HeldPermission<T>> content = pages.get(pageIndex);
    List<Map.Entry<String, HeldPermission<T>>> mappedContent = content.stream().map(hp -> Maps.immutableEntry(lookupFunction.apply(hp.getHolder()), hp)).collect(Collectors.toList());
    // send header
    headerMessage.send(sender, page, pages.size(), results.size());
    for (Map.Entry<String, HeldPermission<T>> ent : mappedContent) {
        String s = "&3> &b" + ent.getKey() + " &7- " + (ent.getValue().getValue() ? "&a" : "&c") + ent.getValue().getValue() + getNodeExpiryString(ent.getValue().asNode()) + MessageUtils.getAppendableNodeContextString(ent.getValue().asNode());
        TextComponent message = TextUtils.fromLegacy(s, CommandManager.AMPERSAND_CHAR).toBuilder().applyDeep(makeFancy(ent.getKey(), holderType, label, ent.getValue())).build();
        sender.sendMessage(message);
    }
}
Also used : TextUtils(me.lucko.luckperms.common.utils.TextUtils) LocaleManager(me.lucko.luckperms.common.locale.LocaleManager) SingleCommand(me.lucko.luckperms.common.command.abstraction.SingleCommand) HoverEvent(net.kyori.text.event.HoverEvent) Function(java.util.function.Function) ArgumentParser(me.lucko.luckperms.common.command.utils.ArgumentParser) ArrayList(java.util.ArrayList) DateUtil(me.lucko.luckperms.common.utils.DateUtil) CommandSpec(me.lucko.luckperms.common.locale.command.CommandSpec) ClickEvent(net.kyori.text.event.ClickEvent) Map(java.util.Map) Message(me.lucko.luckperms.common.locale.message.Message) HolderType(me.lucko.luckperms.common.references.HolderType) LuckPermsPlugin(me.lucko.luckperms.common.plugin.LuckPermsPlugin) HeldPermission(me.lucko.luckperms.api.HeldPermission) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) CommandManager(me.lucko.luckperms.common.command.CommandManager) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) MessageUtils(me.lucko.luckperms.common.command.utils.MessageUtils) NodeFactory(me.lucko.luckperms.common.node.NodeFactory) Sender(me.lucko.luckperms.common.sender.Sender) UUID(java.util.UUID) Iterators(me.lucko.luckperms.common.utils.Iterators) TextComponent(net.kyori.text.TextComponent) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) CommandResult(me.lucko.luckperms.common.command.CommandResult) Consumer(java.util.function.Consumer) CommandPermission(me.lucko.luckperms.common.command.access.CommandPermission) List(java.util.List) TabCompletions(me.lucko.luckperms.common.command.utils.TabCompletions) BuildableComponent(net.kyori.text.BuildableComponent) Node(me.lucko.luckperms.api.Node) Predicates(me.lucko.luckperms.common.utils.Predicates) TextComponent(net.kyori.text.TextComponent) HeldPermission(me.lucko.luckperms.api.HeldPermission) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 5 with Message

use of me.lucko.luckperms.common.locale.message.Message in project LuckPerms by lucko.

the class UserInfo method execute.

@SuppressWarnings("unchecked")
@Override
public CommandResult execute(LuckPermsPlugin plugin, Sender sender, User user, List<String> args, String label) {
    if (ArgumentPermissions.checkViewPerms(plugin, sender, getPermission().get(), user)) {
        Message.COMMAND_NO_PERMISSION.send(sender);
        return CommandResult.NO_PERMISSION;
    }
    Message status = plugin.getBootstrap().isPlayerOnline(user.getUuid()) ? Message.PLAYER_ONLINE : Message.PLAYER_OFFLINE;
    Message.USER_INFO_GENERAL.send(sender, user.getName().orElse("Unknown"), user.getUuid(), user.getUuid().version() == 4 ? "&2mojang" : "&8offline", status.asString(plugin.getLocaleManager()), user.getPrimaryGroup().getValue());
    Set<Node> parents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isPermanent).collect(Collectors.toSet());
    Set<Node> tempParents = user.getEnduringData().asSet().stream().filter(Node::isGroupNode).filter(Node::isTemporary).collect(Collectors.toSet());
    if (!parents.isEmpty()) {
        Message.INFO_PARENT_HEADER.send(sender);
        for (Node node : parents) {
            Message.EMPTY.send(sender, "&f-    &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
        }
    }
    if (!tempParents.isEmpty()) {
        Message.INFO_TEMP_PARENT_HEADER.send(sender);
        for (Node node : tempParents) {
            Message.EMPTY.send(sender, "&f-    &3> &f" + node.getGroupName() + MessageUtils.getAppendableNodeContextString(node));
            Message.EMPTY.send(sender, "&f-    &2-    expires in " + DateUtil.formatDateDiff(node.getExpiryUnixTime()));
        }
    }
    String context = "&bNone";
    String prefix = "&bNone";
    String suffix = "&bNone";
    String meta = "&bNone";
    Contexts contexts = plugin.getContextForUser(user).orElse(null);
    if (contexts != null) {
        ContextSet contextSet = contexts.getContexts();
        if (!contextSet.isEmpty()) {
            context = contextSet.toSet().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
        }
        MetaData data = user.getCachedData().getMetaData(contexts);
        if (data.getPrefix() != null) {
            prefix = "&f\"" + data.getPrefix() + "&f\"";
        }
        if (data.getSuffix() != null) {
            suffix = "&f\"" + data.getSuffix() + "&f\"";
        }
        ListMultimap<String, String> metaMap = data.getMetaMultimap();
        if (!metaMap.isEmpty()) {
            meta = metaMap.entries().stream().map(e -> MessageUtils.contextToString(e.getKey(), e.getValue())).collect(Collectors.joining(" "));
        }
    }
    Message.USER_INFO_DATA.send(sender, MessageUtils.formatBoolean(contexts != null), context, prefix, suffix, meta);
    return CommandResult.SUCCESS;
}
Also used : ContextSet(me.lucko.luckperms.api.context.ContextSet) Message(me.lucko.luckperms.common.locale.message.Message) MetaData(me.lucko.luckperms.api.caching.MetaData) Node(me.lucko.luckperms.api.Node) Contexts(me.lucko.luckperms.api.Contexts)

Aggregations

Message (me.lucko.luckperms.common.locale.message.Message)7 List (java.util.List)5 CommandSpec (me.lucko.luckperms.common.locale.command.CommandSpec)5 Sender (me.lucko.luckperms.common.sender.Sender)5 TextComponent (net.kyori.text.TextComponent)5 HoverEvent (net.kyori.text.event.HoverEvent)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 CommandResult (me.lucko.luckperms.common.command.CommandResult)4 CommandPermission (me.lucko.luckperms.common.command.access.CommandPermission)4 LocaleManager (me.lucko.luckperms.common.locale.LocaleManager)4 LuckPermsPlugin (me.lucko.luckperms.common.plugin.LuckPermsPlugin)4 Predicates (me.lucko.luckperms.common.utils.Predicates)4 ClickEvent (net.kyori.text.event.ClickEvent)4 UUID (java.util.UUID)3 Consumer (java.util.function.Consumer)3 Collectors (java.util.stream.Collectors)3 Node (me.lucko.luckperms.api.Node)3 CommandManager (me.lucko.luckperms.common.command.CommandManager)3 SingleCommand (me.lucko.luckperms.common.command.abstraction.SingleCommand)3