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:
@@ -1856,7 +1856,7 @@
|
||||
+ if (!(this instanceof ServerPlayer)) {
|
||||
+ EntityTeleportEvent teleport = new EntityTeleportEvent(this.getBukkitEntity(), new Location(this.level().getWorld(), d3, d4, d5), new Location(this.level().getWorld(), d0, d6, d2));
|
||||
+ this.level().getCraftServer().getPluginManager().callEvent(teleport);
|
||||
+ if (!teleport.isCancelled()) {
|
||||
+ if (!teleport.isCancelled() && teleport.getTo() != null) { // Paper
|
||||
+ Location to = teleport.getTo();
|
||||
+ this.teleportTo(to.getX(), to.getY(), to.getZ());
|
||||
+ } else {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
if (enumdirection != null) {
|
||||
+ // CraftBukkit start
|
||||
+ EntityTeleportEvent teleportEvent = CraftEventFactory.callEntityTeleportEvent(this, blockposition1.getX(), blockposition1.getY(), blockposition1.getZ());
|
||||
+ if (teleportEvent.isCancelled()) {
|
||||
+ if (teleportEvent.isCancelled() || teleportEvent.getTo() == null) { // Paper
|
||||
+ return false;
|
||||
+ } else {
|
||||
+ blockposition1 = CraftLocation.toBlockPosition(teleportEvent.getTo());
|
||||
|
||||
Reference in New Issue
Block a user