Mob drops

Discussion in 'Plugin Development' started by Pomppujatka, Dec 4, 2013.

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

    Pomppujatka

    Hi, I need some help with my plugin. The idea of the plugin is that when player kills mob and if the player has permission mob will drop some extra stuff
    So I was wondering how is possible to check if lastdamager is a player

    Code:
        @EventHandler
        public void onEs(EntityDeathEvent e) {
            Entity es = e.getEntity();
            if (es.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
                Player p = (Player) es.getLastDamageCause();
     
               
                if (es.getType() == EntityType.SHEEP) {
                                e.getDrops().add(new ItemStack(Material.GOLD_INGOT, 5));
                }
               
            }
    }
    Sorry for my bad English xD
     
  2. Offline

    MooshViolet

    You need to specify who you are giving the new drop to. You need to make it so it sets the player's inventory.
     
  3. you can use the java keyword "instanceof"

    Like:
    Object o="TEST";
    System.out.println(o instanceof Object);
    System.out.println(o instanceof Integer);
    System.out.println(o instanceof String);

    The output should be :

    true (because the object's class is a subclass of the Object class)
    false (because the object's class is not a subclass of the Integer class)
    true (because the object's class is the String class)

    To check that if the entity is a player, use:
    if(entity instanceof Player)
     
  4. Offline

    Pomppujatka

    How I can check if entity who hurted mob is instanceof player
    Code:
                if (?.getEntity instanceof Player) {
                Player p = (Player) es.getLastDamageCause();
     
  5. Offline

    boysnnoco

    Pomppujatka do if(e.getKiller() instanceof Player){
    Player p = (Player)e.getKiller();
    }
     
  6. Offline

    Pomppujatka

    boysnnoco I cant get killer from hurt event
     
  7. Offline

    Bart

    e.getEntity().getKiller()
     
Thread Status:
Not open for further replies.

Share This Page