Search in sources :

Example 1 with JArray

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

use of me.lucko.luckperms.common.utils.gson.JArray 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)

Example 3 with JArray

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

the class VerboseListener method uploadPasteData.

/**
 * Uploads the captured data in this listener to a paste and returns the url
 *
 * @return the url
 */
public String uploadPasteData() {
    // retrieve variables
    long now = System.currentTimeMillis();
    String startDate = DATE_FORMAT.format(new Date(this.startTime));
    String endDate = DATE_FORMAT.format(new Date(now));
    long secondsTaken = (now - this.startTime) / 1000L;
    String duration = DateUtil.formatTimeShort(secondsTaken);
    String filter;
    if (this.filter.isBlank()) {
        filter = "any";
    } else {
        filter = this.filter.toString();
    }
    boolean truncated = this.matchedCounter.get() > this.results.size();
    JObject metadata = new JObject().add("startTime", startDate).add("endTime", endDate).add("duration", duration).add("count", new JObject().add("matched", this.matchedCounter.get()).add("total", this.counter.get())).add("uploader", new JObject().add("name", this.notifiedSender.getNameWithLocation()).add("uuid", this.notifiedSender.getUuid().toString())).add("filter", filter).add("truncated", truncated);
    JArray data = new JArray();
    for (CheckData c : this.results) {
        if (c.getCheckOrigin() == CheckOrigin.API || c.getCheckOrigin() == CheckOrigin.INTERNAL) {
            data.add(c.toJson(WEB_UNFILTERED_PRINTER));
        } else {
            data.add(c.toJson(WEB_FILTERED_PRINTER));
        }
    }
    this.results.clear();
    JsonObject payload = new JObject().add("metadata", metadata).add("data", data).toJson();
    return StandardPastebin.BYTEBIN.postJson(payload, true).id();
}
Also used : JsonObject(com.google.gson.JsonObject) JObject(me.lucko.luckperms.common.utils.gson.JObject) Date(java.util.Date) JArray(me.lucko.luckperms.common.utils.gson.JArray)

Aggregations

JArray (me.lucko.luckperms.common.utils.gson.JArray)3 JObject (me.lucko.luckperms.common.utils.gson.JObject)3 JsonObject (com.google.gson.JsonObject)1 Collection (java.util.Collection)1 Date (java.util.Date)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Contexts (me.lucko.luckperms.api.Contexts)1 MetaContexts (me.lucko.luckperms.api.caching.MetaContexts)1 User (me.lucko.luckperms.common.model.User)1