Solved Detect number of villagers

Discussion in 'Plugin Development' started by Zenok, Dec 30, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Zenok

    Hello, I'm trying to count the remaining villagers living. To do this I have a counter with the number of villagers have spawn, but when villagers die by a zombie I have not any way to detect that he has died.

    This happens in several games running at once, so I need to obtain out which game is usually to find out which item is use an ID stored in a string I can find out, but not in this case


    Code:java
    1. @EventHandler
    2. public void onDeath(EntityDeathEvent e) {
    3. Player player = (Player) e.getEntity().getKiller();
    4.  
    5.  
    6. if((e.getEntity().getKiller() instanceof Player)) {
    7. if(PlayerGame.containsKey(player.getName())) {
    8. int game = PlayerGame.get(player.getName());
    9. e.getDrops().clear();
    10. e.setDroppedExp(0);
    11. VILLAGE_ZOMBIES[game]--;
    12. CheckWaves(game);
    13. }
    14. } else {
    15. if(e.getEntityType() == EntityType.VILLAGER) {
    16. //I do not have any way to get the game Variable
    17. VILLAGE_VILLAGERS[game]--;
    18. }
    19.  
    20. }
    21.  
    22. }


    PlayerGame is an arraymap where I store in that game the player is

    PD: Sorry for my english :(
     
  2. Offline

    xTrollxDudex

    Zenok
    You can just loop through World#getEntities() and check instanceof Villager
     
  3. Offline

    Zenok

    The problem is that the games are on the same same map

    Maybe it would be a game suitable for every map?
     
  4. Offline

    xTrollxDudex

    Zenok
    Hmm, store his UUID and check it on EntityDeathEvent and remove it?
    PHP:
    Map<UUIDIntegermaps = new HashMap<UUIDInteger>();
     
    //add villagers to it
    Villager villager //.......
    maps.put(villager.gettUniqueId(), /* Arena id? */);
     
    //get villager on entity death
    if(maps.containsKey(event.getEntity().getUniqueId()))  {
        
    maps.remove(event.getEntity().getUniqueId());
    }
     
    //get villagers left in a map
    public int getVillagersAlive(int map) {
        
    int i 0;
        for(
    Map.Entry<UUIDIntegerent maps.entrySet()) {
            if(
    ent.getValue() == map) {
                
    i++;
            }
        }
        return 
    i;
    }
     
  5. Offline

    Zenok

    Oh, I did not know that the entities had an ID. Thanks. Solved
     
Thread Status:
Not open for further replies.

Share This Page