Don't fire EntityToggleSitEvent on deserialization & reorder some api patches (#8495)

This commit is contained in:
Owen1212055 2022-10-22 22:55:28 -04:00
parent fc19cbd800
commit c1aac9ca35
2 changed files with 30 additions and 14 deletions

View file

@ -26,26 +26,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private boolean cancelled;
+ private final Entity entity;
+ private final boolean isSitting;
+
+ public EntityToggleSitEvent(@NotNull Entity entity, boolean isSitting) {
+ super(entity);
+ this.entity = entity;
+ this.isSitting = isSitting;
+ }
+
+ /**
+ * The entity involved.
+ *
+ * @return The entity.
+ */
+ @NotNull
+ public Entity getEntity() {
+ return this.entity;
+ }
+
+ /**
+ * Gets the new sitting state that the entity will change to.
+ *
+ * @return If it's going to sit or not.

View file

@ -11,8 +11,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@@ -0,0 +0,0 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity {
}
this.orderedToSit = nbt.getBoolean("Sitting");
- this.setInSittingPose(this.orderedToSit);
+ this.setInSittingPose(this.orderedToSit, false); // Paper - Don't fire event
}
@Override
@@ -0,0 +0,0 @@ public abstract class TamableAnimal extends Animal implements OwnableEntity {
}
public void setInSittingPose(boolean inSittingPose) {
+ if (!new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), inSittingPose).callEvent()) return; // Paper start - call EntityToggleSitEvent
+ // Paper start
+ this.setInSittingPose(inSittingPose, true);
+ }
+ public void setInSittingPose(boolean inSittingPose, boolean callEvent) {
+ // Paper end
+ if (callEvent && !new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), inSittingPose).callEvent()) return; // Paper start - call EntityToggleSitEvent
byte b = this.entityData.get(DATA_FLAGS_ID);
if (inSittingPose) {
this.entityData.set(DATA_FLAGS_ID, (byte)(b | 1));
@ -20,11 +34,25 @@ diff --git a/src/main/java/net/minecraft/world/entity/animal/Fox.java b/src/main
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/animal/Fox.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Fox.java
@@ -0,0 +0,0 @@ public class Fox extends Animal {
this.setSleeping(nbt.getBoolean("Sleeping"));
this.setFoxType(Fox.Type.byName(nbt.getString("Type")));
- this.setSitting(nbt.getBoolean("Sitting"));
+ this.setSitting(nbt.getBoolean("Sitting"), false); // Paper
this.setIsCrouching(nbt.getBoolean("Crouching"));
if (this.level instanceof ServerLevel) {
this.setTargetGoals();
@@ -0,0 +0,0 @@ public class Fox extends Animal {
}
public void setSitting(boolean sitting) {
+ if (!new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), sitting).callEvent()) return; // Paper start - call EntityToggleSitEvent
+ this.setSitting(sitting, true);
+ }
+ // Paper start
+ public void setSitting(boolean sitting, boolean fireEvent) {
+ if (fireEvent && !new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), sitting).callEvent()) return;
+ // Paper end
this.setFlag(1, sitting);
}