Skip to content

NullPointerException in PlayerInteractEvent when player cosmetics data is null (Paper 1.21.11) #13

@inkdASCENSION

Description

@inkdASCENSION

Describe the bug

  • Server: Paper 1.21.11
  • Plugin: AdvancedCosmetics v1.1.16
  • Java: 21 (or whatever you’re using)
  • Storage: (MySQL / Flatfile)

Description:

When a player interacts with a block, AdvancedCosmetics throws a NullPointerException because PlayerCosmeticsHandler#getCosmetics(UUID) can return null, but the result is used without a null check.

Stacktrace:

This happens inside PlayerListeners#onInteractBlock, causing the PlayerInteractEvent to fail.

java.lang.NullPointerException: Cannot invoke 
"net.advancedplugins.cosmetics.playerCosmetics.data.PlayerCosmetics.getCosmetics()" 
because the return value of 
"net.advancedplugins.cosmetics.playerCosmetics.PlayerCosmeticsHandler.getCosmetics(UUID)" 
is null
    at net.advancedplugins.cosmetics.listeners.PlayerListeners.onInteractBlock(PlayerListeners.java:109)
    ...

Expected Behavior

The plugin should safely handle cases where player cosmetics data is not yet loaded or failed to initialize (e.g. skip processing or load data before access).

Actual Behavior

The plugin assumes cosmetics data is always present and throws an NPE when it is not.

How to reproduce

Happens when players join the server

Notes / Possible Cause

This may occur if player cosmetics data fails to load, or during certain lifecycle states (first join, plugin reload, or DB delay).

A simple null check before accessing getCosmetics() would prevent the crash.

Screenshots / Videos

No response

Server Log

https://mcpaste.com/df9aa8fcd8366beaa96cc96ffa3b0560

Filled out form correct and using latest version

I confirm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions