mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-25 05:44:45 +01:00
Add EntityZapEvent
This commit is contained in:
parent
397d3cac4b
commit
4d7ecbdb78
2 changed files with 72 additions and 3 deletions
paper-api/src/main/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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,14 +12,14 @@ import org.jetbrains.annotations.NotNull;
|
||||||
/**
|
/**
|
||||||
* Stores data for pigs being zapped
|
* Stores data for pigs being zapped
|
||||||
*/
|
*/
|
||||||
public class PigZapEvent extends EntityTransformEvent implements Cancellable {
|
public class PigZapEvent extends com.destroystokyo.paper.event.entity.EntityZapEvent implements Cancellable { // Paper
|
||||||
private static final HandlerList handlers = new HandlerList();
|
// private static final HandlerList handlers = new HandlerList(); // Paper - moved in the super class
|
||||||
private boolean canceled;
|
private boolean canceled;
|
||||||
private final PigZombie pigzombie;
|
private final PigZombie pigzombie;
|
||||||
private final LightningStrike bolt;
|
private final LightningStrike bolt;
|
||||||
|
|
||||||
public PigZapEvent(@NotNull final Pig pig, @NotNull final LightningStrike bolt, @NotNull final PigZombie pigzombie) {
|
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.bolt = bolt;
|
||||||
this.pigzombie = pigzombie;
|
this.pigzombie = pigzombie;
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,8 @@ public class PigZapEvent extends EntityTransformEvent implements Cancellable {
|
||||||
return pigzombie;
|
return pigzombie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Paper start
|
||||||
|
/*
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
|
@ -73,4 +75,6 @@ public class PigZapEvent extends EntityTransformEvent implements Cancellable {
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
// Paper end
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue