Scoreboard Kills Mob

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

  1. Hello,
    I code a plugin and I want to put a scoreboard with the number of killed zombie.
    How to do?
    Thank you ^^
  2. Create a Hashmap with the key Player and the Value int (Player, amount of killed Zombies) and then put int the EntityDeathEvent the following code :
    Code (Text):
    if(e.getEntity() instanceof Zombie && e.getEntity().getKiller instanceof Player){
    Hashmap.put(e.getEntity().getKiller(), Hashmap.get(e.getEntity().getKiller())+1);
    Hashmap.put(e.getEntity().getKiller(), 1);
    now you only need to create the Scoreboard and add the values to it.

    (Code is untested, wrote from my mobile phone)
  3. Ok thank you ^^
  4. You're welcome;)
  5. Don't use Player as key. It cost a lot of memory leaks (playername, skin, uuid etc.). Just use UUID or Playername. ++ faster!
    • Agree Agree x 1
  6. You're right. But to use the players name is deprecated so I would use UUID.
  7. No, it's not? Use string as key and when you put/get use p.getName();
    I always use it for minigames.
  8. You shouldn't .
  9. getPlayer(String) is deprecated. If you save the name you'll have to use this method to get the player.
  10. Yeah, if you want a player from a string. But you can just use it for example, how many players in-game.
  11. No, if you have a list you only have to do, list.size(), player name shouldn't be used.
  12. Use Player. No memory leaks, given OP knows how to remove Players from the Map on PlayerQuitEvent. Also, it's faster than Strings and a tad more readable than UUIDs.
    • Funny Funny x 1