[SPIGOT-5210] Villager not taking arrow damage from EntityDamageByEntityEvent Created: 24/Jul/19  Updated: 24/Jul/19  Resolved: 24/Jul/19

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Leo Petrovic Assignee: Unassigned
Resolution: Invalid Votes: 0
Labels: EntityDamageByEntityEvent, attack, entity, spigot, villager
Environment:

 

 

 


Version: Paper version git-Paper-639 (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT)
Guidelines Read: Yes

 Description   

I've been trying to make a test dummy plugin for seeing how much damage a weapon/arrow does to a special test dummy entity, but for some reason, arrows fired at the test dummy (villager) just bounce off. The event works fine for melee hits, but not for projectiles.

Something to note is that this persists until the server is restarted, after which the damage detection works as expected.

Another problem is that the Villager.setProfession() method works unreliably and has unexpected results, as you can still trade with a villager even when it's profession has been set to Nitwit, with the resulting profession being set randomly.

The test dummy (villager) is summoned with a command, as seen below:

public boolean onCommand(CommandSender sender, Command command, String label, String[] args3) {
   if (!(sender instanceof Player)) return false;
   Player player = (Player) sender;
   Villager dummy = (Villager) player.getWorld().spawnEntity(player.getLocation(), EntityType.VILLAGER);
   dummy.setInvulnerable(true);
   dummy.setProfession(Profession.NITWIT);
   dummy.setCollidable(false);
   dummy.setAI(false);
   dummy.setBreed(false);
   dummy.setCanPickupItems(false);
   dummy.setCustomName(ChatColor.AQUA + "Test Dummy");
   dummy.setCustomNameVisible(true); dummy.setRemoveWhenFarAway(false);
   dummy.setSilent(true);
   player.sendMessage(ChatColor.GREEN + "Successfully spawned 1 Test Dummy!");
   return true;
}

And the attack event listener, here:

public void onEntityAttackDummy(EntityDamageByEntityEvent e) {
   if (!(e.getEntity().getType().equals(EntityType.VILLAGER)
      && e.getEntity().getName().equals(ChatColor.AQUA + "Test Dummy")))
      return;
   Player player = null;
   Arrow arrow = null;
   if (e.getDamager() instanceof Arrow) {
      arrow = (Arrow) e.getDamager();
      if (arrow.getShooter() instanceof Player) {
         player = (Player) arrow.getShooter();
         player.sendMessage(ChatColor.DARK_GREEN + "Damage Dealt: " + ChatColor.YELLOW + e.getDamage());
      }
   }
   if (e.getDamager() instanceof Player) {
      player = (Player) e.getDamager();
      player.sendMessage(ChatColor.DARK_GREEN + "Damage Dealt: " + ChatColor.YELLOW + e.getDamage());
   }
   LivingEntity le = (LivingEntity) e.getEntity();
   le.setHealth(le.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
}


 Comments   
Comment by md_5 [ 24/Jul/19 ]

Not running spigot; not following instructions; bug looks to be in plugin code.

Generated at Fri Apr 11 15:30:03 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.