mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-27 10:41:27 +01:00
15fcde4b3c
EntityTeleportEvent#setTo is marked as nullable and so is the getTo method. This fixes the handling of a null "to" location by treating it the same as the event being cancelled. This is already existing behavior for the EntityPortalEvent (which extends EntityTeleportEvent).
86 lines
4.0 KiB
Diff
86 lines
4.0 KiB
Diff
--- a/net/minecraft/world/entity/TamableAnimal.java
|
|
+++ b/net/minecraft/world/entity/TamableAnimal.java
|
|
@@ -27,6 +27,11 @@
|
|
import net.minecraft.world.level.pathfinder.PathType;
|
|
import net.minecraft.world.level.pathfinder.WalkNodeEvaluator;
|
|
import net.minecraft.world.scores.PlayerTeam;
|
|
+// CraftBukkit start
|
|
+import org.bukkit.Location;
|
|
+import org.bukkit.craftbukkit.event.CraftEventFactory;
|
|
+import org.bukkit.event.entity.EntityTeleportEvent;
|
|
+// CraftBukkit end
|
|
|
|
public abstract class TamableAnimal extends Animal implements OwnableEntity {
|
|
|
|
@@ -85,7 +90,7 @@
|
|
}
|
|
|
|
this.orderedToSit = nbt.getBoolean("Sitting");
|
|
- this.setInSittingPose(this.orderedToSit);
|
|
+ this.setInSittingPose(this.orderedToSit, false); // Paper - Add EntityToggleSitEvent
|
|
}
|
|
|
|
@Override
|
|
@@ -96,8 +101,16 @@
|
|
@Override
|
|
public boolean handleLeashAtDistance(Entity leashHolder, float distance) {
|
|
if (this.isInSittingPose()) {
|
|
- if (distance > 10.0F) {
|
|
- this.dropLeash();
|
|
+ if (distance > (float) this.level().paperConfig().misc.maxLeashDistance.or(Leashable.LEASH_TOO_FAR_DIST)) { // Paper - Configurable max leash distance
|
|
+ // Paper start - Expand EntityUnleashEvent
|
|
+ org.bukkit.event.entity.EntityUnleashEvent event = new org.bukkit.event.entity.EntityUnleashEvent(this.getBukkitEntity(), org.bukkit.event.entity.EntityUnleashEvent.UnleashReason.DISTANCE, true);
|
|
+ if (!event.callEvent()) return false;
|
|
+ if (event.isDropLeash()) {
|
|
+ this.dropLeash();
|
|
+ } else {
|
|
+ this.removeLeash();
|
|
+ }
|
|
+ // Paper end - Expand EntityUnleashEvent
|
|
}
|
|
|
|
return false;
|
|
@@ -161,6 +174,12 @@
|
|
}
|
|
|
|
public void setInSittingPose(boolean inSittingPose) {
|
|
+ // Paper start - Add EntityToggleSitEvent
|
|
+ this.setInSittingPose(inSittingPose, true);
|
|
+ }
|
|
+ public void setInSittingPose(boolean inSittingPose, boolean callEvent) {
|
|
+ if (callEvent && !new io.papermc.paper.event.entity.EntityToggleSitEvent(this.getBukkitEntity(), inSittingPose).callEvent()) return;
|
|
+ // Paper end - Add EntityToggleSitEvent
|
|
byte b0 = (Byte) this.entityData.get(TamableAnimal.DATA_FLAGS_ID);
|
|
|
|
if (inSittingPose) {
|
|
@@ -244,7 +263,12 @@
|
|
if (entityliving instanceof ServerPlayer) {
|
|
ServerPlayer entityplayer = (ServerPlayer) entityliving;
|
|
|
|
- entityplayer.sendSystemMessage(this.getCombatTracker().getDeathMessage());
|
|
+ // Paper start - Add TameableDeathMessageEvent
|
|
+ io.papermc.paper.event.entity.TameableDeathMessageEvent event = new io.papermc.paper.event.entity.TameableDeathMessageEvent((org.bukkit.entity.Tameable) getBukkitEntity(), io.papermc.paper.adventure.PaperAdventure.asAdventure(this.getCombatTracker().getDeathMessage()));
|
|
+ if (event.callEvent()) {
|
|
+ entityplayer.sendSystemMessage(io.papermc.paper.adventure.PaperAdventure.asVanilla(event.deathMessage()));
|
|
+ }
|
|
+ // Paper end - Add TameableDeathMessageEvent
|
|
}
|
|
}
|
|
}
|
|
@@ -295,7 +319,14 @@
|
|
if (!this.canTeleportTo(new BlockPos(x, y, z))) {
|
|
return false;
|
|
} else {
|
|
- this.moveTo((double) x + 0.5D, (double) y, (double) z + 0.5D, this.getYRot(), this.getXRot());
|
|
+ // CraftBukkit start
|
|
+ EntityTeleportEvent event = CraftEventFactory.callEntityTeleportEvent(this, (double) x + 0.5D, (double) y, (double) z + 0.5D);
|
|
+ if (event.isCancelled() || event.getTo() == null) { // Paper - prevent NP on null event to location
|
|
+ return false;
|
|
+ }
|
|
+ Location to = event.getTo();
|
|
+ this.moveTo(to.getX(), to.getY(), to.getZ(), to.getYaw(), to.getPitch());
|
|
+ // CraftBukkit end
|
|
this.navigation.stop();
|
|
return true;
|
|
}
|