Fix NPE on null loc for EntityTeleportEvent

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).
This commit is contained in:
Jake Potrebic
2023-12-09 19:15:59 -08:00
parent 5b1ab02f39
commit 15fcde4b3c
4 changed files with 6 additions and 5 deletions

View File

@@ -74,7 +74,7 @@
- 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()) {
+ if (event.isCancelled() || event.getTo() == null) { // Paper - prevent NP on null event to location
+ return false;
+ }
+ Location to = event.getTo();