Solved Default text and reading text from packets

Discussion in 'Plugin Development' started by Tim_M, Sep 19, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Tim_M

    I'll cut to the chase, so basically, I am sending a Playoutopensigneditor packet thing to get a text input from players. I setup a packet listener with protocolLib for whenever the player was done. It works, (I tested) but I don't know how to get the text from the PacketEvent that the player typed. Also I don't know how to set text to appear when the player first gets the signgui opened. I googled, but to no avail. If there is a thread with the solution I need, please post it.

    Code to send the packet:
    Code:
    void openSign(Player player, String[] defaults)
        {
            BlockPosition pos = new BlockPosition(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
            PacketPlayOutOpenSignEditor packet = new PacketPlayOutOpenSignEditor(pos);
            CraftPlayer craftPlayer = (CraftPlayer) player;
          
            craftPlayer.getHandle().playerConnection.sendPacket(packet);
        }
    Code to check for packet:
    Code:
    public void listenPackets()
        {
            Main.pm.addPacketListener(new PacketAdapter(Main.instance, ListenerPriority.NORMAL, PacketType.Play.Client.UPDATE_SIGN)
                    {
                        @Override
                        public void onPacketReceiving(PacketEvent event)
                        {
                            PacketContainer packet = event.getPacket();
                            Bukkit.broadcastMessage(packet.getModifier().getValues().get(0).toString());
                        }
                    });
        }
    I appreciate any answers :p

    This information is no longer relevant, so I'll Mark it solved
     
    Last edited: Dec 12, 2020
  2. Offline

    KarimAKL

    @Tim_M Could you post your current code?
     
  3. Offline

    Tim_M

    Sure, but I can't rn.

    Edit: done its in the original post
     
    Last edited: Sep 19, 2020
  4. Offline

    Tim_M

    Bump :/
     
  5. Offline

    Tim_M

    Bump

    Well, I'm still waiting for help...
     
  6. Offline

    Wick

    Try this

    Code:java
    1. PacketContainer packet = event.getPacket();
    2. String[] lines = packet.getStringArrays().read(0);
     
  7. Offline

    Tim_M

    It doesnt work... Just prints this error:

    Code:
    [12:16:35 WARN]: FieldAccessException: No field with type [Ljava.lang.String; exists in class PacketPlayInUpdateSign.
    
    [12:16:35 WARN]:     at com.comphenix.protocol.reflect.StructureModifier.readInternal(StructureModifier.java:216)
    
    [12:16:35 WARN]:     at com.comphenix.protocol.reflect.StructureModifier.read(StructureModifier.java:195)
    
    [12:16:35 WARN]:     at me.Tim_M.MysticalSkyWars.PacketEventClass$1.onPacketReceiving(PacketEventClass.java:24)
    
    [12:16:35 WARN]:     at com.comphenix.protocol.injector.SortedPacketListenerList.invokeReceivingListener(SortedPacketListenerList.java:114)
    
    [12:16:35 WARN]:     at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketRecieving(SortedPacketListenerList.java:67)
    
    [12:16:35 WARN]:     at com.comphenix.protocol.injector.PacketFilterManager.handlePacket(PacketFilterManager.java:590)
    
    [12:16:35 WARN]:     at com.comphenix.protocol.injector.PacketFilterManager.invokePacketRecieving(PacketFilterManager.java:557)
    
    [12:16:35 WARN]:     at com.comphenix.protocol.injector.netty.ProtocolInjector.packetReceived(ProtocolInjector.java:350)
    
    [12:16:35 WARN]:     at com.comphenix.protocol.injector.netty.ProtocolInjector.onPacketReceiving(ProtocolInjector.java:315)
    
    [12:16:35 WARN]:     at com.comphenix.protocol.injector.netty.ChannelInjector.decode(ChannelInjector.java:538)
    
    [12:16:35 WARN]:     at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:249)
    
    [12:16:35 WARN]:     at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:149)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    
    [12:16:35 WARN]:     at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    
    [12:16:35 WARN]:     at com.comphenix.protocol.injector.netty.ChannelInjector$2.channelRead(ChannelInjector.java:259)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    
    [12:16:35 WARN]:     at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    
    [12:16:35 WARN]:     at io.netty.handler.timeout.ReadTimeoutHandler.channelRead(ReadTimeoutHandler.java:150)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333)
    
    [12:16:35 WARN]:     at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319)
    
    [12:16:35 WARN]:     at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:787)
    
    [12:16:35 WARN]:     at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130)
    
    [12:16:35 WARN]:     at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    
    [12:16:35 WARN]:     at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    
    [12:16:35 WARN]:     at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    
    [12:16:35 WARN]:     at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    
    [12:16:35 WARN]:     at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
    
    [12:16:35 WARN]:     at java.lang.Thread.run(Thread.java:748)
     
  8. Offline

    Wick

    What Minecraft version are you on?
     
  9. Offline

    Tim_M

    1.8.9 Bukkit

    Also bump
     
  10. Offline

    Wick

    Hard to find 1.8 packet information, try

    Code:java
    1. packet.getChatComponentArrays().read(0);


    EDIT: Yep, that should be it looking at the decompiled PacketPlayOutUpdateSign for 1.8.8
     
  11. Offline

    Tim_M

    It actually works! Thank you so much!

    But how would I go about setting some default text on the sign?
     
  12. Offline

    Wick

    Something similar pretty much, instead youre using packetplayout

    Code:java
    1.  
    2. PacketContainer packetPlayOutSign = new PacketContainer(PacketType.Play.Server.UPDATE_SIGN);
    3. WrappedChatComponent[] wrappedChatComponent = {WrappedChatComponent.fromText("Line1"), WrappedChatComponent.fromText("Line2"), WrappedChatComponent.fromText("Line3"), WrappedChatComponent.fromText("Line4")};packetPlayOutSign.getChatComponentArrays().write(0, wrappedChatComponent);
    4.  


    ^^ I think
     
    Last edited: Oct 6, 2020
  13. Offline

    Tim_M

    This is the code I have right now, gives a field exception when ran:
    Code:
    Main.pm.addPacketListener(new PacketAdapter(Main.instance, ListenerPriority.NORMAL, PacketType.Play.Server.OPEN_SIGN_EDITOR)
            {
                @Override
                public void onPacketSending(PacketEvent event)
                {
                    PacketContainer packet = event.getPacket();
    
                    ArrayList<WrappedChatComponent> linesList = new ArrayList<WrappedChatComponent>();
                  
                    linesList.add(WrappedChatComponent.fromText(ChatColor.GREEN + "" + ChatColor.BOLD + "Set map name"));
                    linesList.add(WrappedChatComponent.fromText(ChatColor.DARK_GREEN + "on lines 3 & 4"));
                    linesList.add(WrappedChatComponent.fromText(""));
                    linesList.add(WrappedChatComponent.fromText(""));
                  
                    WrappedChatComponent[] lines = new WrappedChatComponent[0];
                  
                    linesList.toArray(lines);
                  
                    packet.getChatComponentArrays().write(0, lines);
                }
            });
        }
    PS. Your code resulted in nothing happening. Also PacketType.Server.UPDATE_SIGN is deprecated.
     
  14. Offline

    Wick

    You also need to fill in location data I believe, do some googling and play around with it. It's deprecated because it was removed past 1.8 I think. May be wrong though.
     
  15. Offline

    Tim_M

    So I slightly changed my code when creating the packet to this:
    Code:
    void openSign(Player player, String[] defaults)
        {
            //BlockPosition pos = new BlockPosition(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
            //PacketPlayOutOpenSignEditor packet = new PacketPlayOutOpenSignEditor(pos);
            //CraftPlayer craftPlayer = (CraftPlayer) player;
          
            PacketContainer container = Main.pm.createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR);
          
            //ArrayList<WrappedChatComponent> linesList = new ArrayList<WrappedChatComponent>();
          
    //        linesList.add(WrappedChatComponent.fromText(ChatColor.GREEN + "" + ChatColor.BOLD + "Set map name"));
    //        linesList.add(WrappedChatComponent.fromText(ChatColor.DARK_GREEN + "on lines 3 & 4"));
    //        linesList.add(WrappedChatComponent.fromText(""));
    //        linesList.add(WrappedChatComponent.fromText(""));
    //      
    //        WrappedChatComponent[] lines = new WrappedChatComponent[0];
    //      
    //        lines = linesList.toArray(new WrappedChatComponent[linesList.size()]);
          
            //container.getChatComponentArrays().write(0, lines);
            Bukkit.broadcastMessage(container.getModifier().getValues().toString());
            try
            {
                Main.pm.sendServerPacket(player, container);
            }
            catch (InvocationTargetException e)
            {
                e.printStackTrace();
            }
        }
    It appears that it is impossible to set the text in a openSignEditorPacket, because it contains no strings, IChatCompoments and WrappedChatComponents to write. Im a little confused.

    How would I go about knowing what sign to expect from who? I dont want all signs places to be counted.

    Bump it is
     
    Last edited: Oct 25, 2020
  16. Offline

    Tim_M

    Also bump :p
     
Thread Status:
Not open for further replies.

Share This Page