Skip to content

Fix potential NullPointerException in passenger packet sending and NoSuchElementException in location-drift command - #75

Open
Spagles wants to merge 2 commits into
Cubicake:mainfrom
Spagles:main
Open

Fix potential NullPointerException in passenger packet sending and NoSuchElementException in location-drift command#75
Spagles wants to merge 2 commits into
Cubicake:mainfrom
Spagles:main

Conversation

@Spagles

@Spagles Spagles commented Aug 1, 2026

Copy link
Copy Markdown
  1. Prevents a NoSuchElementException when executing /raycastedantiesp test location-drift without any nearby entities present by checking isEmpty() before calling getFirst().
  2. Prevents a NullPointerException in sendEntityPassengerPacket when resolving a disconnected or null PacketEvents User channel, delegating packet writing to COMMON.writeIfPresent.

@CLAassistant

CLAassistant commented Aug 1, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@Cubicake

Cubicake commented Aug 1, 2026

Copy link
Copy Markdown
Owner

This should really be 2 different PRs but I get that they're very small fixes so I'll ignore that.

Can PacketEvents User ever be null without something being very broken? If it's a sign that something's gone catastrophically wrong, I'd rather not band-aid over it. Since you said disconnected I assume this can occur when a player logs out during packet processing? Have you observed this?

PlayerData playerData = PlayerRegistry.getInstance().getPlayerData(player.getUniqueId());
Entity closestEntity = player.getNearbyEntities(10,10,10).getFirst();
if (closestEntity == null) return;
var nearbyEntities = player.getNearbyEntities(10,10,10);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer not to use var

Entity closestEntity = player.getNearbyEntities(10,10,10).getFirst();
if (closestEntity == null) return;
var nearbyEntities = player.getNearbyEntities(10,10,10);
if (nearbyEntities.isEmpty()) return;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if this is going to be handled correctly instead of erroring, the player should be notified about why it failed

@Cubicake

Copy link
Copy Markdown
Owner

Are you going to update this PR or should I close it?

@Cubicake

Copy link
Copy Markdown
Owner

@Spagles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants