2021-02-27 20:15:43 +01:00
|
|
|
/**
|
|
|
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
|
|
|
* Copyright (C) 2015 dmulloy2
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with this program;
|
|
|
|
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
* 02111-1307 USA
|
|
|
|
*/
|
|
|
|
package com.comphenix.protocol.wrappers;
|
|
|
|
|
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility class for converting between the Adventure API Component and ProtocolLib's wrapper
|
|
|
|
* <p>
|
|
|
|
* Note: The Adventure API Component is not included in CraftBukkit, Bukkit or Spigot and but is present in PaperMC.
|
|
|
|
*/
|
|
|
|
public class AdventureComponentConverter {
|
|
|
|
|
|
|
|
private AdventureComponentConverter() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a {@link WrappedChatComponent} into a {@link Component}
|
|
|
|
* @param wrapper ProtocolLib wrapper
|
|
|
|
* @return Component
|
|
|
|
*/
|
|
|
|
public static Component fromWrapper(WrappedChatComponent wrapper) {
|
|
|
|
return GsonComponentSerializer.gson().deserialize(wrapper.getJson());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a {@link Component} into a ProtocolLib wrapper
|
Packet filtering for bundled packets in 1.19.4 (#2258)
Since Minecraft 1.19.4, the protocol supports bundling consecutive packets to ensure the client processes them in one tick. However, Packet Events are not called for the individual packets in such a bundle in the current dev build of ProtocolLib. For example, no packet events are currently sent for the ENTITY_METADATA packet when an entity is first spawned as the packet is bundled with the ENTITY_SPAWN packet. However, if the entity metadata is changed later on, the event will be called.
This PR proposes to fix this by unpacking the bundled packets and invoking the packet filtering for each packet.
I also want to briefly explain how the bundling works. A bundle starts with a PACKET_DELIMITER (0x00, net.minecraft.network.protocol.BundleDelimiterPacket) packet followed by all packets that should be bundled and finished with another PACKET_DELIMITER (0x00). Within the Netty pipeline, this sequence is transformed into one synthesized packet found in net.minecraft.network.protocol.game.ClientboundBundlePacket, which is essentially just a list of packets. At the stage at which ProtocolLib injects into the clientbound netty pipeline, this packet has not been unpacked yet. Thus, we need to handle the ClientboundBundlePacket, which unfortunately is not registered in ProtocolLib. The fact that two different classes map to the same packet currently requires a dirty remapping in the packet structure modifier.
2023-03-26 04:08:31 +02:00
|
|
|
* @param component Component
|
2021-02-27 20:15:43 +01:00
|
|
|
* @return ProtocolLib wrapper
|
|
|
|
*/
|
|
|
|
public static WrappedChatComponent fromComponent(Component component) {
|
|
|
|
return WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(component));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Class<?> getComponentClass() {
|
|
|
|
return Component.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Component clone(Object component) {
|
|
|
|
return (Component) component;
|
|
|
|
}
|
|
|
|
}
|