From 1f46b2ca93d6f528aca1ea327ac678d476104a18 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Wed, 6 Sep 2023 17:28:06 -0700 Subject: [PATCH] Fix NPE in TeleportUtils if the Entity becomes retired The onComplete variable is possibly null and should be checked before trying to invoke it. Fixes https://github.com/PaperMC/Folia/issues/151 --- patches/server/0003-Threaded-Regions.patch | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/patches/server/0003-Threaded-Regions.patch b/patches/server/0003-Threaded-Regions.patch index 465dfa7..f61da9a 100644 --- a/patches/server/0003-Threaded-Regions.patch +++ b/patches/server/0003-Threaded-Regions.patch @@ -5472,10 +5472,10 @@ index 0000000000000000000000000000000000000000..112d24a93bddf3d81c9176c05340c94e +} diff --git a/src/main/java/io/papermc/paper/threadedregions/TeleportUtils.java b/src/main/java/io/papermc/paper/threadedregions/TeleportUtils.java new file mode 100644 -index 0000000000000000000000000000000000000000..84b4ff07735fb84e28ee8966ffdedb1bb3d07dff +index 0000000000000000000000000000000000000000..7b31c4ea6d01f936271bdadc3626201dcf32a683 --- /dev/null +++ b/src/main/java/io/papermc/paper/threadedregions/TeleportUtils.java -@@ -0,0 +1,60 @@ +@@ -0,0 +1,70 @@ +package io.papermc.paper.threadedregions; + +import ca.spottedleaf.concurrentutil.completable.Completable; @@ -5496,7 +5496,9 @@ index 0000000000000000000000000000000000000000..84b4ff07735fb84e28ee8966ffdedb1b + positionCompletable.addWaiter( + (final Location loc, final Throwable thr) -> { + if (loc == null) { -+ onComplete.accept(null); ++ if (onComplete != null) { ++ onComplete.accept(null); ++ } + return; + } + final boolean scheduled = from.getBukkitEntity().taskScheduler.schedule( @@ -5510,12 +5512,16 @@ index 0000000000000000000000000000000000000000..84b4ff07735fb84e28ee8966ffdedb1b + ); + }, + (final Entity retired) -> { -+ onComplete.accept(null); ++ if (onComplete != null) { ++ onComplete.accept(null); ++ } + }, + 1L + ); + if (!scheduled) { -+ onComplete.accept(null); ++ if (onComplete != null) { ++ onComplete.accept(null); ++ } + } + } + ); @@ -5525,12 +5531,16 @@ index 0000000000000000000000000000000000000000..84b4ff07735fb84e28ee8966ffdedb1b + positionCompletable.complete(target.getBukkitEntity().getLocation()); + }, + (final Entity retired) -> { -+ onComplete.accept(null); ++ if (onComplete != null) { ++ onComplete.accept(null); ++ } + }, + 1L + ); + if (!scheduled) { -+ onComplete.accept(null); ++ if (onComplete != null) { ++ onComplete.accept(null); ++ } + } + } +