1
0
Fork 0
mirror of https://github.com/PaperMC/Paper.git synced 2025-01-31 03:50:36 +01:00

Add EntityZapEvent

This commit is contained in:
AlphaBlend 2016-10-16 23:19:34 -07:00
parent 397d3cac4b
commit 4d7ecbdb78
2 changed files with 72 additions and 3 deletions
paper-api/src/main/java
com/destroystokyo/paper/event/entity
org/bukkit/event/entity

View file

@ -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;
}
}

View file

@ -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
}