Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5210

Villager not taking arrow damage from EntityDamageByEntityEvent

    XMLWordPrintable

Details

    • Paper version git-Paper-639 (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT)
    • 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());
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            mapokapo Leo Petrovic
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: