aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-API-Patches/0116-Add-EntityKnockbackByEntityEvent.patch
blob: 0e513c7283a8798aa5690d711630465a95da3fcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From 3aa00b8416f918d281c0bd49999ea499af44f3b2 Mon Sep 17 00:00:00 2001
From: Brokkonaut <hannos17@gmx.de>
Date: Mon, 18 Jun 2018 15:40:39 +0200
Subject: [PATCH] Add EntityKnockbackByEntityEvent


diff --git a/src/main/java/com/destroystokyo/paper/event/entity/EntityKnockbackByEntityEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/EntityKnockbackByEntityEvent.java
new file mode 100644
index 000000000..f6ef11624
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/EntityKnockbackByEntityEvent.java
@@ -0,0 +1,76 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.bukkit.util.Vector;
+
+/**
+ * Fired when an Entity is knocked back by the hit of another Entity. The acceleration
+ * vector can be modified. If this event is cancelled, the entity is not knocked back.
+ *
+ */
+public class EntityKnockbackByEntityEvent extends EntityEvent implements Cancellable {
+    private static final HandlerList handlers = new HandlerList();
+
+    private final Entity hitBy;
+    private final float knockbackStrength;
+    private final Vector acceleration;
+    private boolean cancelled = false;
+
+    public EntityKnockbackByEntityEvent(LivingEntity entity, Entity hitBy, float knockbackStrength, Vector acceleration) {
+        super(entity);
+        this.hitBy = hitBy;
+        this.knockbackStrength = knockbackStrength;
+        this.acceleration = acceleration;
+    }
+
+    public HandlerList getHandlers() {
+        return handlers;
+    }
+
+    public static HandlerList getHandlerList() {
+        return handlers;
+    }
+
+    @Override
+    public boolean isCancelled() {
+        return cancelled;
+    }
+
+    @Override
+    public void setCancelled(boolean cancel) {
+        cancelled = cancel;
+    }
+
+    /**
+     * @return the entity which was knocked back
+     */
+    @Override
+    public LivingEntity getEntity() {
+        return (LivingEntity) super.getEntity();
+    }
+
+    /**
+     * @return the original knockback strength.
+     */
+    public float getKnockbackStrength() {
+        return knockbackStrength;
+    }
+
+    /**
+     * @return the Entity which hit
+     */
+    public Entity getHitBy() {
+        return hitBy;
+    }
+
+    /**
+     * @return the acceleration that will be applied
+     */
+    public Vector getAcceleration() {
+        return acceleration;
+    }
+}
-- 
2.18.0