Search in sources :

Example 1 with JObject

use of me.lucko.luckperms.common.utils.gson.JObject in project LuckPerms by lucko.

the class TreeView method uploadPasteData.

/**
 * Uploads the data contained in this TreeView and returns the id.
 *
 * @param sender the sender
 * @param user the reference user, or null
 * @param checker the permission data instance to check against, or null
 * @return the id, or null
 */
public String uploadPasteData(Sender sender, User user, PermissionCache checker) {
    // only paste if there is actually data here
    if (!hasData()) {
        throw new IllegalStateException();
    }
    // work out the prefix to apply
    // since the view is relative, we need to prepend this to all permissions
    String prefix = this.rootPosition.equals(".") ? "" : (this.rootPosition + ".");
    JsonObject jsonTree = this.view.toJson(prefix);
    JObject metadata = new JObject().add("time", DATE_FORMAT.format(new Date(System.currentTimeMillis()))).add("root", this.rootPosition).add("uploader", new JObject().add("name", sender.getNameWithLocation()).add("uuid", sender.getUuid().toString()));
    JObject checks;
    if (user != null && checker != null) {
        metadata.add("referenceUser", new JObject().add("name", user.getFriendlyName()).add("uuid", user.getUuid().toString()));
        checks = new JObject();
        for (Map.Entry<Integer, String> node : this.view.getNodeEndings()) {
            String permission = prefix + node.getValue();
            checks.add(permission, checker.getPermissionValue(permission).name().toLowerCase());
        }
    } else {
        checks = null;
    }
    JsonObject payload = new JObject().add("metadata", metadata).add("data", new JObject().add("tree", jsonTree).consume(obj -> {
        if (checks != null) {
            obj.add("checkResults", checks);
        }
    })).toJson();
    return StandardPastebin.BYTEBIN.postJson(payload, true).id();
}
Also used : JsonObject(com.google.gson.JsonObject) JObject(me.lucko.luckperms.common.utils.gson.JObject) Map(java.util.Map) Date(java.util.Date)

Example 2 with JObject

use of me.lucko.luckperms.common.utils.gson.JObject 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 3 with JObject

use of me.lucko.luckperms.common.utils.gson.JObject in project LuckPerms by lucko.

the class DebugCommand method serializeMetaData.

private static JObject serializeMetaData(MetaCache metaData) {
    return new JObject().add("prefix", metaData.getPrefix()).add("suffix", metaData.getSuffix()).add("prefixes", () -> {
        JArray prefixes = new JArray();
        for (Map.Entry<Integer, String> entry : metaData.getPrefixes().entrySet()) {
            prefixes.add(new JObject().add("weight", entry.getKey()).add("value", entry.getValue()));
        }
        return prefixes;
    }).add("suffixes", () -> {
        JArray suffixes = new JArray();
        for (Map.Entry<Integer, String> entry : metaData.getSuffixes().entrySet()) {
            suffixes.add(new JObject().add("weight", entry.getKey()).add("value", entry.getValue()));
        }
        return suffixes;
    }).add("meta", () -> {
        JObject metaMap = new JObject();
        for (Map.Entry<String, String> entry : metaData.getMeta().entrySet()) {
            metaMap.add(entry.getKey(), entry.getValue());
        }
        return metaMap;
    }).add("metaMap", () -> {
        JObject metaMultimap = new JObject();
        for (Map.Entry<String, Collection<String>> entry : metaData.getMetaMultimap().asMap().entrySet()) {
            JArray values = new JArray();
            for (String v : entry.getValue()) {
                values.add(v);
            }
            metaMultimap.add(entry.getKey(), values);
        }
        return metaMultimap;
    });
}
Also used : Collection(java.util.Collection) JObject(me.lucko.luckperms.common.utils.gson.JObject) Map(java.util.Map) JArray(me.lucko.luckperms.common.utils.gson.JArray)

Example 4 with JObject

use of me.lucko.luckperms.common.utils.gson.JObject in project LuckPerms by lucko.

the class DebugCommand method getStorageData.

