Search in sources :

Example 6 with JsonObject

use of com.viaversion.viaversion.libs.gson.JsonObject 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)

Example 7 with JsonObject

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

the class BackwardsMappings method loadExtras.

@Override
protected void loadExtras(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings) {
    if (diffMappings != null) {
        JsonObject diffItems = diffMappings.getAsJsonObject("items");
        if (diffItems != null) {
            backwardsItemMappings = VBMappingDataLoader.loadItemMappings(oldMappings.getAsJsonObject("items"), newMappings.getAsJsonObject("items"), diffItems, shouldWarnOnMissing("items"));
        }
        JsonObject diffSounds = diffMappings.getAsJsonObject("sounds");
        if (diffSounds != null) {
            backwardsSoundMappings = VBMappingDataLoader.objectToNamespacedMap(diffSounds);
        }
        JsonObject diffEntityNames = diffMappings.getAsJsonObject("entitynames");
        if (diffEntityNames != null) {
            entityNames = VBMappingDataLoader.objectToMap(diffEntityNames);
        }
    }
    // Just re-use ViaVersion's item id map
    if (vvProtocolClass != null) {
        itemMappings = Via.getManager().getProtocolManager().getProtocol(vvProtocolClass).getMappingData().getItemMappings().inverse();
    }
    loadVBExtras(oldMappings, newMappings);
}
Also used : JsonObject(com.viaversion.viaversion.libs.gson.JsonObject)

Example 8 with JsonObject

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

the class VBMappingDataLoader method loadItemMappings.

public static Int2ObjectMap<MappedItem> loadItemMappings(JsonObject oldMapping, JsonObject newMapping, JsonObject diffMapping, boolean warnOnMissing) {
    Int2ObjectMap<MappedItem> itemMapping = new Int2ObjectOpenHashMap<>(diffMapping.size(), 0.99F);
    Object2IntMap<String> newIdenfierMap = MappingDataLoader.indexedObjectToMap(newMapping);
    Object2IntMap<String> oldIdenfierMap = MappingDataLoader.indexedObjectToMap(oldMapping);
    for (Map.Entry<String, JsonElement> entry : diffMapping.entrySet()) {
        JsonObject object = entry.getValue().getAsJsonObject();
        String mappedIdName = object.getAsJsonPrimitive("id").getAsString();
        int mappedId = newIdenfierMap.getInt(mappedIdName);
        if (mappedId == -1) {
            if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
                ViaBackwards.getPlatform().getLogger().warning("No key for " + mappedIdName + " :( ");
            }
            continue;
        }
        int oldId = oldIdenfierMap.getInt(entry.getKey());
        if (oldId == -1) {
            if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
                ViaBackwards.getPlatform().getLogger().warning("No old entry for " + mappedIdName + " :( ");
            }
            continue;
        }
        String name = object.getAsJsonPrimitive("name").getAsString();
        itemMapping.put(oldId, new MappedItem(mappedId, name));
    }
    // Look for missing keys
    if (warnOnMissing && !Via.getConfig().isSuppressConversionWarnings()) {
        for (Object2IntMap.Entry<String> entry : oldIdenfierMap.object2IntEntrySet()) {
            if (!newIdenfierMap.containsKey(entry.getKey()) && !itemMapping.containsKey(entry.getIntValue())) {
                ViaBackwards.getPlatform().getLogger().warning("No item mapping for " + entry.getKey() + " :( ");
            }
        }
    }
    return itemMapping;
}
Also used : Int2ObjectOpenHashMap(com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) Object2IntMap(com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) Object2IntMap(com.viaversion.viaversion.libs.fastutil.objects.Object2IntMap) HashMap(java.util.HashMap) Int2ObjectMap(com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectMap) Map(java.util.Map) Int2ObjectOpenHashMap(com.viaversion.viaversion.libs.fastutil.ints.Int2ObjectOpenHashMap)

Example 9 with JsonObject

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

the class PlayerPackets1_11 method register.

