mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-06 18:50:51 +01:00
#567: Add ability to cancel ProjectileHitEvent
By: Martoph <sager1018@gmail.com>
This commit is contained in:
parent
9c9c9763ae
commit
d8fbe1d4ee
1 changed files with 27 additions and 2 deletions
|
@ -4,6 +4,7 @@ import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Projectile;
|
import org.bukkit.entity.Projectile;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -11,11 +12,12 @@ import org.jetbrains.annotations.Nullable;
|
||||||
/**
|
/**
|
||||||
* Called when a projectile hits an object
|
* Called when a projectile hits an object
|
||||||
*/
|
*/
|
||||||
public class ProjectileHitEvent extends EntityEvent {
|
public class ProjectileHitEvent extends EntityEvent implements Cancellable {
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Entity hitEntity;
|
private final Entity hitEntity;
|
||||||
private final Block hitBlock;
|
private final Block hitBlock;
|
||||||
private final BlockFace hitFace;
|
private final BlockFace hitFace;
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
public ProjectileHitEvent(@NotNull final Projectile projectile) {
|
public ProjectileHitEvent(@NotNull final Projectile projectile) {
|
||||||
this(projectile, null, null);
|
this(projectile, null, null);
|
||||||
|
@ -77,6 +79,30 @@ public class ProjectileHitEvent extends EntityEvent {
|
||||||
return hitEntity;
|
return hitEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCancelled() {
|
||||||
|
return cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to cancel the action that occurs when the projectile hits.
|
||||||
|
*
|
||||||
|
* In the case of an entity, it will not collide (unless it's a firework,
|
||||||
|
* then use {@link FireworkExplodeEvent}).
|
||||||
|
* <br>
|
||||||
|
* In the case of a block, some blocks (eg target block, bell) will not
|
||||||
|
* perform the action associated.
|
||||||
|
* <br>
|
||||||
|
* This does NOT prevent block collisions, and explosions will still occur
|
||||||
|
* unless their respective events are cancelled.
|
||||||
|
*
|
||||||
|
* @param cancel true if you wish to cancel this event
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setCancelled(boolean cancel) {
|
||||||
|
this.cancel = cancel;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
|
@ -87,5 +113,4 @@ public class ProjectileHitEvent extends EntityEvent {
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue