Search in sources :

Example 1 with JsonArray

use of com.viaversion.viaversion.libs.gson.JsonArray in project ViaBackwards by ViaVersion.

the class ChatItemRewriter method toClient.

public static void toClient(JsonElement element, UserConnection user) {
    if (element instanceof JsonObject) {
        JsonObject obj = (JsonObject) element;
        if (obj.has("hoverEvent")) {
            if (obj.get("hoverEvent") instanceof JsonObject) {
                JsonObject hoverEvent = (JsonObject) obj.get("hoverEvent");
                if (hoverEvent.has("action") && hoverEvent.has("value")) {
                    String type = hoverEvent.get("action").getAsString();
                    if (type.equals("show_item") || type.equals("show_entity")) {
                        JsonElement value = hoverEvent.get("value");
                        if (value.isJsonArray()) {
                            JsonArray newArray = new JsonArray();
                            int index = 0;
                            for (JsonElement valueElement : value.getAsJsonArray()) {
                                if (valueElement.isJsonPrimitive() && valueElement.getAsJsonPrimitive().isString()) {
                                    String newValue = index + ":" + valueElement.getAsString();
                                    newArray.add(new JsonPrimitive(newValue));
                                }
                            }
                            hoverEvent.add("value", newArray);
                        }
                    }
                }
            }
        } else if (obj.has("extra")) {
            toClient(obj.get("extra"), user);
        }
    } else if (element instanceof JsonArray) {
        JsonArray array = (JsonArray) element;
        for (JsonElement value : array) {
            toClient(value, user);
        }
    }
}
Also used : JsonArray(com.viaversion.viaversion.libs.gson.JsonArray) JsonPrimitive(com.viaversion.viaversion.libs.gson.JsonPrimitive) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject)

Example 2 with JsonArray

use of com.viaversion.viaversion.libs.gson.JsonArray in project ViaFabric by ViaVersion.

the class AbstractFabricPlatform method getDump.

@Override
public JsonObject getDump() {
    JsonObject platformSpecific = new JsonObject();
    JsonArray mods = new JsonArray();
    FabricLoader.getInstance().getAllMods().stream().map((mod) -> {
        JsonObject jsonMod = new JsonObject();
        jsonMod.addProperty("id", mod.getMetadata().getId());
        jsonMod.addProperty("name", mod.getMetadata().getName());
        jsonMod.addProperty("version", mod.getMetadata().getVersion().getFriendlyString());
        JsonArray authors = new JsonArray();
        mod.getMetadata().getAuthors().stream().map(it -> {
            JsonObject info = new JsonObject();
            JsonObject contact = new JsonObject();
            it.getContact().asMap().entrySet().forEach(c -> contact.addProperty(c.getKey(), c.getValue()));
            if (contact.size() != 0) {
                info.add("contact", contact);
            }
            info.addProperty("name", it.getName());
            return info;
        }).forEach(authors::add);
        jsonMod.add("authors", authors);
        return jsonMod;
    }).forEach(mods::add);
    platformSpecific.add("mods", mods);
    NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class);
    if (ver != null) {
        platformSpecific.addProperty("native version", ver.getNativeServerVersion());
    }
    return platformSpecific;
}
Also used : JsonArray(com.viaversion.viaversion.libs.gson.JsonArray) FabricLoader(net.fabricmc.loader.api.FabricLoader) ConfigurationProvider(com.viaversion.viaversion.api.configuration.ConfigurationProvider) FabricViaAPI(com.viaversion.fabric.common.platform.FabricViaAPI) CompletableFuture(java.util.concurrent.CompletableFuture) NativeVersionProvider(com.viaversion.fabric.common.platform.NativeVersionProvider) ViaPlatform(com.viaversion.viaversion.api.platform.ViaPlatform) EnvType(net.fabricmc.api.EnvType) Version(net.fabricmc.loader.api.Version) ModContainer(net.fabricmc.loader.api.ModContainer) Path(java.nio.file.Path) ExecutorService(java.util.concurrent.ExecutorService) CancellationException(java.util.concurrent.CancellationException) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) FutureTaskId(com.viaversion.fabric.common.util.FutureTaskId) ViaVersionConfig(com.viaversion.viaversion.api.configuration.ViaVersionConfig) UUID(java.util.UUID) Via(com.viaversion.viaversion.api.Via) EventLoop(io.netty.channel.EventLoop) Logger(java.util.logging.Logger) File(java.io.File) JsonArray(com.viaversion.viaversion.libs.gson.JsonArray) TimeUnit(java.util.concurrent.TimeUnit) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) ModMetadata(net.fabricmc.loader.api.metadata.ModMetadata) JLoggerToLog4j(com.viaversion.fabric.common.util.JLoggerToLog4j) ViaAPI(com.viaversion.viaversion.api.ViaAPI) Future(io.netty.util.concurrent.Future) LogManager(org.apache.logging.log4j.LogManager) FabricViaConfig(com.viaversion.fabric.common.platform.FabricViaConfig) NativeVersionProvider(com.viaversion.fabric.common.platform.NativeVersionProvider) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject)

Aggregations

JsonArray (com.viaversion.viaversion.libs.gson.JsonArray)2 JsonObject (com.viaversion.viaversion.libs.gson.JsonObject)2 FabricViaAPI (com.viaversion.fabric.common.platform.FabricViaAPI)1 FabricViaConfig (com.viaversion.fabric.common.platform.FabricViaConfig)1 NativeVersionProvider (com.viaversion.fabric.common.platform.NativeVersionProvider)1 FutureTaskId (com.viaversion.fabric.common.util.FutureTaskId)1 JLoggerToLog4j (com.viaversion.fabric.common.util.JLoggerToLog4j)1 Via (com.viaversion.viaversion.api.Via)1 ViaAPI (com.viaversion.viaversion.api.ViaAPI)1 ConfigurationProvider (com.viaversion.viaversion.api.configuration.ConfigurationProvider)1 ViaVersionConfig (com.viaversion.viaversion.api.configuration.ViaVersionConfig)1 ViaPlatform (com.viaversion.viaversion.api.platform.ViaPlatform)1 JsonElement (com.viaversion.viaversion.libs.gson.JsonElement)1 JsonPrimitive (com.viaversion.viaversion.libs.gson.JsonPrimitive)1 EventLoop (io.netty.channel.EventLoop)1 Future (io.netty.util.concurrent.Future)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1 File (java.io.File)1 Path (java.nio.file.Path)1 UUID (java.util.UUID)1