Hello Bukkitians, Objective: Removing EntityDamageByEntityEvent Tick Delay Result: Entities can damage players more than once in 10 ticks(Which is the damage Tick Delay) Information: If you wanted to damage an entity more than once in a tick for instance thinking about a gun, a shotgun in specific, it shoots more than one bullet(or shell) at once. If you were to use snowballs as the projectile which is going to act like the bullets, you would not be able to damage a player within 10 ticks of the first hit so the player would only be damaged by one snowball. Code: Before Code Code:java @EventHandlerpublic void onDamage(EntityDamageByEntityEvent e) {if (e.getEntity() instanceof Player) {if (e.getDamager() instanceof Snowball) {Snowball sball = (Snowball) e.getDamager();Player victim = (Player) e.getEntity();Player attacker = (Player) sball.getShooter();if (attacker.getItemInHand().getType().equals(Material.IRON_BARDING)) {e.setDamage(14.0);}}}} Now the code above wont allow multiple hits to get registered within 10 ticks which is the damage tick delay. To remove this delay we would do the following. Above: Code:java e.setDamage(14.0); Add: Code:java victim.setNoDamageTicks(0); Finished Code Code:java @EventHandlerpublic void onDamage(EntityDamageByEntityEvent e) {if (e.getEntity() instanceof Player) {if (e.getDamager() instanceof Snowball) {Snowball sball = (Snowball) e.getDamager();Player victim = (Player) e.getEntity();Player attacker = (Player) sball.getShooter();if (attacker.getItemInHand().getType().equals(Material.IRON_BARDING)) {victim.setNoDamageTicks(0);e.setDamage(14.0);}}}} Finished: Now you have followed these steps you have finished your goal. If you have any questions on this subject please comment below because I do feel as if I did not elaborate enough, if so I will do my best to explain this more as much as possible. Please forgive me if this is bad due to it being my first tutorial.
sethrem A whole tutorial for one line of code? Have you seen this? http://jd.bukkit.org/dev/doxygen/d4...Entity.html#a4d8dec33296af3c37f09ba275696b5d8 No offence, but this tutorial is pretty much useless.
xTrollxDudex No, You can remove that if statement if you'd like and then it would work for everything. I just had that iron barlding to use as a gun. AdamQpzm I guess so.
I LOVE THIS POST! Never thought it was THAT EASY! Is this probably what mineplex does for the paintball shotgun? //Edit: no longer works... How do you make this work now?
Now you need to use "LivingEntity" instead of "Player" Code: LivingEntity victim = (LivingEntity) event.getEntity(); victim.setNoDamageTicks(0); victim.damage(10.0); //or event.setDamage(10.0); But there is still something that doesn't work... My Shotgun code is still not working, only one bullet per shot is damaging even if 4 bullets hitted the LivingEntity...