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
You need to specify who you are giving the new drop to. You need to make it so it sets the player's inventory.
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)
How I can check if entity who hurted mob is instanceof player Code: if (?.getEntity instanceof Player) { Player p = (Player) es.getLastDamageCause();