private static JObject getStorageData(LuckPermsPlugin plugin) {
    return new JObject().add("storage", new JObject().add("name", plugin.getStorage().getName()).add("type", plugin.getStorage().getDao().getClass().getName()).add("meta", () -> {
        JObject metaObject = new JObject();
        Map<String, String> meta = plugin.getStorage().getMeta();
        for (Map.Entry<String, String> entry : meta.entrySet()) {
            metaObject.add(entry.getKey(), entry.getValue());
        }
        return metaObject;
    })).add("messaging", () -> {
        JObject messaging = new JObject();
        plugin.getMessagingService().ifPresent(ms -> {
            messaging.add("name", ms.getName());
            messaging.add("implementation", new JObject().add("messenger", ms.getMessenger().getClass().getName()).add("provider", ms.getMessengerProvider().getClass().getName()));
        });
        return messaging;
    });
}
Also used : JObject(me.lucko.luckperms.common.utils.gson.JObject) Map(java.util.Map)

Example 5 with JObject

use of me.lucko.luckperms.common.utils.gson.JObject in project LuckPerms by lucko.

the class DebugCommand method getPlayersData.

private static JObject getPlayersData(LuckPermsPlugin plugin) {
    JObject ret = new JObject();
    Set<UUID> onlinePlayers = plugin.getBootstrap().getOnlinePlayers().collect(Collectors.toSet());
    ret.add("count", onlinePlayers.size());
    JArray playerArray = new JArray();
    for (UUID uuid : onlinePlayers) {
        User user = plugin.getUserManager().getIfLoaded(uuid);
        if (user == null) {
            playerArray.add(new JObject().add("uniqueId", uuid.toString()).add("loaded", false));
            continue;
        }
        playerArray.add(new JObject().add("uniqueId", uuid.toString()).add("loaded", true).add("username", user.getName().orElse("null")).add("primaryGroup", new JObject().add("type", user.getPrimaryGroup().getClass().getName()).add("value", user.getPrimaryGroup().getValue()).add("storedValue", user.getPrimaryGroup().getStoredValue().orElse("null"))).add("activeContext", () -> {
            JObject obj = new JObject();
            Contexts contexts = plugin.getContextForUser(user).orElse(null);
            if (contexts != null) {
                MetaContexts metaContexts = plugin.getContextManager().formMetaContexts(contexts);
                obj.add("data", new JObject().add("permissions", serializePermissionsData(user.getCachedData().getPermissionData(contexts))).add("meta", serializeMetaData(user.getCachedData().getMetaData(metaContexts)))).add("contextSet", ContextSetJsonSerializer.serializeContextSet(contexts.getContexts())).add("settings", serializeContextsSettings(contexts)).add("metaSettings", serializeMetaContextsSettings(metaContexts));
            }
            return obj;
        }));
    }
    ret.add("players", playerArray);
    return ret;
}
Also used : MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) User(me.lucko.luckperms.common.model.User) JObject(me.lucko.luckperms.common.utils.gson.JObject) UUID(java.util.UUID) Contexts(me.lucko.luckperms.api.Contexts) MetaContexts(me.lucko.luckperms.api.caching.MetaContexts) JArray(me.lucko.luckperms.common.utils.gson.JArray)

Aggregations

JObject (me.lucko.luckperms.common.utils.gson.JObject)6 Map (java.util.Map)4 JArray (me.lucko.luckperms.common.utils.gson.JArray)4 JsonObject (com.google.gson.JsonObject)2 Collection (java.util.Collection)2 Date (java.util.Date)2 UUID (java.util.UUID)2 Contexts (me.lucko.luckperms.api.Contexts)2 MetaContexts (me.lucko.luckperms.api.caching.MetaContexts)2 User (me.lucko.luckperms.common.model.User)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 List (java.util.List)1 Set (java.util.Set)1 BiConsumer (java.util.function.BiConsumer)1 Collectors (java.util.stream.Collectors)1 LookupSetting (me.lucko.luckperms.api.LookupSetting)1 ContextCalculator (me.lucko.luckperms.api.context.ContextCalculator)1 StaticContextCalculator (me.lucko.luckperms.api.context.StaticContextCalculator)1 MetaStackDefinition (me.lucko.luckperms.api.metastacking.MetaStackDefinition)1