3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-14 20:10:05 +01:00
Paper/patches/api/0040-Add-EntityZapEvent.patch

116 Zeilen
4.0 KiB
Diff

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