diff --git a/src/client/java/net/kyori/adventure/platform/fabric/impl/client/ClientProxy.java b/src/client/java/net/kyori/adventure/platform/fabric/impl/client/ClientProxy.java index f38cbdc4..97996eb8 100644 --- a/src/client/java/net/kyori/adventure/platform/fabric/impl/client/ClientProxy.java +++ b/src/client/java/net/kyori/adventure/platform/fabric/impl/client/ClientProxy.java @@ -1,7 +1,7 @@ /* * This file is part of adventure-platform-fabric, licensed under the MIT License. * - * Copyright (c) 2020-2022 KyoriPowered + * Copyright (c) 2020-2024 KyoriPowered * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,7 @@ package net.kyori.adventure.platform.fabric.impl.client; import java.util.function.Function; +import net.kyori.adventure.platform.fabric.impl.NonWrappingComponentSerializer; import net.kyori.adventure.platform.fabric.impl.SidedProxy; import net.kyori.adventure.platform.fabric.impl.WrappedComponent; import net.kyori.adventure.pointer.Pointered; @@ -47,7 +48,8 @@ public void contributeFlattenerElements( public @NotNull WrappedComponent createWrappedComponent( final @NotNull Component wrapped, final @Nullable Function partition, - final @Nullable ComponentRenderer renderer + final @Nullable ComponentRenderer renderer, + final @Nullable NonWrappingComponentSerializer nonWrappingSerializer ) { return new ClientWrappedComponent(wrapped, partition, renderer); } diff --git a/src/client/java/net/kyori/adventure/platform/fabric/impl/client/ClientWrappedComponent.java b/src/client/java/net/kyori/adventure/platform/fabric/impl/client/ClientWrappedComponent.java index cc2035a5..4fb34606 100644 --- a/src/client/java/net/kyori/adventure/platform/fabric/impl/client/ClientWrappedComponent.java +++ b/src/client/java/net/kyori/adventure/platform/fabric/impl/client/ClientWrappedComponent.java @@ -1,7 +1,7 @@ /* * This file is part of adventure-platform-fabric, licensed under the MIT License. * - * Copyright (c) 2020-2023 KyoriPowered + * Copyright (c) 2020-2024 KyoriPowered * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -33,7 +33,7 @@ public final class ClientWrappedComponent extends WrappedComponent { public ClientWrappedComponent(final Component wrapped, final @Nullable Function partition, final @Nullable ComponentRenderer renderer) { - super(wrapped, partition, renderer); + super(wrapped, partition, renderer, null); } @Override diff --git a/src/main/java/net/kyori/adventure/platform/fabric/FabricAudiences.java b/src/main/java/net/kyori/adventure/platform/fabric/FabricAudiences.java index f460716b..f24a90dd 100644 --- a/src/main/java/net/kyori/adventure/platform/fabric/FabricAudiences.java +++ b/src/main/java/net/kyori/adventure/platform/fabric/FabricAudiences.java @@ -85,7 +85,7 @@ public interface FabricAudiences { partition = null; renderer = null; } - return AdventureCommon.SIDE_PROXY.createWrappedComponent(modified, partition, renderer); + return AdventureCommon.SIDE_PROXY.createWrappedComponent(modified, partition, renderer, null); } /** diff --git a/src/main/java/net/kyori/adventure/platform/fabric/impl/NonWrappingComponentSerializer.java b/src/main/java/net/kyori/adventure/platform/fabric/impl/NonWrappingComponentSerializer.java index b8343e52..dde1ea61 100644 --- a/src/main/java/net/kyori/adventure/platform/fabric/impl/NonWrappingComponentSerializer.java +++ b/src/main/java/net/kyori/adventure/platform/fabric/impl/NonWrappingComponentSerializer.java @@ -47,7 +47,7 @@ private NonWrappingComponentSerializer() { this(Suppliers.ofInstance(RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY))); } - private NonWrappingComponentSerializer(final @NotNull Supplier provider) { + public NonWrappingComponentSerializer(final @NotNull Supplier provider) { this.holderProvider = provider; } diff --git a/src/main/java/net/kyori/adventure/platform/fabric/impl/SidedProxy.java b/src/main/java/net/kyori/adventure/platform/fabric/impl/SidedProxy.java index 39895792..6eb7bc60 100644 --- a/src/main/java/net/kyori/adventure/platform/fabric/impl/SidedProxy.java +++ b/src/main/java/net/kyori/adventure/platform/fabric/impl/SidedProxy.java @@ -1,7 +1,7 @@ /* * This file is part of adventure-platform-fabric, licensed under the MIT License. * - * Copyright (c) 2020-2022 KyoriPowered + * Copyright (c) 2020-2024 KyoriPowered * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -37,6 +37,7 @@ public interface SidedProxy { @NotNull WrappedComponent createWrappedComponent( final @NotNull Component wrapped, final @Nullable Function partition, - final @Nullable ComponentRenderer renderer + final @Nullable ComponentRenderer renderer, + final @Nullable NonWrappingComponentSerializer nonWrappingSerializer ); } diff --git a/src/main/java/net/kyori/adventure/platform/fabric/impl/WrappedComponent.java b/src/main/java/net/kyori/adventure/platform/fabric/impl/WrappedComponent.java index 4c97ea56..809264e9 100644 --- a/src/main/java/net/kyori/adventure/platform/fabric/impl/WrappedComponent.java +++ b/src/main/java/net/kyori/adventure/platform/fabric/impl/WrappedComponent.java @@ -1,7 +1,7 @@ /* * This file is part of adventure-platform-fabric, licensed under the MIT License. * - * Copyright (c) 2020-2023 KyoriPowered + * Copyright (c) 2020-2024 KyoriPowered * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -32,6 +32,7 @@ import net.kyori.adventure.pointer.Pointers; import net.kyori.adventure.text.TextComponent; import net.kyori.adventure.text.renderer.ComponentRenderer; +import net.kyori.adventure.text.serializer.ComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentContents; @@ -49,13 +50,20 @@ public class WrappedComponent implements Component { private final net.kyori.adventure.text.Component wrapped; private final @Nullable Function partition; private final @Nullable ComponentRenderer renderer; + private final @Nullable NonWrappingComponentSerializer nonWrappingSerializer; private @Nullable Object lastData; private @Nullable WrappedComponent lastRendered; - public WrappedComponent(final net.kyori.adventure.text.Component wrapped, final @Nullable Function partition, final @Nullable ComponentRenderer renderer) { + public WrappedComponent( + final net.kyori.adventure.text.Component wrapped, + final @Nullable Function partition, + final @Nullable ComponentRenderer renderer, + final @Nullable NonWrappingComponentSerializer nonWrappingComponentSerializer + ) { this.wrapped = wrapped; this.partition = partition; this.renderer = renderer; + this.nonWrappingSerializer = nonWrappingComponentSerializer; } /** @@ -86,13 +94,17 @@ public synchronized WrappedComponent rendered(final Pointered ptr) { return this.lastRendered; } this.lastData = data; - return this.lastRendered = this.renderer == null ? this : AdventureCommon.SIDE_PROXY.createWrappedComponent(this.renderer.render(this.wrapped, ptr), null, null); + return this.lastRendered = this.renderer == null ? this : AdventureCommon.SIDE_PROXY.createWrappedComponent(this.renderer.render(this.wrapped, ptr), null, null, this.nonWrappingSerializer); } public Component deepConverted() { Component converted = this.converted; if (converted == null || this.deepConvertedLocalized != null) { - converted = this.converted = FabricAudiences.nonWrappingSerializer().serialize(this.wrapped); + ComponentSerializer serializer = this.nonWrappingSerializer; + if (serializer == null) { + serializer = FabricAudiences.nonWrappingSerializer(); + } + converted = this.converted = serializer.serialize(this.wrapped); this.deepConvertedLocalized = null; } return converted; diff --git a/src/main/java/net/kyori/adventure/platform/fabric/impl/server/DedicatedServerProxy.java b/src/main/java/net/kyori/adventure/platform/fabric/impl/server/DedicatedServerProxy.java index 29a23695..0eb31e43 100644 --- a/src/main/java/net/kyori/adventure/platform/fabric/impl/server/DedicatedServerProxy.java +++ b/src/main/java/net/kyori/adventure/platform/fabric/impl/server/DedicatedServerProxy.java @@ -1,7 +1,7 @@ /* * This file is part of adventure-platform-fabric, licensed under the MIT License. * - * Copyright (c) 2020-2022 KyoriPowered + * Copyright (c) 2020-2024 KyoriPowered * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,6 +24,7 @@ package net.kyori.adventure.platform.fabric.impl.server; import java.util.function.Function; +import net.kyori.adventure.platform.fabric.impl.NonWrappingComponentSerializer; import net.kyori.adventure.platform.fabric.impl.SidedProxy; import net.kyori.adventure.platform.fabric.impl.WrappedComponent; import net.kyori.adventure.pointer.Pointered; @@ -43,8 +44,9 @@ public void contributeFlattenerElements(final ComponentFlattener.@NotNull Builde public @NotNull WrappedComponent createWrappedComponent( final @NotNull Component wrapped, final @Nullable Function partition, - final @Nullable ComponentRenderer renderer + final @Nullable ComponentRenderer renderer, + final @Nullable NonWrappingComponentSerializer nonWrappingSerializer ) { - return new WrappedComponent(wrapped, partition, renderer); + return new WrappedComponent(wrapped, partition, renderer, nonWrappingSerializer); } } diff --git a/src/main/java/net/kyori/adventure/platform/fabric/impl/server/FabricServerAudiencesImpl.java b/src/main/java/net/kyori/adventure/platform/fabric/impl/server/FabricServerAudiencesImpl.java index c905fbdc..58af1c68 100644 --- a/src/main/java/net/kyori/adventure/platform/fabric/impl/server/FabricServerAudiencesImpl.java +++ b/src/main/java/net/kyori/adventure/platform/fabric/impl/server/FabricServerAudiencesImpl.java @@ -1,7 +1,7 @@ /* * This file is part of adventure-platform-fabric, licensed under the MIT License. * - * Copyright (c) 2020-2023 KyoriPowered + * Copyright (c) 2020-2024 KyoriPowered * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,6 +38,7 @@ import net.kyori.adventure.platform.fabric.impl.AdventureCommandSourceStackInternal; import net.kyori.adventure.platform.fabric.impl.AdventureCommon; import net.kyori.adventure.platform.fabric.impl.FabricAudiencesInternal; +import net.kyori.adventure.platform.fabric.impl.NonWrappingComponentSerializer; import net.kyori.adventure.pointer.Pointered; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.flattener.ComponentFlattener; @@ -76,12 +77,14 @@ public static void forEachInstance(final Consumer act } private final MinecraftServer server; + private final NonWrappingComponentSerializer nonWrappingSerializer; private final Function partition; private final ComponentRenderer renderer; final ServerBossBarListener bossBars; public FabricServerAudiencesImpl(final MinecraftServer server, final Function partition, final ComponentRenderer renderer) { this.server = server; + this.nonWrappingSerializer = new NonWrappingComponentSerializer(this::registryAccess); this.partition = partition; this.renderer = renderer; this.bossBars = new ServerBossBarListener(this); @@ -179,7 +182,12 @@ private Iterable audiences(final Iterable play public net.minecraft.network.chat.@NotNull Component toNative(final @NotNull Component adventure) { if (adventure == Component.empty()) return net.minecraft.network.chat.Component.empty(); - return AdventureCommon.SIDE_PROXY.createWrappedComponent(requireNonNull(adventure, "adventure"), this.partition, this.renderer); + return AdventureCommon.SIDE_PROXY.createWrappedComponent(requireNonNull(adventure, "adventure"), this.partition, this.renderer, this.nonWrappingSerializer); + } + + @Override + public @NotNull Component toAdventure(final net.minecraft.network.chat.@NotNull Component vanilla) { + return this.nonWrappingSerializer.deserialize(vanilla); } public ServerBossBarListener bossBars() { diff --git a/src/test/java/net/kyori/adventure/platform/fabric/ComponentConversionTest.java b/src/test/java/net/kyori/adventure/platform/fabric/ComponentConversionTest.java index 78185ab0..9f4b48d9 100644 --- a/src/test/java/net/kyori/adventure/platform/fabric/ComponentConversionTest.java +++ b/src/test/java/net/kyori/adventure/platform/fabric/ComponentConversionTest.java @@ -134,6 +134,6 @@ private static String toStableString(final JsonElement stringable) { private WrappedComponent toNativeWrapped(final Component component) { final Function partition = AdventureCommon.localePartition(); - return new WrappedComponent(component, partition, GlobalTranslator.renderer().mapContext(partition)); + return new WrappedComponent(component, partition, GlobalTranslator.renderer().mapContext(partition), null); } }