mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-19 13:40:24 -07:00
Fix NoSuchElementException in EntityTransformEvent for slimes (#12510)
This commit is contained in:
parent
cb3ffd0b4a
commit
d637ae85dd
@ -6,11 +6,12 @@ import org.bukkit.entity.Entity;
|
|||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jspecify.annotations.NullMarked;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when an entity is about to be replaced by another entity.
|
* Called when an entity is about to be replaced by another entity.
|
||||||
*/
|
*/
|
||||||
|
@NullMarked
|
||||||
public class EntityTransformEvent extends EntityEvent implements Cancellable {
|
public class EntityTransformEvent extends EntityEvent implements Cancellable {
|
||||||
|
|
||||||
private static final HandlerList HANDLER_LIST = new HandlerList();
|
private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
@ -22,10 +23,10 @@ public class EntityTransformEvent extends EntityEvent implements Cancellable {
|
|||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
public EntityTransformEvent(@NotNull Entity original, @NotNull List<Entity> convertedList, @NotNull TransformReason transformReason) {
|
public EntityTransformEvent(Entity original, List<Entity> convertedList, TransformReason transformReason) {
|
||||||
super(original);
|
super(original);
|
||||||
this.convertedList = Collections.unmodifiableList(convertedList);
|
this.convertedList = Collections.unmodifiableList(convertedList);
|
||||||
this.converted = convertedList.get(0);
|
this.converted = convertedList.getFirst();
|
||||||
this.transformReason = transformReason;
|
this.transformReason = transformReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +35,6 @@ public class EntityTransformEvent extends EntityEvent implements Cancellable {
|
|||||||
*
|
*
|
||||||
* @return The transformed entities.
|
* @return The transformed entities.
|
||||||
*/
|
*/
|
||||||
@NotNull
|
|
||||||
public List<Entity> getTransformedEntities() {
|
public List<Entity> getTransformedEntities() {
|
||||||
return this.convertedList;
|
return this.convertedList;
|
||||||
}
|
}
|
||||||
@ -47,7 +47,6 @@ public class EntityTransformEvent extends EntityEvent implements Cancellable {
|
|||||||
* @return The transformed entity.
|
* @return The transformed entity.
|
||||||
* @see #getTransformedEntities()
|
* @see #getTransformedEntities()
|
||||||
*/
|
*/
|
||||||
@NotNull
|
|
||||||
public Entity getTransformedEntity() {
|
public Entity getTransformedEntity() {
|
||||||
return this.converted;
|
return this.converted;
|
||||||
}
|
}
|
||||||
@ -57,7 +56,6 @@ public class EntityTransformEvent extends EntityEvent implements Cancellable {
|
|||||||
*
|
*
|
||||||
* @return The reason for conversion that has occurred.
|
* @return The reason for conversion that has occurred.
|
||||||
*/
|
*/
|
||||||
@NotNull
|
|
||||||
public TransformReason getTransformReason() {
|
public TransformReason getTransformReason() {
|
||||||
return this.transformReason;
|
return this.transformReason;
|
||||||
}
|
}
|
||||||
@ -72,13 +70,11 @@ public class EntityTransformEvent extends EntityEvent implements Cancellable {
|
|||||||
this.cancelled = cancel;
|
this.cancelled = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return HANDLER_LIST;
|
return HANDLER_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return HANDLER_LIST;
|
return HANDLER_LIST;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
+ // CraftBukkit end
|
+ // CraftBukkit end
|
||||||
+ }
|
+ }
|
||||||
+ // CraftBukkit start
|
+ // CraftBukkit start
|
||||||
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTransformEvent(this, slimes, org.bukkit.event.entity.EntityTransformEvent.TransformReason.SPLIT).isCancelled()) {
|
+ if (!slimes.isEmpty() && org.bukkit.craftbukkit.event.CraftEventFactory.callEntityTransformEvent(this, slimes, org.bukkit.event.entity.EntityTransformEvent.TransformReason.SPLIT).isCancelled()) { // check for empty converted entities or cancel event
|
||||||
+ super.remove(reason, eventCause); // add Bukkit remove cause
|
+ super.remove(reason, eventCause); // add Bukkit remove cause
|
||||||
+ return;
|
+ return;
|
||||||
+ }
|
+ }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user