Hi guys i've been coding some minigames, and i was managing some events when i noticed something: When i cancel an EntityDamageEvent, if a player gets shot by the arrow, the arrow ricochets and could possibly damage the arrow launcher. Other thing is i want to prevent people from destroying soiled dirt. When someone jumps into soiled dirt, it transforms into normal dirt. How can i prevent this
For the arrow thing that sounds odd, and I'll have to look into that personally. Try rather than canceling it set the damage to 0 that way it's like they were hit, but not really. For the dirt thing, this might be worth reading: https://forums.bukkit.org/threads/solved-prevent-farmland-trampling.100136/
Pik0 Code:java public void damage(EntityDamageEvent e){if (!(e.getCause() == DamageCause.PROJECTILE)) return;if (!e.getEntity().getLastDamageCause().getEntity().getType().equals(EntityType.ARROW)) return; e.setCancelled(true); e.getEntity().getLastDamageCause().getEntity().setVelocity(new Vector(0, 0, 0)); //Make sure you import the bukkit version of the Vector class//This will set the velocity to 0, 0, 0 so the arrow wont move after the damage event.} I hope this helped you out a little. --Heirteir
You could do what Nateb did, or you could just cancel the event and use e.getEntity().remove(); Also, Heirteir - EntityType can't equal a Material...