Skip to content

PlaceholderAPI expansion can NPE if a card doesn't exist for the requested player #319

Description

@dmccoystephenson

Where
src/main/java/dansplugins/rpsystem/placeholders/PlaceholderAPI.java, onPlaceholderRequest (all six card_* branches).

What
Each branch does:

return medievalRoleplayEngine.cardRepository.getCard(player.getUniqueId()).getName();

CardRepository.getCard(UUID) (src/main/java/dansplugins/rpsystem/cards/CardRepository.java) returns null when no card exists for that UUID, so this throws an NPE for any player without a card.

Why it's currently low-risk but still a gap
JoinListener creates a card for every player on PlayerJoinEvent, so in the common case (a placeholder evaluated for a currently-online player) a card always exists. The NPE would only surface for edge cases outside that guarantee — e.g. a placeholder consumer querying a player object before the join listener has run, or any future caller that evaluates placeholders for an offline/unloaded player.

Suggested fix
Null-guard each branch (e.g. extract CharacterCard card = ...cardRepository.getCard(...) once, return null/"" if card == null) so the expansion degrades gracefully instead of throwing.

Found while documenting the placeholder tokens in #303 / PR #318 — noted there rather than fixed, since that was a docs-only cycle.


This issue body was drafted during a Gardener session (Stephenson-Software/gardener).

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