Core - Scoreboard Help?

Discussion in 'Spigot Plugin Development' started by DidactCraft, May 23, 2015.

  1. Hey

    So I've been tackling this error for about 30 minutes now and still can't figure out how to do it. What I want to do is display the number of kills a player has in a scoreboard. The scoreboard is fully setup and working but I'm not sure how to add the number of kills into it. I have created a hashmap so that I can check for a player's death in the playerdeath event and then if it's a player that killed them, add 1 to that players amount of kills. How do I call for this and implement it into my scoreboard?

    Here is my code >

    Thanks in advance!
  2. First, don't use Player for a hashmap, it cost a lot of memory leaks. For example use String (playername) or UUID.

    Second, when you put the kills in the hashmap change it to this: kills.put(uuid/playername(string), kills.get(uuid/playername) + 1); otherwise it will always stay 1.

    numofkills change it to this: kills.get(key); key = playername/uuid.

    Use for displayslot this: #setDisplaySlot(DisplaySlot.SIDEBAR);

  3. They don't. Developers do. Just remove the Player's entry when they quit the server, and you will be memory leak free.

    It's faster than using Strings, but slower than UUIDs. Though, I find them easier to use at times as I don't have to constantly have to append getUniqueId() to the lookups :p.