Solved Adding online player names on tab

Discussion in 'Spigot Plugin Development' started by Lookups, Aug 11, 2018.

  1. Removed
    #1 Lookups, Aug 11, 2018
    Last edited: Aug 11, 2018
  2. Bump - Still can't seem to find a solution :unsure:
  3. Use a forloop for all the online players.
  4. Yes, but how, i'd need to set the amount of slot of the tab, example:
    First Line:
    Code (Text):
    tab.setSlot(1, "HELLO");
    This'd result in:

    HELLO, *blank*, *blank*
  5. As i've already said, i can make a custom tab, but i can't seem to add players on the tablist, i've tried:

    Code (Text):
    tab.setSlot(1, Bukkit.getOnlinePlayers()[0].getName());
    tab.setSlot(2, Bukkit.getOnlinePlayers()[1].getName());
    tab.setSlot(3, Bukkit.getOnlinePlayers()[2].getName());
    1) I think, it's much of code; i think it can be slimmer
    2) I'd need to make a check for how much players are online, that'd make the code about 300+ lines more, wich could be easier done i think.
  6. Code (Text):
    int i = 0;
    Bukkit.getOnlinePlayers().forEach(player -> {
         tab.setSlot(i, player.getName());
    Code (Java):
    int count = 0;
    for (Player p : Bukkit.getOnlinePlayers()){
          tab.setSlot(count, p.getName());
    #7 TheWisePotato, Aug 11, 2018
    Last edited: Aug 11, 2018
  7. I'm currently coding for an 1.7.x server, and forEach doesn't work for Bukkit#getOnlinePlayers() on that spigot version.
  8. Use a forloop then, it does the same
  10. Look at my most recent post, it's edited.
  11. This would be the forloop
    Code (Text):
    For (Player player : Bukkit.getOnlinePlayers()) {

    //the tablist code

  12. He knows that, he needs to make the slot increase every time though, which I have already posted.
  13. Thanks, i'll try it in a second.

    I know how to make a for loop
  14. Why arent you using it then if foreach doesnt work for you
  15. TheWisePotato explained it
  16. Having a new problem -

    Code (Text):
    [22:47:50 WARN]: Exception in thread "Craft Scheduler Thread - 152"
    [22:47:50 WARN]: org.apache.commons.lang.UnhandledException: Plugin Slut v3.0 generated an exception while executing task 44
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor$ Source)
            at Source)
    Caused by: java.lang.NullPointerException
            at nv6.tablist.adapter.TablistAdapter.addTabEntry(
            at me.im97p.hcfactions.Base$
            ... 3 more
    Line 52 -
    Code (Text):
    if(mode.hcf.contains(player)) {

    Defined "mode" at -

    Code (Text):
        static TablistMode mode;
    Defined the HashMap hcf at:

    Code (Text):
        public ArrayList<Player> hcf = new ArrayList<Player>();
  17. Please provide the full class
  18. Why do you want the full class while you only need that piece of code? :unsure:
  19. In that case il just say you never definded mode so ofc it returnes null. Where not some kind of magical wizzards that know exactly what you code is and what you want to achieve.