Cancel player knockback without rubberband effect

Discussion in 'Spigot Plugin Development' started by EVILCAT6, Mar 17, 2019.

  1. Hey. So I'm trying to make an ability in my mini-game where you can activate Anti-Knockback for 5 seconds. I've got some code working that will prevent the knockback, but it sets the player's Velocity to 0 which causes a rubberbanding effect (The player freezes for a tick). I want to the player to be able to move freely and not take knockback when activating this ability.

    This is my current code:

    Code (Java):
    player.setVelocity(new Vector());
                    Bukkit.getScheduler().runTaskLater(core, new Runnable() {

                        public void run() {
                            player.setVelocity(new Vector());
                    }, 1l);
    This is being ran in a EntityDamageByEntityEvent when I have checked that the player has activated the ability.

    I know I could just cancel the damage event, but I want the player to get damaged too. Is there any other way I can cancel knockback but still let the player get damaged?
  2. Use PlayerVelocityEvent and cancel the velocity?
  3. Wouldn't that also cancel the player's movement velocity as well?