How to get a variable to increase when you kill a mob?

Discussion in 'Spigot Plugin Help' started by Bluehawk409, Sep 10, 2020.

  1. I have another post about this plugin, but this is a different question. I am making a plugin that when a player kills an entity, it increases an integer called souls unique to them, but this code is not working for some reason?
    Code (Text):
        public class MobListener implements Listener {
         
            public static Map<Player, Integer> soulsmap = new HashMap<>();
            public int souls = 0;
         
    @EventHandler
    public void onEntityDeath(EntityDeathEvent event) {

     
            Entity mob = event.getEntity();
     
            if(mob.getLastDamageCause() instanceof Player) {
         
                Player player = ((LivingEntity) mob).getKiller();
                souls = souls + 1;
             
                soulsmap.put(player, souls);
             
             
            }
        }

    }
     
  2. soulsmap.put(player, soulsmap.get(player)+1)
     
  3. You have to put integer on HashMap for any players one by one
    Code (Text):
        public class MobListener implements Listener {
       
            public static Map<Player, Integer> soulsmap = new HashMap<>();
            public int souls = 0;
       
    @EventHandler
    public void onEntityDeath(EntityDeathEvent event) {

            Entity mob = event.getEntity();
            if(mob.getLastDamageCause() instanceof Player) {
       
                Player player = ((LivingEntity) mob).getKiller();
                souls = soulsmap.get(player);
                souls+=1;
                soulsmap.remove(player);
                soulsmap.put(player, souls);
           
           
            }
        }
       
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent event){
       
        Player player = event.getPlayer();
        soulsmap.putIfAbsent(player,0);
       
    }


    }
    try this it must be works