From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: AlphaBlend 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 }