Solved Player kill mob event???

Discussion in 'Plugin Development' started by vhbob, Dec 4, 2015.

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

    vhbob

    Hey, the title mostly explains this, but how would i tell when a player kills a mob??? anyone know
     
  2. Offline

    Scimiguy

    EntityDeathEvent
     
  3. Offline

    vhbob

    @Scimiguy i know that, but how do i check if the player killed that mob??? would it be
    Code:
    @EventHandler
        public void getCoin1(EntityDeathEvent e) {
            Entity dead = e.getEntity();
            if (dead.getLastDamageCause() instanceof Player) {
               
            }
        }
     
  4. Offline

    Scimiguy

    EntityLiving#getKiller()
     
  5. Offline

    vhbob

    @Scimiguy what do you mean??? i have this and it does not work
    Code:
    @EventHandler
        public void getCoin1(EntityDeathEvent e) {
            Entity dead = e.getEntity();
            if (dead.getLastDamageCause() instanceof Player) {
                Player p = (Player) dead.getLastDamageCause();
                if (dead.getType().equals(EntityType.ZOMBIE)) {
                    giveCoins(p, 5);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "5" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.CREEPER)) {
                    giveCoins(p, 10);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "10" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.SPIDER)) {
                    giveCoins(p, 8);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "8" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.SKELETON)) {
                    giveCoins(p, 10);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "10" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.ENDERMAN)) {
                    giveCoins(p, 20);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "20" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.SLIME)) {
                    giveCoins(p, 1);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "1" + ChatColor.GRAY + " VC");
                }
            }
        }
    giveCoins method:
    Code:
    public void giveCoins(Player p, int i) {
            int bal = getConfig().getInt(p.getName() + "Bal");
            getConfig().set(p.getName() + "Bal", bal + i);
            saveConfig();
        }
     
  6. Offline

    blackpoiso

    @vhbob he means you need to get the killer. In your case, it would be dead.getKiller();
     
  7. Offline

    vhbob

    @blackpoiso there is no method called "getKiller();"
     
  8. Offline

    blackpoiso

    @vhbob there should be. Like Entity killer = e.getEntity().getKiller();
     
  9. Offline

    vhbob

    @blackpoiso so this should work???
    Code:
    @EventHandler
        public void getCoin1(EntityDeathEvent e) {
            Entity dead = e.getEntity();
            if (dead.getLastDamageCause() instanceof Player) {
                Player p = (Player) e.getEntity().getKiller();
                if (dead.getType().equals(EntityType.ZOMBIE)) {
                    giveCoins(p, 5);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "5" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.CREEPER)) {
                    giveCoins(p, 10);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "10" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.SPIDER)) {
                    giveCoins(p, 8);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "8" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.SKELETON)) {
                    giveCoins(p, 10);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "10" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.ENDERMAN)) {
                    giveCoins(p, 20);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "20" + ChatColor.GRAY + " VC");
                }
                if (dead.getType().equals(EntityType.SLIME)) {
                    giveCoins(p, 1);
                    p.sendMessage(ChatColor.GRAY + "You reviced " + ChatColor.GOLD + "1" + ChatColor.GRAY + " VC");
                }
            }
        }
     
  10. Offline

    blackpoiso

    @vhbob I was thinking something more like this:
    Code:
    @EventHandler
      public void onDeath(EntityDeathEvent e){
        Entity entity = e.getEntity();
        Entity killer = e.getEntity().getKiller();
      
        if (killer instanceof Player){
          //your code
        }
      }
     
  11. Offline

    vhbob

  12. Offline

    blackpoiso

    @vhbob good, glad to hear :D
     
  13. Offline

    Scimiguy

    Then mark this thread as solved
     
    blackpoiso likes this.
Thread Status:
Not open for further replies.

Share This Page