Message above the xp bar

Discussion in 'Plugin Development' started by Mathie, Feb 5, 2016.

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


    Hello !

    I have been working this morning on a countdown.
    I display on my screen the countdown and the exp bar.

    Now I'd like to display a message for a long time above the item's name. I use this function:

        public static void sendActionBar(Player player, String message){
            CraftPlayer p = (CraftPlayer) player;
            IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + message + "\"}");
            PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte) 2);;
            ((CraftPlayer) p).getHandle().playerConnection.sendPacket(ppoc);
    So no worries, ALL WORKS.
    Except that the message appears only 3 seconds. I want to know how to make the message is displayed all the time until I give it a new setting?

    Thanks !
  2. Offline


    I suggest you just keep sending this packet with a scheduler:

        public void runText(){
            Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable(){
                public void run(){
                    MyClass.sendActionBar(player, message);
            }, 0, 40);
    What this does it sends the player this text every 2 seconds (40 ticks = 2 seconds).
    This will keep the message like constant. Just run this method wherever you want to send the constant message.
Thread Status:
Not open for further replies.

Share This Page