Development Assistance Header, Footer and Titles 1.8 coding

Discussion in 'Plugin Help/Development/Requests' started by WingedMLGPro, May 17, 2015.

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

    WingedMLGPro

    Hey Guys,
    I want to know how to do titles and tab header and footers!
    I have no idea how to do this so any help will be appreciated!
    Thanks,
    WingedMLGPro
     
  2. The titles can be done with the packet PacketPlayOutTitle and the header/footer with PacketPlayOutPlayerListHeaderFooter. e.g.:
    Code:
    PacketPlayOutTitle times = new PacketPlayOutTitle(<fadeIn>, <display>, <fadeout>); //The time the title is displayed in ticks
    PacketPlayOutTitle title = new PacketPlayOutTitle(EnumTitleAction.TITLE, ChatSerializer.a("\"§6Cookies!\""));
    PacketPlayOutTitle subtitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, ChatSerializer.a("\"§cThey're delicious!\""));
    for(Packet packet : new Packet[] {times, title, subtitle}) {
        ((CraftPlayer) <playertosend>).getHandle().playerConnection.sendPacket(packet);
    }
    PacketPlayOutPlayerListHeaderFooter headerfooter = new PacketPlayOutPlayerListHeaderFooter();
    try {
        Field header = headerfooter.getClass().getDeclaredField("a");
        Field footer = headerfooter.getClass().getDeclaredField("b");
        header.setAccessible(true);
        footer.setAccessible(true);
        header.set(headerfooter, ChatSerializer.a("\"§3Welcome to a server!\""));
        footer.set(headerfooter, ChatSerializer.a("\"§aI'm a footer!\""));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    ((CraftPlayer) <playertosend>).getHandle().playerConnection.sendPacket(headerfooter);
     
  3. Offline

    WingedMLGPro

    @megamichiel Would i put that in a Join Listener and also does that work with 1.8.3?
     
  4. @WingedMLGPro
    You can put it anywhere, and the titles and tab list headers/footers are especially for MC 1.8+. But if you do put it in the join listener, you have to put a little delay or the player won't recieve the packet properly
     
  5. Offline

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
  6. Offline

    WingedMLGPro

    @megamichiel when i do a command, it doesnt work! Here is my code:
    Code:
    package me.benkea.Test;
    
    import net.minecraft.server.v1_8_R2.IChatBaseComponent;
    import net.minecraft.server.v1_8_R2.Packet;
    import net.minecraft.server.v1_8_R2.PacketPlayOutPlayerListHeaderFooter;
    import net.minecraft.server.v1_8_R2.PacketPlayOutTitle;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    
    import java.lang.reflect.Field;
    
    /**
    * © This Document and Code is STRICTLY copyrited(©) to Ben.
    * © If anyone takes any part of this code and uses it for
    * © Something public, Share with someone, uses it for API's,
    * © implementing it to their code and taking the rights for
    * © it is NOT allowed unless you get permission from me!
    * © This project SwiftyHub was created by 35047
    * © at 17/05/15 at 5:59 PM
    */
    public class TestCmd implements CommandExecutor {
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    
            Player p = (Player)sender;
    
            if (cmd.getName().equalsIgnoreCase("tester")){
                p.sendMessage("OK!");
                PacketPlayOutTitle times = new PacketPlayOutTitle(5, 60, 5); //The time the title is displayed in ticks
                PacketPlayOutTitle title = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, IChatBaseComponent.ChatSerializer.a("\"§6Cookies!\""));
                PacketPlayOutTitle subtitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, IChatBaseComponent.ChatSerializer.a("\"§cThey're delicious!\""));
                for(Packet packet : new Packet[] {times, title, subtitle}) {
                    ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
                }
                PacketPlayOutPlayerListHeaderFooter headerfooter = new PacketPlayOutPlayerListHeaderFooter();
                try {
                    Field header = headerfooter.getClass().getDeclaredField("a");
                    Field footer = headerfooter.getClass().getDeclaredField("b");
                    header.setAccessible(true);
                    footer.setAccessible(true);
                    header.set(headerfooter, IChatBaseComponent.ChatSerializer.a("\"§3Welcome to a server!\""));
                    footer.set(headerfooter, IChatBaseComponent.ChatSerializer.a("\"§aI'm a footer!\""));
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                ((CraftPlayer) p).getHandle().playerConnection.sendPacket(headerfooter);
            }
            return true;
        }
    }
    
     
  7. Offline

    WingedMLGPro

    @megamichiel No, it does the thing where in white it says /tester
     
  8. @WingedMLGPro
    In your onEnable call "getCommand(<commandname).setExecutor(<command class>)", so bukkit knows which class handles the execution of the command
     
  9. Offline

    WingedMLGPro

    @megamichiel I did that! It just doesnt work for some reason
     
  10. Offline

    WingedMLGPro

    @megamichiel Do you want me too send you my main and command again?

    @megamichiel I figured out it was the code you sent me at the top that was bugging it.
    I dont think that code works!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  11. @WingedMLGPro
    No matter how many errors occur, everything that happens before it gets performed normally, so there's something not properly done if you're still seeing the white command message.
     
Thread Status:
Not open for further replies.

Share This Page