Solved Vector Cancellations

Discussion in 'Plugin Help/Development/Requests' started by 2008Choco, Jul 3, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    My main goal is to cancel the vector of an arrow hitting a player, without having to cancel the event. The reason why I want to do this, is because I want to set a later vector. However, when I set a later vector, the arrow vector is overriding the one I have set. For example if I set the vector to new Vector(0, 100, 0), it won't launch the player because of the arrow knockback vector overriding the one I have just set. Is there any way I can cancel the vector that the arrow is creating without cancelling the event all together?

    I've attempted using .setKnockbackStrength(0), but that didn't fix my issue. For more information, I am currently using an EntityDamageByEntityEvent.
  2. Offline


    I'm still lookin' for some help on this <3 That would be great
  3. Offline


    Still looking for an answer. I need this for a plugin I'm working on :) Thanks
  4. Offline


    I mean, I couldn't figure out how to do it without setting the event to cancelled.


    I did get what I think you wanted working.
    I did cancel the event, but I kept the damage and was able to set another vector after.

        public void onEntityDamageEntity(EntityDamageByEntityEvent event) {
            if (event.getDamager() instanceof Arrow && event.getEntity() instanceof Player) {
                Player p = (Player) event.getEntity();
                if (p.getHealth() - event.getDamage() <= 0)
                p.setVelocity(new Vector(0, 1, 0));
                //^Player takes the damage is is launched with the new velocity
    I'm not sure if you wanted to do anything else that would mean you couldn't cancel the event but I believe this works fine :D

    Edit: Fixed it so that the death message is still displayed if they die

    Edit 2: less lines
    Last edited: Jul 6, 2015
  5. Offline


    @Destroyer7712 Yea that was the way I had accomplished that before. The reason why I want to avoid using event.setCancelled(true) is because of PvP Protection plugins. I don't want to have to add in about 5 different API's such as WorldGuard just so I can work around PvP. If I don't cancel the event, their code prevents arrow damage. If the event is cancelled and the damage is dealt by the plugin, that's unfortunately not protected and they can damage other players in spawn.

    I appreciate the attempt, but I need to avoid event.setCancelled(true) at all costs
    Destroyer7712 likes this.
  6. Offline


    I spent a while trying to figure this out but I couldn't come up with anything :/ the .normalize() helps slightly
  7. Offline


    I'm not quite sure what to do with the .normalize(); method. Still looking for help though, that would be great
  8. Offline


    @2008Choco Canceling events is not always wrong, as there is the EventPriority enum.

    Basicly you let your pvp protection plugins do their work first, and cancel the event at HIGHEST priority.

  9. Offline


    Thank you @MisterErwin ^-^ I will test this out sometime later as I really have no way to test it right now. This should work, and I'm not sure why I didn't think of EventPriorities before
Thread Status:
Not open for further replies.

Share This Page