WorldGuard integration may cause mob spawning to fail
Due to a misplaced null check, WorldGuard integration may cause mob spawning to fail exceptionally under certain conditions. Full stacktrace can be found here. Note that while the NPE is wrapped in a java.util.concurrent.CompletionException
, it was not executed asynchronously or off the main server thread.
This was encountered in updating our in-house plugins from 1.16.5 to 1.18.2, so it is possible that the issue is a regression.
(Code as of Mythic-Dist-5.1.0-20220531.222700-43
, decompiled)
/* (snip) */
public boolean getLocationAllowsMobSpawning(Location l) {
World world = BukkitAdapter.adapt(l.getWorld());
RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(world);
WorldConfiguration worldState = WorldGuard.getInstance().getPlatform().getGlobalStateManager().get(world);
if (!worldState.blockPluginSpawning) {
return true;
} else {
ApplicableRegionSet ret = regionManager.getApplicableRegions(BlockVector3.at(l.getX(), l.getY(), l.getZ()));
// Null check does nothing; will always fail exceptionally if regionManager
// is null due to previous line.
return regionManager == null || ret.testState((RegionAssociable)null, new StateFlag[]{Flags.MOB_SPAWNING});
/*
Replace previous two lines with
return regionManager == null ||
regionManager.getApplicableRegions(BlockVector3.at(l.getX(), l.getY(), l.getZ()))
.testState(null, new StateFlag[] { Flags.MOB_SPAWNING });
*/
}
}
/* (snip) */
The error can be avoided by refactoring the responsible method.