public void register(Protocol1_10To1_11 protocol) {
    protocol.registerClientbound(ClientboundPackets1_9_3.TITLE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Action
            map(Type.VAR_INT);
            handler(wrapper -> {
                int action = wrapper.get(Type.VAR_INT, 0);
                if (action == 2) {
                    // Handle the new ActionBar
                    JsonElement message = wrapper.read(Type.COMPONENT);
                    wrapper.clearPacket();
                    wrapper.setId(ClientboundPackets1_9_3.CHAT_MESSAGE.ordinal());
                    // https://bugs.mojang.com/browse/MC-119145to
                    String legacy = LegacyComponentSerializer.legacySection().serialize(GsonComponentSerializer.gson().deserialize(message.toString()));
                    message = new JsonObject();
                    message.getAsJsonObject().addProperty("text", legacy);
                    wrapper.write(Type.COMPONENT, message);
                    wrapper.write(Type.BYTE, (byte) 2);
                } else if (action > 2) {
                    // Move everything one position down
                    wrapper.set(Type.VAR_INT, 0, action - 1);
                }
            });
        }
    });
    protocol.registerClientbound(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Collected entity id
            map(Type.VAR_INT);
            // 1 - Collector entity id
            map(Type.VAR_INT);
            // Ignore item pickup count
            handler(wrapper -> wrapper.read(Type.VAR_INT));
        }
    });
    protocol.registerServerbound(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {

        @Override
        public void registerMap() {
            // 0 - Location
            map(Type.POSITION);
            // 1 - Face
            map(Type.VAR_INT);
            // 2 - Hand
            map(Type.VAR_INT);
            map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT);
            map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT);
            map(Type.UNSIGNED_BYTE, TO_NEW_FLOAT);
        }
    });
}
Also used : PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) LegacyComponentSerializer(com.viaversion.viaversion.libs.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer) Type(com.viaversion.viaversion.api.type.Type) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) ServerboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) ValueTransformer(com.viaversion.viaversion.api.protocol.remapper.ValueTransformer) ClientboundPackets1_9_3(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3) GsonComponentSerializer(com.viaversion.viaversion.libs.kyori.adventure.text.serializer.gson.GsonComponentSerializer) Protocol1_10To1_11(com.viaversion.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject)

Example 10 with JsonObject

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

the class Protocol1_13To1_13_1 method registerPackets.

@Override
protected void registerPackets() {
    executeAsyncAfterLoaded(Protocol1_13_1To1_13.class, MAPPINGS::load);
    entityRewriter.register();
    itemRewriter.register();
    WorldPackets1_13_1.register(this);
    TranslatableRewriter translatableRewriter = new TranslatableRewriter(this);
    translatableRewriter.registerChatMessage(ClientboundPackets1_13.CHAT_MESSAGE);
    translatableRewriter.registerCombatEvent(ClientboundPackets1_13.COMBAT_EVENT);
    translatableRewriter.registerDisconnect(ClientboundPackets1_13.DISCONNECT);
    translatableRewriter.registerTabList(ClientboundPackets1_13.TAB_LIST);
    translatableRewriter.registerTitle(ClientboundPackets1_13.TITLE);
    translatableRewriter.registerPing();
    new CommandRewriter1_13_1(this).registerDeclareCommands(ClientboundPackets1_13.DECLARE_COMMANDS);
    registerServerbound(ServerboundPackets1_13.TAB_COMPLETE, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.VAR_INT);
            map(Type.STRING, new ValueTransformer<String, String>(Type.STRING) {

                @Override
                public String transform(PacketWrapper wrapper, String inputValue) {
                    // 1.13 starts sending slash at start, so we remove it for compatibility
                    return !inputValue.startsWith("/") ? "/" + inputValue : inputValue;
                }
            });
        }
    });
    registerServerbound(ServerboundPackets1_13.EDIT_BOOK, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.FLAT_ITEM);
            map(Type.BOOLEAN);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    itemRewriter.handleItemToServer(wrapper.get(Type.FLAT_ITEM, 0));
                    wrapper.write(Type.VAR_INT, 0);
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_13.OPEN_WINDOW, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Id
            map(Type.UNSIGNED_BYTE);
            // Window Type
            map(Type.STRING);
            handler(wrapper -> {
                JsonElement title = wrapper.passthrough(Type.COMPONENT);
                translatableRewriter.processText(title);
                if (ViaBackwards.getConfig().fix1_13FormattedInventoryTitle()) {
                    if (title.isJsonObject() && title.getAsJsonObject().size() == 1 && title.getAsJsonObject().has("translate")) {
                        // Hotfix simple translatable components from being converted to legacy text
                        return;
                    }
                    // https://bugs.mojang.com/browse/MC-124543
                    JsonObject legacyComponent = new JsonObject();
                    legacyComponent.addProperty("text", ChatRewriter.jsonToLegacyText(title.toString()));
                    wrapper.set(Type.COMPONENT, 0, legacyComponent);
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_13.TAB_COMPLETE, new PacketRemapper() {

        @Override
        public void registerMap() {
            // Transaction id
            map(Type.VAR_INT);
            // Start
            map(Type.VAR_INT);
            // Length
            map(Type.VAR_INT);
            // Count
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int start = wrapper.get(Type.VAR_INT, 1);
                    // Offset by +1 to take into account / at beginning
                    wrapper.set(Type.VAR_INT, 1, start - 1);
                    // Passthrough suggestions
                    int count = wrapper.get(Type.VAR_INT, 3);
                    for (int i = 0; i < count; i++) {
                        wrapper.passthrough(Type.STRING);
                        boolean hasTooltip = wrapper.passthrough(Type.BOOLEAN);
                        if (hasTooltip) {
                            // JSON Tooltip
                            wrapper.passthrough(Type.STRING);
                        }
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_13.BOSSBAR, new PacketRemapper() {

        @Override
        public void registerMap() {
            map(Type.UUID);
            map(Type.VAR_INT);
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int action = wrapper.get(Type.VAR_INT, 0);
                    if (action == 0 || action == 3) {
                        translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT));
                        if (action == 0) {
                            wrapper.passthrough(Type.FLOAT);
                            wrapper.passthrough(Type.VAR_INT);
                            wrapper.passthrough(Type.VAR_INT);
                            short flags = wrapper.read(Type.UNSIGNED_BYTE);
                            if ((flags & 0x04) != 0)
                                flags |= 0x02;
                            wrapper.write(Type.UNSIGNED_BYTE, flags);
                        }
                    }
                }
            });
        }
    });
    registerClientbound(ClientboundPackets1_13.ADVANCEMENTS, new PacketRemapper() {

        @Override
        public void registerMap() {
            handler(new PacketHandler() {

                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    // Reset/clear
                    wrapper.passthrough(Type.BOOLEAN);
                    // Mapping size
                    int size = wrapper.passthrough(Type.VAR_INT);
                    for (int i = 0; i < size; i++) {
                        // Identifier
                        wrapper.passthrough(Type.STRING);
                        // Parent
                        if (wrapper.passthrough(Type.BOOLEAN))
                            wrapper.passthrough(Type.STRING);
                        // Display data
                        if (wrapper.passthrough(Type.BOOLEAN)) {
                            // Title
                            wrapper.passthrough(Type.COMPONENT);
                            // Description
                            wrapper.passthrough(Type.COMPONENT);
                            Item icon = wrapper.passthrough(Type.FLAT_ITEM);
                            itemRewriter.handleItemToClient(icon);
                            // Frame type
                            wrapper.passthrough(Type.VAR_INT);
                            // Flags
                            int flags = wrapper.passthrough(Type.INT);
                            if ((flags & 1) != 0)
                                // Background texture
                                wrapper.passthrough(Type.STRING);
                            // X
                            wrapper.passthrough(Type.FLOAT);
                            // Y
                            wrapper.passthrough(Type.FLOAT);
                        }
                        // Criteria
                        wrapper.passthrough(Type.STRING_ARRAY);
                        int arrayLength = wrapper.passthrough(Type.VAR_INT);
                        for (int array = 0; array < arrayLength; array++) {
                            // String array
                            wrapper.passthrough(Type.STRING_ARRAY);
                        }
                    }
                }
            });
        }
    });
    new TagRewriter(this).register(ClientboundPackets1_13.TAGS, RegistryType.ITEM);
    new StatisticsRewriter(this).register(ClientboundPackets1_13.STATISTICS);
}
Also used : ValueTransformer(com.viaversion.viaversion.api.protocol.remapper.ValueTransformer) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) TranslatableRewriter(com.viaversion.viabackwards.api.rewriters.TranslatableRewriter) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) Entity1_13Types(com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types) Item(com.viaversion.viaversion.api.minecraft.item.Item) BackwardsProtocol(com.viaversion.viabackwards.api.BackwardsProtocol) RegistryType(com.viaversion.viaversion.api.minecraft.RegistryType) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) Type(com.viaversion.viaversion.api.type.Type) ServerboundPackets1_13(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13) EntityTrackerBase(com.viaversion.viaversion.data.entity.EntityTrackerBase) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) ValueTransformer(com.viaversion.viaversion.api.protocol.remapper.ValueTransformer) ItemRewriter(com.viaversion.viaversion.api.rewriter.ItemRewriter) CommandRewriter1_13_1(com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.data.CommandRewriter1_13_1) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement) InventoryPackets1_13_1(com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets.InventoryPackets1_13_1) ClientWorld(com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld) WorldPackets1_13_1(com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets.WorldPackets1_13_1) EntityPackets1_13_1(com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.packets.EntityPackets1_13_1) ClientboundPackets1_13(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) BackwardsMappings(com.viaversion.viabackwards.api.data.BackwardsMappings) ChatRewriter(com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter) ViaBackwards(com.viaversion.viabackwards.ViaBackwards) EntityRewriter(com.viaversion.viaversion.api.rewriter.EntityRewriter) Protocol1_13_1To1_13(com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13) CommandRewriter1_13_1(com.viaversion.viabackwards.protocol.protocol1_13to1_13_1.data.CommandRewriter1_13_1) TranslatableRewriter(com.viaversion.viabackwards.api.rewriters.TranslatableRewriter) TagRewriter(com.viaversion.viaversion.rewriter.TagRewriter) PacketRemapper(com.viaversion.viaversion.api.protocol.remapper.PacketRemapper) JsonObject(com.viaversion.viaversion.libs.gson.JsonObject) Item(com.viaversion.viaversion.api.minecraft.item.Item) StatisticsRewriter(com.viaversion.viaversion.rewriter.StatisticsRewriter) PacketHandler(com.viaversion.viaversion.api.protocol.remapper.PacketHandler) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) JsonElement(com.viaversion.viaversion.libs.gson.JsonElement)

