aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/api/0040-Add-EntityZapEvent.patch
blob: a9b79bd56b8a5a4c9b03a06eddac13e3f63fb90b (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: AlphaBlend <whizkid3000@hotmail.com>
Date: Sun, 16 Oct 2016 23:19:34 -0700
Subject: [PATCH] Add EntityZapEvent


diff --git a/src/main/java/com/destroystokyo/paper/event/entity/EntityZapEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/EntityZapEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..af2b1629f845ffe1559e7d580b482636cc6441d9
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/EntityZapEvent.java
@@ -0,0 +1,65 @@
+package com.destroystokyo.paper.event.entity;
+
+import java.util.Collections;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LightningStrike;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityTransformEvent;
+import org.jetbrains.annotations.ApiStatus;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * Fired when lightning strikes an entity
+ */
+@NullMarked
+public class EntityZapEvent extends EntityTransformEvent implements Cancellable {
+
+    private static final HandlerList HANDLER_LIST = new HandlerList();
+
+    private final LightningStrike bolt;
+    private boolean cancelled;
+
+    @ApiStatus.Internal
+    public EntityZapEvent(final Entity entity, final LightningStrike bolt, final Entity replacementEntity) {
+        super(entity, Collections.singletonList(replacementEntity), TransformReason.LIGHTNING);
+        this.bolt = bolt;
+    }
+
+    /**
+     * Gets the lightning bolt that is striking the entity.
+     *
+     * @return The lightning bolt responsible for this event
+     */
+    public LightningStrike getBolt() {
+        return this.bolt;
+    }
+
+    /**
+     * Gets the entity that will replace the struck entity.
+     *
+     * @return The entity that will replace the struck entity
+     */
+    public Entity getReplacementEntity() {
+        return super.getTransformedEntity();
+    }
+
+    @Override
+    public boolean isCancelled() {
+        return this.cancelled;
+    }
+
+    @Override
+    public void setCancelled(final boolean cancel) {
+        this.cancelled = cancel;
+    }
+
+    @Override
+    public HandlerList getHandlers() {
+        return HANDLER_LIST;
+    }
+
+    public static HandlerList getHandlerList() {
+        return HANDLER_LIST;
+    }
+}
diff --git a/src/main/java/org/bukkit/event/entity/PigZapEvent.java b/src/main/java/org/bukkit/event/entity/PigZapEvent.java
index 0e0ed93b568fd2c0d8f6e359c31dc29cb0fa71c2..085337f3d3d6adef5fd4ecda133c607e4b77bd93 100644
--- a/src/main/java/org/bukkit/event/entity/PigZapEvent.java
+++ b/src/main/java/org/bukkit/event/entity/PigZapEvent.java
@@ -12,14 +12,14 @@ import org.jetbrains.annotations.NotNull;
 /**
  * Stores data for pigs being zapped
  */
-public class PigZapEvent extends EntityTransformEvent implements Cancellable {
-    private static final HandlerList handlers = new HandlerList();
+public class PigZapEvent extends com.destroystokyo.paper.event.entity.EntityZapEvent implements Cancellable { // Paper
+    // private static final HandlerList handlers = new HandlerList(); // Paper - moved in the super class
     private boolean canceled;
     private final PigZombie pigzombie;
     private final LightningStrike bolt;
 
     public PigZapEvent(@NotNull final Pig pig, @NotNull final LightningStrike bolt, @NotNull final PigZombie pigzombie) {
-        super(pig, Collections.singletonList((Entity) pigzombie), TransformReason.LIGHTNING);
+        super(pig, bolt, pigzombie); // Paper
         this.bolt = bolt;
         this.pigzombie = pigzombie;
     }
@@ -63,6 +63,8 @@ public class PigZapEvent extends EntityTransformEvent implements Cancellable {
         return pigzombie;
     }
 
+    // Paper start
+    /*
     @NotNull
     @Override
     public HandlerList getHandlers() {
@@ -73,4 +75,6 @@ public class PigZapEvent extends EntityTransformEvent implements Cancellable {
     public static HandlerList getHandlerList() {
         return handlers;
     }
+    */
+    // Paper end
 }