Hello! I'm making plugin that edits damage on tools. This my code: Code: EntityDamageEvent dmgevent = new EntityDamageEvent(player, DamageCause.ENTITY_ATTACK, (double) 20); victim.setLastDamageCause(dmgevent); According to this code a tool must kill entities from one hit. But when I hit entities - the damage doesn't 20. I also tried to print the damage in chat - it was 20. But I hitted entity several times to kill it. What I am doing wrong? Thanks in advance.
@VENTO Are you trying to listen to the DamageEvent here? If you are, you are doing it wrong. Read up on this tutorial: https://wiki.bukkit.org/Event_API_Reference
I'm listenening to EntityDamageByEntityEvent. Then check if player has a tool in his hand and gets the victim and setting last damage cause to this victim.
Code: @EventHandler public void onAttack(EntityDamageByEntityEvent e) { if (e.getDamager() instanceof Player) { Player attacker = (Player) e.getDamager(); Entity victim = e.getEntity(); if (FriendUtils.isFriend(attacker, victim.getName())) { e.setCancelled(true); } else { setDamageByMelee(attacker, victim); //DAMAGE } } } private static void setDamageByMelee(Player attacker, Entity victim) { ItemStack item = attacker.getItemInHand(); if (item == null) { return; } ColdWeapon coldweapon = MeleeUtils.getMelee(item, attacker); //CHECKING IF IT'S COLDWEAPON if (coldweapon == null) { return; } coldweapon.onHit(victim); //DAMAGING ENTITY } public void onHit(Entity victim) { EntityDamageEvent dmgevent = new EntityDamageEvent(p, DamageCause.ENTITY_ATTACK, (double) 20); victim.setLastDamageCause(dmgevent); }