fix: prevent NullPointerException in world setup when getWorld returns null - #4901
fix: prevent NullPointerException in world setup when getWorld returns null#4901bastigfz wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes /plot setup failing with an exception when BukkitUtil.getSpawn() is invoked for a world that is not yet registered in Bukkit.
Changes:
- Adds a null-check around
getWorld(world)inBukkitUtil.getSpawn(). - Introduces a fallback spawn location when the Bukkit world is unavailable.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| final org.bukkit.Location temp = getWorld(world).getSpawnLocation(); | ||
| final World bukkitWorld = getWorld(world); | ||
| if (bukkitWorld == null) { | ||
| return Location.at(world, 0, 64, 0); |
1043eb6 to
222222f
Compare
| final World bukkitWorld = getWorld(world); | ||
| if (bukkitWorld == null) { | ||
| return UncheckedWorldLocation.at(world, 0, 64, 0); | ||
| } | ||
| final org.bukkit.Location temp = bukkitWorld.getSpawnLocation(); |
Why is that? |
…s null BukkitUtil.getSpawn() assumed getWorld() would never return null, but during the /plot setup process the world may not yet be registered with Bukkit when getSpawn() is called, causing a NullPointerException. This adds a null check in getSpawn(), returning a safe fallback spawn location at (0, 64, 0) when the world is not yet available, consistent with the existing null-safe pattern used in setSpawn(). Uses UncheckedWorldLocation for the fallback to avoid a secondary exception from Location.at() which resolves the platform world internally and throws if the world is not registered. Also adds a null check in BukkitPlayer.teleport() to prevent a NullPointerException when constructing the Bukkit Location from a world that is not yet registered. Fixes the following error during /plot setup: java.lang.NullPointerException: Cannot invoke "org.bukkit.World.getSpawnLocation()" because the return value of "com.plotsquared.bukkit.util.BukkitUtil.getWorld(String)" is null
222222f to
79f9d25
Compare
|
I've never encountered this. I'm going to look into this before approving. |
The issue occurs because Objects.requireNonNull(PlotSquared.platform()).worldManager()
.handleWorldCreation(builder.worldName(), builder.generatorName());
if (Bukkit.getWorld(world) != null) {
return world;
}
return builder.worldName();Back in |
No, world creation is not asynchronous. Maybe your fork is at fault. |
You are right, Looking at the stack trace from the reporter again: The NPE happens before the world is even created. This means I cannot fully explain the root cause from the code alone – it could be a Leaf-specific behavior, a version mismatch in 7.5.13-Premium, or something else. However, the defensive null-checks in |
This really sounds like a problem with the server software you are using. |
|
|
Description
Fixes a
NullPointerExceptionthat occurs during/plot setupwhenBukkitUtil.getSpawn()is called for a world that has not yet been registered with Bukkit.Root Cause
BukkitUtil.getSpawn()calledgetWorld(world).getSpawnLocation()without a null check. During the plot setup process, the world may not yet be available viaBukkit.getWorld(), causing:Fix
Added a null check in
BukkitUtil.getSpawn(), returning a safe fallback spawn location at(0, 64, 0)when the world is not yet available. This is consistent with the existing null-safe pattern already used insetSpawn().Related