PaperMC/patches/api/Add-EntityZapEvent.patch
Jake Potrebic 64e918335c Begin switching to JSpecify annotations (#11448)
* Begin switching to JSpecify annotations

* more

* fixes
2024-09-29 12:52:13 -07:00

115 lines
4 KiB
Diff

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..0000000000000000000000000000000000000000
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/EntityZapEvent.java
@@ -0,0 +0,0 @@
+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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/event/entity/PigZapEvent.java
+++ b/src/main/java/org/bukkit/event/entity/PigZapEvent.java
@@ -0,0 +0,0 @@ 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;
}
@@ -0,0 +0,0 @@ public class PigZapEvent extends EntityTransformEvent implements Cancellable {
return pigzombie;
}
+ // Paper start
+ /*
@NotNull
@Override
public HandlerList getHandlers() {
@@ -0,0 +0,0 @@ public class PigZapEvent extends EntityTransformEvent implements Cancellable {
public static HandlerList getHandlerList() {
return handlers;
}
+ */
+ // Paper end
}