Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +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:
Ursprung
edbb946d97
Commit
50bed6a2be
@ -155,7 +155,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.GeyserMC</groupId>
|
||||
<artifactId>MCProtocolLib</artifactId>
|
||||
<version>7efa636</version>
|
||||
<version>0771504</version>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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 org.geysermc.geyser.inventory.Inventory;
|
||||
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.Translator;
|
||||
import org.geysermc.geyser.translator.text.MessageTranslator;
|
||||
import org.geysermc.geyser.translator.inventory.InventoryTranslator;
|
||||
import org.geysermc.geyser.util.InventoryUtils;
|
||||
import org.geysermc.geyser.text.MinecraftLocale;
|
||||
|
||||
@Translator(packet = ClientboundOpenScreenPacket.class)
|
||||
public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenScreenPacket> {
|
||||
@ -57,8 +56,7 @@ public class JavaOpenScreenTranslator extends PacketTranslator<ClientboundOpenSc
|
||||
return;
|
||||
}
|
||||
|
||||
String name = MessageTranslator.convertMessageLenient(packet.getName(), session.getLocale());
|
||||
name = MinecraftLocale.getLocaleString(name, session.getLocale());
|
||||
String name = MessageTranslator.convertMessage(packet.getTitle(), session.getLocale());
|
||||
|
||||
Inventory newInventory = newTranslator.createInventory(name, packet.getContainerId(), packet.getType(), session.getPlayerInventory());
|
||||
if (openInventory != null) {
|
||||
|
@ -34,10 +34,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.ChatColor;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.geysermc.geyser.text.GsonComponentSerializerWrapper;
|
||||
import org.geysermc.geyser.text.MinecraftTranslationRegistry;
|
||||
import org.geysermc.geyser.text.*;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
@ -85,8 +82,13 @@ public class MessageTranslator {
|
||||
TEAM_COLORS.put(TeamColor.STRIKETHROUGH, BASE + "m");
|
||||
TEAM_COLORS.put(TeamColor.ITALIC, BASE + "o");
|
||||
|
||||
// Temporary fix for https://github.com/KyoriPowered/adventure/issues/447
|
||||
GsonComponentSerializer source = DefaultComponentSerializer.get();
|
||||
// Temporary fix for https://github.com/KyoriPowered/adventure/issues/447 - TODO resolve properly
|
||||
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);
|
||||
// Tell MCProtocolLib to use this serializer, too.
|
||||
DefaultComponentSerializer.set(GSON_SERIALIZER);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren