Patbox / TextPlaceholderAPI

Placeholder API for Fabric
GNU Lesser General Public License v3.0
39 stars 16 forks source link

player:statistic doesn't work properly #26

Closed NyakoFox closed 2 years ago

NyakoFox commented 2 years ago

I want to use the fish caught statistic in text. For that, I'm just writing %player:statistic fish_caught%. However, that returns "Invalid statistic", despite it being valid. I also tried minecraft:fish_caught, but it was the same.

I looked in the code, and noticed the following:

ctx.player().getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Identifier.tryParse("minecraft:fish_caught"))) this doesn't work, but it's basically what placeholder api does.

ctx.player().getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Stats.FISH_CAUGHT)) this DOES work, despite it being an identifier, containing "minecraft:fish_caught"...

This is because stats are stored in an IdentityHashMap, which use reference equality. You can't make a new identifier and pass it in.

A fix would be, instead of doing getOrCreateStat(identifier), do getOrCreateStat(Registry.CUSTOM_STAT.get(identifier)). I haven't tested, but this seems to fix the issue.

NyakoFox commented 2 years ago

apparently this is already fixed... whoops. must not have the latest version of the api