Solved Bukkit title lagg/bugg?

Discussion in 'Plugin Development' started by Banjer_HD, Jan 2, 2017.

Thread Status:
Not open for further replies.
  1. Problem:
    I am making a plugin where you can have an title + multiple line subtitle.
    If I am walking all the titles will go away, only the first title will show up... the debug lines still work...

    Code:
    Code:
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
    
            final Player p = e.getPlayer();
    
            //TABLIST:
            IChatBaseComponent headerText = ChatSerializer.a("{\"text\":\"" + utils.toColor(plugin.getConfig().getString("tablist.header")) + "\"}");
            IChatBaseComponent footerText = ChatSerializer.a("{\"text\": \"" + utils.toColor(plugin.getConfig().getString("tablist.footer")) + "\"}");
    
    
           PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
    
           try {
    
               Field headerField = packet.getClass().getDeclaredField("a");
               headerField.setAccessible(true);
               headerField.set(packet, headerText);
               headerField.setAccessible(!headerField.isAccessible());
    
               Field footerField = packet.getClass().getDeclaredField("b");
               footerField.setAccessible(true);
               footerField.set(packet, footerText);
               footerField.setAccessible(!footerField.isAccessible());
      
           } catch (Exception er) {
               er.printStackTrace();
           }
    
            ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packet);
    
    
    
            //TITLE:
          
                    if(p.hasPlayedBefore()) {
              
                        p.sendTitle(config.getString("test1"), config().getString("test2"), 0, plugin.getConfig().getStringList("onjoin.subtitles").size() * 20, 0);
              
                    }else {
              
               
                      p.sendTitle("Welcome" + config.getString("test1"), config().getString("test2"), 0, plugin.getConfig().getStringList("onjoin.subtitles").size() * 20, 0);
              
                    }
    
    
    
            //TODO: HERE ARE THE SUBTITLES
            new BukkitRunnable() {
                int next = 0;
      
                public void run() {
                    if(plugin.getConfig().getStringList("onjoin.subtitles").size() >= next + 1) {
              
                        String s = plugin.getConfig().getStringList("onjoin.subtitles").get(next);
                        Bukkit.broadcastMessage("Next: " + next);
              
                        if(next + 1 == plugin.getConfig().getStringList("onjoin.subtitles").size()) {
                  
                      p.sendTitle(s, s, 0, 20 - 10, 10);
                  
                        }else {
                  
                      p.sendTitle(s, s, 0, 20, 0);
                  
                        }
              
                        next++;
              
                    }else {
                        this.cancel();
                    }
                }
            }.runTaskTimer(plugin, 0, 20);
    
    
        }
    
     
    Last edited: Jan 3, 2017
  2. Offline

    Zombie_Striker

    @Banjer_HD
    If you are using 1.9+, you can use the Player#sendTitle() method to handle packets for you. It's easy, reduces a ton of lines, and doing it that way will means it will work on multiple versions of bukkit.
     
  3. Thanks! @Zombie_Striker
    Changed the code in the thread...
    But it is still not solved...
     
    Last edited: Jan 3, 2017
  4. Offline

    Zombie_Striker

    @Banjer_HD
    What do you mean by subtitles? Subtitles, in regards to MC and bukkit, is the second parameter for the sendTitle method (the "test2"). Are you referring to that, or what you labeled as "subtitles"?
     
  5. Thanks for your reaction! Yes, I did mean subtitle as in the seccond line of player#sendTitle()... With multiple line, I mean:

    First second:
    Code:
    Hello + Name
    News1
    
    1 second after:
    Code:
    Hello + Name
    News2
    
    And that for all the strings in a list in the config...

    Thanks again for reading! ;) xD
     
    Last edited: Jan 3, 2017
Thread Status:
Not open for further replies.

Share This Page