Aggregations

JsonObject (com.viaversion.viaversion.libs.gson.JsonObject)11 JsonElement (com.viaversion.viaversion.libs.gson.JsonElement)7 PacketRemapper (com.viaversion.viaversion.api.protocol.remapper.PacketRemapper)4 Type (com.viaversion.viaversion.api.type.Type)4 TranslatableRewriter (com.viaversion.viabackwards.api.rewriters.TranslatableRewriter)3 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)3 ViaBackwards (com.viaversion.viabackwards.ViaBackwards)2 BackwardsProtocol (com.viaversion.viabackwards.api.BackwardsProtocol)2 Via (com.viaversion.viaversion.api.Via)2 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)2 RegistryType (com.viaversion.viaversion.api.minecraft.RegistryType)2 Item (com.viaversion.viaversion.api.minecraft.item.Item)2 PacketHandler (com.viaversion.viaversion.api.protocol.remapper.PacketHandler)2 ValueTransformer (com.viaversion.viaversion.api.protocol.remapper.ValueTransformer)2 EntityRewriter (com.viaversion.viaversion.api.rewriter.EntityRewriter)2 EntityTrackerBase (com.viaversion.viaversion.data.entity.EntityTrackerBase)2 JsonArray (com.viaversion.viaversion.libs.gson.JsonArray)2 JsonPrimitive (com.viaversion.viaversion.libs.gson.JsonPrimitive)2 ClientWorld (com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld)2 StatisticsRewriter (com.viaversion.viaversion.rewriter.StatisticsRewriter)2