setNoDamageTicks Seems to be completely broken?

Discussion in 'Spigot Plugin Development' started by FlyingLlama, Jun 10, 2015.

  1. Sometime between 1.7 and 1.8, setNoDamageTicks has been rendered completely nonfunctional, as far as i can tell from extensive testing and looking at various threads (example: https://bukkit.org/threads/tutorial-removing-damage-tick-delay.321642/ ).

    I have tested this with bows shooting multiple arrows (only one hits, the others bounce off the mob) and melee attacks. Any attempt to set the value to 0 silently fails to do anything at all.

    Is this intended? Fixable?
     
  2. Post your code. Have you also tried setting the no damage ticks using Scheduler#runTask? (So right after all the damage has been handled instead of before)
     
  3. i have attempted setting it before and after each instance of damage, in multiple places, and tested the value before doing anything to it. it is being set correctly, as far as getNoDamageTicks reports, but does absolutely nothing. arrows report that they hit the entity, but bounce off without doing damage, and do not pass the if(event.getDamager() instanceof Arrow ) test, making me think that getDamager() is returning null or an incorrect value.

    @EventHandler(priority = EventPriority.HIGHEST)
    public void onHit(EntityDamageByEntityEvent event)
    {
    logger.info("hitentity");
    LivingEntity help = (LivingEntity) event.getEntity();
    help.setNoDamageTicks(0);
    help.setLastDamage(0);
    //if(event.getCause() == DamageCause.ENTITY_ATTACK)
    //{
    //logger.info(event.getDamager().toString()+" Hit "+event.getEntity().toString());
    //}
    //logger.info("hit something");
    if(event.getDamager() instanceof Arrow )
    {
    logger.info("is arrow "+event.getDamage()+" "+help.getNoDamageTicks());
    //logger.info("hit with arrow");
    Arrow arrow = (Arrow) event.getDamager();
    if(arrow.hasMetadata("gArrowDamage"))
    {
    logger.info("arrow has bonus damage");
    double damage = event.getDamage()+(double)arrow.getMetadata("gArrowDamage").get(0).asDouble();
    event.setDamage(damage);
    }
    if(arrow.hasMetadata("gArrowType"))
    {
    //logger.info("hit");
    //if(target.getType() == EntityType.PLAYER && source.getType() == EntityType.PLAYER )
    // return; //no friendly fail
    String spellname = arrow.getMetadata("gArrowType").get(0).asString().trim();
    logger.info("["+spellname+"]" + Integer.toString(spellname.length()));
    String tType = "!Player"; //eventually will allow player/mob only damage

    //run commands from the arrow via the server to prevent derpery with dead mobs and arrows hitting slimes at 0/0/0
    ConsoleCommandSender server = getServer().getConsoleSender();
    String arrowexec = "execute "+arrow.getUniqueId().toString()+" ~ ~ ~ ";

    if(spellname.equals("Frost"))
    {
    logger.info("running Frost on "+event.getEntity().getUniqueId().toString());
    getServer().dispatchCommand(server,arrowexec+"particle snowshovel ~ ~0.25 ~ .5 .5 .5 .1 100 force");
    getServer().dispatchCommand(server,arrowexec+"effect @e[r=4,type="+tType+"] 2 5 4 true");
    getServer().dispatchCommand(server,arrowexec+"effect @e[r=4,type="+tType+"] 20 5 0 true");
    }
    }
    if(event.getEntity() instanceof LivingEntity)
    {
    //allow multishot to hit by removing invincibility-flash

    help.setNoDamageTicks(0);
    help.setLastDamage(0);
    }
    }
    }

    Older code samples from 2012-2014 that i have read or tested also seem to fail to do anything in my testing, and for other people, judging from more recent comments.
     
  4. Have you tried wrapping the setNoDamageTicks(0) in a runTask like I suggested in my previous post? (The code doesn't suggest you did).

    After the damage event, it will probably set the no damage ticks itself (after applying the damage), overriding your setDamageTicks(0)
     
  5. That would be completely useless, as far as i can tell. first, the value is not doing anything, even thought it seems to apply, and the issue is multiple hits happening in a single tick, not just multiple ticks.
     
  6. Sorry for gravedigging, but it looks like the method doesn't change anything at all. Did you report this in the bug tracker yet?

    Edit: Fixed it, using Bukkit scheduler works.