Search in sources :

Example 11 with WrappedChatComponent

use of com.comphenix.protocol.wrappers.WrappedChatComponent in project ProtocolStringReplacer by Rothes.

the class BossBar method process.

protected void process(PacketEvent packetEvent) {
    PsrUser user = getEventUser(packetEvent);
    if (user == null) {
        return;
    }
    StructureModifier<WrappedChatComponent> wrappedChatComponentStructureModifier = packetEvent.getPacket().getChatComponents();
    if (wrappedChatComponentStructureModifier.size() != 0) {
        WrappedChatComponent wrappedChatComponent = wrappedChatComponentStructureModifier.read(0);
        String json = wrappedChatComponent.getJson();
        WrappedChatComponent replaced = getReplacedJsonWrappedComponent(packetEvent, user, listenType, json, filter);
        if (replaced != null) {
            wrappedChatComponentStructureModifier.write(0, replaced);
        }
    }
}
Also used : WrappedChatComponent(com.comphenix.protocol.wrappers.WrappedChatComponent) PsrUser(me.rothes.protocolstringreplacer.api.user.PsrUser)

Example 12 with WrappedChatComponent

use of com.comphenix.protocol.wrappers.WrappedChatComponent in project ProtocolStringReplacer by Rothes.

the class ScoreBoardObjective method process.

protected void process(PacketEvent packetEvent) {
    PsrUser user = getEventUser(packetEvent);
    if (user == null) {
        return;
    }
    PacketContainer packet = packetEvent.getPacket();
    if (packet.getIntegers().read(0) != 1) {
        if (ProtocolStringReplacer.getInstance().getServerMajorVersion() > 12) {
            StructureModifier<WrappedChatComponent> wrappedChatComponentStructureModifier = packet.getChatComponents();
            WrappedChatComponent wrappedChatComponent = wrappedChatComponentStructureModifier.read(0);
            String replaced = getReplacedJson(packetEvent, user, listenType, wrappedChatComponent.getJson(), titleFilter);
            if (replaced != null) {
                wrappedChatComponentStructureModifier.write(0, wrappedChatComponent);
            }
        } else {
            StructureModifier<String> strings = packet.getStrings();
            String replaced = getReplacedText(packetEvent, user, listenType, strings.read(0), titleFilter);
            if (replaced != null)
                strings.write(0, replaced);
        }
    }
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) WrappedChatComponent(com.comphenix.protocol.wrappers.WrappedChatComponent) PsrUser(me.rothes.protocolstringreplacer.api.user.PsrUser)

Aggregations

WrappedChatComponent (com.comphenix.protocol.wrappers.WrappedChatComponent)12 PacketContainer (com.comphenix.protocol.events.PacketContainer)9 PsrUser (me.rothes.protocolstringreplacer.api.user.PsrUser)8 WrappedWatchableObject (com.comphenix.protocol.wrappers.WrappedWatchableObject)2 Optional (java.util.Optional)2 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)2 ItemStack (org.bukkit.inventory.ItemStack)2 FieldAccessException (com.comphenix.protocol.reflect.FieldAccessException)1 BlockPosition (com.comphenix.protocol.wrappers.BlockPosition)1 Direction (com.comphenix.protocol.wrappers.EnumWrappers.Direction)1 NativeGameMode (com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode)1 PlayerInfoData (com.comphenix.protocol.wrappers.PlayerInfoData)1 Vector3F (com.comphenix.protocol.wrappers.Vector3F)1 WrappedBlockData (com.comphenix.protocol.wrappers.WrappedBlockData)1 WrappedDataWatcherObject (com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject)1 WrappedParticle (com.comphenix.protocol.wrappers.WrappedParticle)1 NbtWrapper (com.comphenix.protocol.wrappers.nbt.NbtWrapper)1 IOException (java.io.IOException)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 Field (java.lang.reflect.Field)1