Chang guis title using protocollib

Discussion in 'Plugin Development' started by 1461748123, Mar 4, 2015.

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

    1461748123

    Hi guys! I'm trying to change the GUI title with protocollib.
    But I have no idea how to read the gui names.

    I tried
    Code:
    ProtocolLibrary.getProtocolManager().addPacketListener(new PacketListener() {
                public Plugin getPlugin() {
                    return Bukkit.getPluginManager().getPlugin("ProtocolLibTest");
                }
    
                public ListeningWhitelist getReceivingWhitelist() {
                    return ListeningWhitelist.newBuilder().gamePhase(GamePhase.PLAYING).highest().types(PacketType.Play.Server.OPEN_WINDOW).build();
                }
    
                public ListeningWhitelist getSendingWhitelist() {
                    return ListeningWhitelist.newBuilder().gamePhase(GamePhase.PLAYING).highest().types(PacketType.Play.Server.OPEN_WINDOW).build();
                }
    
                public void onPacketReceiving(PacketEvent e) {
                    return;
                }
    
                @Override
                public void onPacketSending(PacketEvent e) {
                    if (!(e.getPacket().getType() == PacketType.Play.Server.OPEN_WINDOW))
                        return;
                    PacketContainer wrapper = e.getPacket();
                    System.out.println(wrapper.getStrings().read(1));
       
                    // wrapper.getStrings().writeSafely(3, invTitle);
                    // e.setPacket(wrapper);
                    // setMenuTitle = false;
                }
    
            });
    But it only return minecraft:chest
    When I read 1, it show up this:
    upload_2015-3-4_15-21-30.png

    I want to read and set the "c", can any one help me out?
     
  2. Offline

    Skionz

    @1461748123
    Use reflection to get the field and change it. Here is an example:
    I will use this class
    Code:
    public class Stuff {
        private String stuff = "hello";
    }
    Here is how you would get the field 'stuff' and change the value
    Code:
    public static void main(String[] args) {
        Stuff object = new Stuff();
        Field field = Stuff.class.getDeclaredField("stuff"); //Gets the field
        field.setAccessible(true); //Lets us modify it
        field.set(object, "The New Value"); //Changes the value of 'stuff' in the object we created above
    }
     
  3. Offline

    1461748123

    @Skionz

    Can you help me out?
    I have no idea how to do it.
    I tried this and it gives me error:
    Code:
    Field field = e.getPacket().getClass().getDeclaredField("c");
                        field.setAccessible(true);
                        System.out.println(field.getType());


    upload_2015-3-4_20-47-31.png
     
Thread Status:
Not open for further replies.

Share This Page