Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix custom statistic criteria creation #9595

Merged
merged 1 commit into from
Aug 12, 2023

Conversation

NoahvdAa
Copy link
Member

When looking into fixing #9507 I noticed a lot more statistic criterion than just the play time were broken by the 'naive' enum -> key conversion. See the wiki for the full list, everything that doesn't match with the enum is broken.

Rather than having to update the entire enum with the correct names in the way lynx showed in this comment, I opted for grabbing the correct statistic key from the server itself, using unsafevalues to bridge the gap. This should be easier to maintain and will prevent us missing the enum update should the keys change again.

A proper, long-term solution would be #5691, but until then I believe this is best fix.

Fixes #9507.

@NoahvdAa NoahvdAa requested a review from a team as a code owner August 12, 2023 13:43
+
+ @Override
+ public String getStatisticCriteriaKey(org.bukkit.Statistic statistic) {
+ if (statistic.getType() != org.bukkit.Statistic.Type.UNTYPED) return "minecraft.custom:minecraft." + statistic.getKey().getKey();
Copy link
Member Author

Choose a reason for hiding this comment

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

For context; CraftStatistic#getNMSStatistic only allows looking up untyped statistics. Typed statistics don't/shouldn't work with the Criteria#static method anyway, as described in the javadocs, so this keeps the same behavior as before.

@lynxplay lynxplay force-pushed the fix/custom-statistic-criteria branch from 1afd12f to a7889a0 Compare August 12, 2023 21:28
@lynxplay lynxplay merged commit 29aaf7b into PaperMC:master Aug 12, 2023
1 check passed
@NoahvdAa NoahvdAa deleted the fix/custom-statistic-criteria branch August 12, 2023 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

PLAY_ONE_MINUTE statistic doesn't work as scoreboard objective
3 participants