3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Use a dummy legacy event hover serializer

This reduces computation processing needing, since Bedrock doesn't have any hover text ability. This also fixes a 1.8 bug where villager titles would not process correctly - by having a dummy serializer, a recent MCProtocolLib update would not stop the window packet from processing.
Dieser Commit ist enthalten in:
Camotoy 2022-03-05 22:15:25 -05:00
Ursprung edbb946d97
Commit 50bed6a2be
4 geänderte Dateien mit 80 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -155,7 +155,7 @@
<dependency> <dependency>
<groupId>com.github.GeyserMC</groupId> <groupId>com.github.GeyserMC</groupId>
<artifactId>MCProtocolLib</artifactId> <artifactId>MCProtocolLib</artifactId>
<version>7efa636</version> <version>0771504</version>
<scope>compile</scope> <scope>compile</scope>
<exclusions> <exclusions>
<exclusion> <exclusion>

Datei anzeigen

@ -0,0 +1,69 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.text;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.serializer.gson.LegacyHoverEventSerializer;
import net.kyori.adventure.util.Codec;
import org.jetbrains.annotations.NotNull;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
public final class DummyLegacyHoverEventSerializer implements LegacyHoverEventSerializer {
private final HoverEvent.ShowEntity dummyShowEntity;
private final HoverEvent.ShowItem dummyShowItem;
public DummyLegacyHoverEventSerializer() {
dummyShowEntity = HoverEvent.ShowEntity.of(Key.key("geysermc", "dummyshowitem"),
UUID.nameUUIDFromBytes("entitiesareprettyneat".getBytes(StandardCharsets.UTF_8)));
dummyShowItem = HoverEvent.ShowItem.of(Key.key("geysermc", "dummyshowentity"), 0);
}
@Override
public HoverEvent.@NotNull ShowItem deserializeShowItem(@NotNull Component input) {
return dummyShowItem;
}
@Override
public HoverEvent.@NotNull ShowEntity deserializeShowEntity(@NotNull Component input,
Codec.Decoder<Component, String, ? extends RuntimeException> componentDecoder) {
return dummyShowEntity;
}
@Override
public @NotNull Component serializeShowItem(HoverEvent.@NotNull ShowItem input) {
return Component.empty();
}
@Override
public @NotNull Component serializeShowEntity(HoverEvent.@NotNull ShowEntity input,
Codec.Encoder<Component, String, ? extends RuntimeException> componentEncoder) {
return Component.empty();
}
}

Datei anzeigen

@ -29,12 +29,11 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.inventory.Cli
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundContainerClosePacket;
import org.geysermc.geyser.inventory.Inventory; import org.geysermc.geyser.inventory.Inventory;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.PacketTranslator;
import org.geysermc.geyser.translator.protocol.Translator; import org.geysermc.geyser.translator.protocol.Translator;
import org.geysermc.geyser.translator.text.MessageTranslator; import org.geysermc.geyser.translator.text.MessageTranslator;
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
import org.geysermc.geyser.util.InventoryUtils; import org.geysermc.geyser.util.InventoryUtils;
import org.geysermc.geyser.text.MinecraftLocale;
@Translator(packet = ClientboundOpenScreenPacket.class) @Translator(packet = ClientboundOpenScreenPacket.class)
public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenScreenPacket> { public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenScreenPacket> {
@ -57,8 +56,7 @@ public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenSc
return; return;
} }
String name = MessageTranslator.convertMessageLenient(packet.getName(), session.getLocale()); String name = MessageTranslator.convertMessage(packet.getTitle(), session.getLocale());
name = MinecraftLocale.getLocaleString(name, session.getLocale());
Inventory newInventory = newTranslator.createInventory(name, packet.getContainerId(), packet.getType(), session.getPlayerInventory()); Inventory newInventory = newTranslator.createInventory(name, packet.getContainerId(), packet.getType(), session.getPlayerInventory());
if (openInventory != null) { if (openInventory != null) {

Datei anzeigen

@ -34,10 +34,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.*;
import org.geysermc.geyser.text.GeyserLocale;
import org.geysermc.geyser.text.GsonComponentSerializerWrapper;
import org.geysermc.geyser.text.MinecraftTranslationRegistry;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
@ -85,8 +82,13 @@ public class MessageTranslator {
TEAM_COLORS.put(TeamColor.STRIKETHROUGH, BASE + "m"); TEAM_COLORS.put(TeamColor.STRIKETHROUGH, BASE + "m");
TEAM_COLORS.put(TeamColor.ITALIC, BASE + "o"); TEAM_COLORS.put(TeamColor.ITALIC, BASE + "o");
// Temporary fix for https://github.com/KyoriPowered/adventure/issues/447 // Temporary fix for https://github.com/KyoriPowered/adventure/issues/447 - TODO resolve properly
GsonComponentSerializer source = DefaultComponentSerializer.get(); GsonComponentSerializer source = DefaultComponentSerializer.get()
.toBuilder()
// Use a custom legacy hover event deserializer since we don't use any of this data anyway, and
// fixes issues where legacy hover events throw deserialization errors
.legacyHoverEventSerializer(new DummyLegacyHoverEventSerializer())
.build();
GSON_SERIALIZER = new GsonComponentSerializerWrapper(source); GSON_SERIALIZER = new GsonComponentSerializerWrapper(source);
// Tell MCProtocolLib to use this serializer, too. // Tell MCProtocolLib to use this serializer, too.
DefaultComponentSerializer.set(GSON_SERIALIZER); DefaultComponentSerializer.set(GSON_SERIALIZER);