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