PaperMC/Spigot-API-Patches/0040-Add-ProjectileCollideEvent.patch
2018-07-23 09:44:57 +01:00

77 lines
2.1 KiB
Diff

From 4eac0975455ab0ef81f5dac6bf83d475951f9a81 Mon Sep 17 00:00:00 2001
From: Techcable <Techcable@outlook.com>
Date: Fri, 16 Dec 2016 21:25:39 -0600
Subject: [PATCH] Add ProjectileCollideEvent
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/ProjectileCollideEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/ProjectileCollideEvent.java
new file mode 100644
index 00000000..f42e9851
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/ProjectileCollideEvent.java
@@ -0,0 +1,62 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Projectile;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+
+/**
+ * Called when an projectile collides with an entity
+ * <p>
+ * This event is called <b>before</b> {@link org.bukkit.event.entity.EntityDamageByEntityEvent}, and cancelling it will allow the projectile to continue flying
+ */
+public class ProjectileCollideEvent extends EntityEvent implements Cancellable {
+ private final Entity collidedWith;
+
+ /**
+ * Get the entity the projectile collided with
+ *
+ * @return the entity collided with
+ */
+ public Entity getCollidedWith() {
+ return collidedWith;
+ }
+
+ public ProjectileCollideEvent(Projectile what, Entity collidedWith) {
+ super(what);
+ this.collidedWith = collidedWith;
+ }
+
+ /**
+ * Get the projectile that collided
+ *
+ * @return the projectile that collided
+ */
+ public Projectile getEntity() {
+ return (Projectile) super.getEntity();
+ }
+
+ private static final HandlerList handlerList = new HandlerList();
+
+ public static HandlerList getHandlerList() {
+ return handlerList;
+ }
+
+ @Override
+ public HandlerList getHandlers() {
+ return handlerList;
+ }
+
+ private boolean cancelled = false;
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+}
--
2.18.0