Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
Added better PlayerVelocityEvent support (#391)
Browse files Browse the repository at this point in the history
- PlayerVelocityEvent now details if the event was fired from player attack knockback
  • Loading branch information
Archonic944 authored Mar 28, 2022
1 parent 0a3a65e commit f370fc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit f370fc6

Please sign in to comment.