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();
}
Aggregations