From f370fc6d1965924a7b6909f0607effca24c934e8 Mon Sep 17 00:00:00 2001 From: Archonic <55026152+Archonic944@users.noreply.github.com> Date: Mon, 28 Mar 2022 13:03:26 -0700 Subject: [PATCH] Added better PlayerVelocityEvent support (#391) - PlayerVelocityEvent now details if the event was fired from player attack knockback --- .../bukkit/event/player/PlayerVelocityEvent.java | 16 +++++++++++++++- .../java/net/minecraft/server/EntityHuman.java | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/NachoSpigot-API/src/main/java/org/bukkit/event/player/PlayerVelocityEvent.java b/NachoSpigot-API/src/main/java/org/bukkit/event/player/PlayerVelocityEvent.java index 69d2fce4a..b0bb08106 100644 --- a/NachoSpigot-API/src/main/java/org/bukkit/event/player/PlayerVelocityEvent.java +++ b/NachoSpigot-API/src/main/java/org/bukkit/event/player/PlayerVelocityEvent.java @@ -12,10 +12,16 @@ public class PlayerVelocityEvent extends PlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancel = false; private Vector velocity; + private final boolean fromAttack; - public PlayerVelocityEvent(final Player player, final Vector velocity) { + public PlayerVelocityEvent(final Player player, final Vector velocity, final boolean fromPlayerBeingAttacked) { super(player); this.velocity = velocity; + this.fromAttack = fromPlayerBeingAttacked; + } + + public PlayerVelocityEvent(final Player player, final Vector velocity) { + this(player, velocity, false); } public boolean isCancelled() { @@ -52,4 +58,12 @@ public HandlerList getHandlers() { public static HandlerList getHandlerList() { return handlers; } + + /** + * + * @return Whether this velocity change was triggered due to the player being attacked by another player. + */ + public boolean fromPlayerBeingAttacked(){ + return fromAttack; + } } diff --git a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java index d10c5472c..1539eb61e 100644 --- a/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java +++ b/NachoSpigot-Server/src/main/java/net/minecraft/server/EntityHuman.java @@ -1025,7 +1025,7 @@ public void attack(Entity entity) { if (entity instanceof EntityPlayer && entity.velocityChanged) { Player player = (Player) entity.getBukkitEntity(); final Vector velocity = new Vector(entity.motX, entity.motY, entity.motZ); - PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity); + PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity, true); world.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) {