Solved Scoreboard handling from a different plugin.

Discussion in 'Spigot Plugin Development' started by NavyDev, May 31, 2018.

  1. Very rarely these days do I have to come to Spigot asking for help. However, this one has stumped me and I'm sure I'm overlooking something super simple and likely overthinking. On that note though, I'd like some help on this issue.

    Effectively, I'm looking to create a snippet of code that handles the scoreboard of any plugins affecting the tab list within a server.

    The point of this code is to set a players scoreboard to an arena scoreboard and then restore the scoreboard a player had beforehand.

    What would be the best way to do this?

    Thank you in advance.
     
  2. Just store the data of the previous scoreboard somewhere just before generating the new one, and then when the arena scoreboard needs to be taken off create a new scoreboard object with the data stored and set that as the scoreboard.
     
    • Like Like x 1
  3. Yeah, I was thinking of just throwing it in a hashmap within a handler, then just set them back to that stored scoreboard. However, it didn't seem to work.
     
  4. What I'm trying to say is don't store the scoreboard, store the strings in a List and then make a new scoreboard with all those strings.
     
  5. It's a great idea, however, the way this works is that there is a scoreboard that everyone on the server is a part of (e.g the scoreboard from tablistPrefix), what I'm doing is setting certain players onto a new scoreboard and then I'm wanting to add them back to the scoreboard that a plugin such as tablistPrefix is using so everyone can see the same values on the tablist.

    I could set everyone onto that new scoreboard, but it seems a bit inefficient and there could be more efficient ways
     
  6. Why do you set players to a new scoreboard and then back to the tablist one if you want everyone to see the same values?
     
  7. Maximvdw

    Benefactor

    Scoreboards are handled (in my opinion) very badly in spigot. Spigot treats a scoreboard as a collection of objectives and teams - with one player only having one scoreboard.

    The reality is that Minecraft "Scoreboards" are actually objectives. Meaning objectives/teams are separate things that can be made in a way that it would never conflict.

    To solve your issue you would need to keep the scoreboard in memory , then create a new scoreboard and add your arena objective. After the game ends, just set the scoreboard back to the stored scoreboard
     
    • Winner Winner x 1
  8. Because if a server is using a plugin like TablistPrefix, it is unlikely they're wanting it to change globally all the time.

    I assume using a hashmap with player, scoreboard is sufficient, while also setting the scoreboard using #.getScoreboard() ?
     
  9. Maximvdw

    Benefactor

    Take a look at mcMMO scoreboard handeling
     
    • Like Like x 1
  10. Cheers, all fixed now. Your explanation of how spigot actually handles its scoreboard helped a lot. The way I was programming scoreboards before was that each player could have multiple scoreboards, as in I treated the TAB_LIST, SIDEBAR, etc as 3 separate scoreboards that I could edit as 3 instances, instead they're all under one scoreboard. Hence, the fact it didn't work beforehand.
     
  11. That's odd how this was so tough, scoreboards shouldn't be this complicated.
     
    • Agree Agree x 1
  12. Maximvdw

    Benefactor

    They are when 1 plugin wants to give all players the same scoreboard, and another wants to give them each their own scoreboard
     
  13. I get that it IS tough, my post was saying that it shouldn't be this tough. I am not disagreeing with anyone here, I was just making a statement :p
     
  14. I mostly send packets because the scoreboard API is kinda bloated. I don't really like it, and packets are more straightforward.

    That being said, good luck interacting with my plugins (Not that they are public, but whatever).
    The only way I see is to intercept packets, trace state and resend them afterwards - ie do what BungeeCord does.
     
    • Agree Agree x 1
  15. I will summarise what I did to fix the issue in case anyone in the future comes across the same issue.

    • Scoreboards should be treated as one per player (TAB_LIST, SIDEBAR, etc all come under the same scoreboard)
    • You can restore scoreboards by internally storing the player as the key and the scoreboard as the value.
      • (Then, of course, setting the players scoreboard back to the one you stored once you're finished)
    • Use teams, on the creation of your scoreboard then edit those teams when you're wanting to update a scoreboard, not scores & sending a whole new updated scoreboard
     
    • Informative Informative x 1