I’m using Player.getDisplayNameData
to get a player’s display name, but it tries to call get
on an Absent
if the player has no custom display name.
Yet this issue specifically states that the DisplayNameData is implemented.
I’m using Player.getDisplayNameData
to get a player’s display name, but it tries to call get
on an Absent
if the player has no custom display name.
Yet this issue specifically states that the DisplayNameData is implemented.
Hmm, it should be implented, as shown here: https://github.com/SpongePowered/SpongeCommon/blob/master/src/main/java/org/spongepowered/common/data/manipulator/mutable/SpongeDisplayNameData.java
Have you tried using player.get(Keys.DISPLAY_NAME)
if you’re just wanting to get the display name?
Your problem is that if the player does not have a custom display name, it returns absent. Players don’t have custom display names.
So should I instead use getOrCreate
?
Edit: I fixed it, what I did was the following…
Optional<DisplayNameData> data;
if ((data = player.get(DisplayNameData.class)).isPresent())
return data.get().displayName().get();
else
return Texts.of(player.getName());