Scoreboard Kills Mob

Discussion in 'Spigot Plugin Development' started by maxouland1, 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){
    if(Hashmap.contains(e.getEntity().getKiller()){
    Hashmap.put(e.getEntity().getKiller(), Hashmap.get(e.getEntity().getKiller())+1);
    }else{
    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. You're welcome;)
     
  4. 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
  5. You're right. But to use the players name is deprecated so I would use UUID.
     
  6. No, it's not? Use string as key and when you put/get use p.getName();
    I always use it for minigames.
     
  7. You shouldn't .
     
  8. getPlayer(String) is deprecated. If you save the name you'll have to use this method to get the player.
     
  9. Yeah, if you want a player from a string. But you can just use it for example, how many players in-game.
     
  10. No, if you have a list you only have to do, list.size(), player name shouldn't be used.
     
  11. 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