Hi, How can I make it so when a player gets hit by another player, projectile, mob, etc, they don't take knock back? If you know how to do this please reply. Thank you!
@coopjc Listen for an EntityDamageEvent, check the cause of the damage (e.g Arrow), set velocity to 0. May cause issues if they are running, not sure.
@Connor2weirdness Wouldn't that just stop the entity that attacked them from moving? @coopjc There's a very dirty way to do this, it's to cancel damage events then set health to be health - damage. There is a method for living entities called damage, however it's possible that method could call an event (The method would call the event, the event would call the method, the method would call the event...), if it doesn't then you should use damage instead of setHealth. There's another problem with this though, the player will not appear red and it will not look as if they were damaged at all, nor will they achieve the built in 10 ticks of invulnerability that is built in after each hit so a entity could be killed quite quickly. Edit: Spacing...
@Connor2weirdness Since that would be set inside the event handler all that should do is clear the player's velocity before the knockback is applied, the knockback is not actually applied until the event returns as not cancelled. Which means it needs to run through all event handlers first.
@Connor2weirdness @Xerox262 Setting the velocity is the best thing to do. Just set it on the next tick in a task.