Search in sources :

Example 1 with WrappedChatComponent

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

the class ActionBar method process.

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

Example 2 with WrappedChatComponent

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

the class Chat method process.

protected void process(PacketEvent packetEvent) {
    PacketContainer packet = packetEvent.getPacket();
    Optional<Boolean> isFiltered = packet.getMeta("psr_filtered_packet");
    if (!(isFiltered.isPresent() && isFiltered.get())) {
        PsrUser user = getEventUser(packetEvent);
        if (user == null) {
            return;
        }
        StructureModifier<WrappedChatComponent> wrappedChatComponentStructureModifier = packet.getChatComponents();
        WrappedChatComponent wrappedChatComponent = wrappedChatComponentStructureModifier.read(0);
        String json;
        if (wrappedChatComponent != null) {
            json = wrappedChatComponent.getJson();
            WrappedChatComponent replaced = getReplacedJsonWrappedComponent(packetEvent, user, listenType, json, filter);
            if (replaced != null) {
                wrappedChatComponentStructureModifier.write(0, replaced);
            }
        } else {
            StructureModifier<Object> modifier = packet.getModifier();
            setupFields(modifier.getFields());
            if (bungeeComponentsField != -1) {
                Object obj = modifier.read(bungeeComponentsField);
                if (obj == null) {
                    if (paperComponentField != -1) {
                        obj = modifier.read(paperComponentField);
                        Component component = (Component) obj;
                        json = getPaperGsonComponentSerializer().serialize(component);
                        WrappedChatComponent replaced = getReplacedJsonWrappedComponent(packetEvent, user, listenType, json, filter);
                        if (replaced != null) {
                            wrappedChatComponentStructureModifier.write(0, replaced);
                            modifier.write(paperComponentField, null);
                        }
                    }
                    return;
                }
                BaseComponent[] components = (BaseComponent[]) obj;
                json = ComponentSerializer.toString(components);
                WrappedChatComponent replaced = getReplacedJsonWrappedComponent(packetEvent, user, listenType, json, filter);
                if (replaced != null) {
                    wrappedChatComponentStructureModifier.write(0, replaced);
                    modifier.write(bungeeComponentsField, null);
                }
            }
        }
    }
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) WrappedChatComponent(com.comphenix.protocol.wrappers.WrappedChatComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) PsrUser(me.rothes.protocolstringreplacer.api.user.PsrUser) WrappedChatComponent(com.comphenix.protocol.wrappers.WrappedChatComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) Component(net.kyori.adventure.text.Component)

Example 3 with WrappedChatComponent

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

the class OpenWindow method process.

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

Example 4 with WrappedChatComponent

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

the class BossBarUpper17 method process.

protected void process(PacketEvent packetEvent) {
    if (!hooked) {
        return;
    }
    PsrUser user = getEventUser(packetEvent);
    if (user == null) {
        return;
    }
    Object handle = packetEvent.getPacket().getHandle();
    try {
        Object action = actionField.get(handle);
        if (action == null) {
            return;
        }
        Field field = actionComponentField.get(action.getClass());
        if (field != null) {
            WrappedChatComponent wrappedChatComponent = WrappedChatComponent.fromHandle(field.get(action));
            String replacedJson = getReplacedJson(packetEvent, user, listenType, wrappedChatComponent.getJson(), filter);
            if (replacedJson != null) {
                wrappedChatComponent.setJson(replacedJson);
                field.set(action, wrappedChatComponent.getHandle());
            }
        }
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) WrappedChatComponent(com.comphenix.protocol.wrappers.WrappedChatComponent) PsrUser(me.rothes.protocolstringreplacer.api.user.PsrUser)

Example 5 with WrappedChatComponent

use of com.comphenix.protocol.wrappers.WrappedChatComponent in project ChangeSkin by games647.

the class SkinApplier method sendPacketsSelf.

private void sendPacketsSelf(WrappedGameProfile gameProfile) {
    PacketContainer removeInfo;
    PacketContainer addInfo;
    PacketContainer respawn;
    PacketContainer teleport;
    try {
        NativeGameMode gamemode = NativeGameMode.fromBukkit(receiver.getGameMode());
        WrappedChatComponent displayName = WrappedChatComponent.fromText(receiver.getPlayerListName());
        PlayerInfoData playerInfoData = new PlayerInfoData(gameProfile, 0, gamemode, displayName);
        // remove the old skin - client updates it only on a complete remove and add
        removeInfo = new PacketContainer(PLAYER_INFO);
        removeInfo.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
        removeInfo.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfoData));
        // add info containing the skin data
        addInfo = removeInfo.deepClone();
        addInfo.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER);
        // Respawn packet - notify the client that it should update the own skin
        respawn = createRespawnPacket(gamemode);
        // prevent the moved too quickly message
        teleport = createTeleportPacket(receiver.getLocation().clone());
    } catch (ReflectiveOperationException reflectiveEx) {
        plugin.getLog().error("Error occurred preparing packets. Cancelling self update", reflectiveEx);
        return;
    }
    sendPackets(removeInfo, addInfo, respawn, teleport);
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) WrappedChatComponent(com.comphenix.protocol.wrappers.WrappedChatComponent) PlayerInfoData(com.comphenix.protocol.wrappers.PlayerInfoData) NativeGameMode(com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode)

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