Search in sources :

Example 6 with JObject

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

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