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

EntityTransformEvent for cured ZombieVillager and drowning Zombies fires each tick if it was cancelled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • This server is running CraftBukkit version git-Spigot-1981d55-860b354 (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)
    • Yes

      Cancelling EntityTransformEvent for Zombie Villager isn't doing anything to prevent it from firing next tick.

      How to reproduce

      @EventHandler
      public void onEntityTransform(EntityTransformEvent e) {
        if(e.getTransformReason() == EntityTransformEvent.TransformReason.CURED) {
          e.setCancelled(true);
          Bukkit.getLogger().info("Event was cancelled!"); //Enjoy flooded console
          //I was spawning a new Villager here. Almost killed my server with whole horde :O
          //Currently, developers need to manually kill zombie here to prevent this event
        }
      }

      Code analysis

      Each tick, EntityZombieVillager checks if conversionTime is less or equal than 0, and calls method a(WorldServer). From this method, Bukkit fires EntityTransformEvent and checks if it was cancelled, but instead of resetting conversion status, it just uses return.

      Possible fix

      Reset conversion status and remove strength effect from zombie.

      if (CraftEventFactory.callEntityTransformEvent(this, entityvillager, EntityTransformEvent.TransformReason.CURED).isCancelled()) {
          this.getDataWatcher().set(EntityZombieVillager.CONVERTING, false);
          this.removeEffect(MobEffects.INCREASE_DAMAGE, EntityPotionEffectEvent.Cause.CONVERSION);
          return;
      }

       

       

            Unassigned Unassigned
            prettydude prettydude
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: