Skip to content

Better Stats API#12699

Open
Machine-Maker wants to merge 3 commits intoPaperMC:mainfrom
Machine-Maker:feature/better-stats-api
Open

Better Stats API#12699
Machine-Maker wants to merge 3 commits intoPaperMC:mainfrom
Machine-Maker:feature/better-stats-api

Conversation

@Machine-Maker
Copy link
Member

Replaces #11834

@Machine-Maker Machine-Maker requested a review from a team as a code owner June 19, 2025 20:51
@github-project-automation github-project-automation bot moved this to Awaiting review in Paper PR Queue Jun 19, 2025
@Machine-Maker Machine-Maker force-pushed the feature/better-stats-api branch 2 times, most recently from 1544ca8 to d0244c7 Compare June 21, 2025 19:41
@Machine-Maker Machine-Maker moved this from Awaiting review to Awaiting final testing in Paper PR Queue Jun 21, 2025
Comment on lines +38 to +51
+
+ // Paper start
+ if (io.papermc.paper.event.player.PlayerRequestStatisticsEvent.getHandlerList().getRegisteredListeners().length > 0) {
+ io.papermc.paper.event.player.PlayerRequestStatisticsEvent statEvent = new io.papermc.paper.event.player.PlayerRequestStatisticsEvent(
+ player.getBukkitEntity(),
+ map.object2IntEntrySet()
+ .stream()
+ .collect(Object2IntOpenHashMap::new, (map1, entry) -> map1.put(io.papermc.paper.statistic.PaperStatistics.getPaperStatistic(entry.getKey()), entry.getIntValue()), Object2IntOpenHashMap::putAll)
+ );
+ if (!statEvent.callEvent()) {
+ return;
+ }
+ map = statEvent.getStatisticMap().object2IntEntrySet().stream().collect(Object2IntOpenHashMap::new, (map1, entry) -> map1.put(io.papermc.paper.statistic.PaperStatistics.getNMSStatistic(entry.getKey()), entry.getIntValue()), Object2IntOpenHashMap::putAll);
+ }
Copy link
Member

Choose a reason for hiding this comment

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

I am not quite sure about canceling this? As this will cause the menu to just reveal a blank screen which may be very confusing. At least, I think this should be documented.

Copy link
Contributor

Choose a reason for hiding this comment

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

In my Stats request PR I answered with an empty map because the client would show a loading screen until it got an update if the stats weren't cached before
(Not 100% sure if that is vanilla behavior since I have a few mods installed that might change that behavior, but just in case)
Maybe the same documentation I had could be applied?

@Machine-Maker Machine-Maker force-pushed the feature/better-stats-api branch from 80a4b7f to 201d4e4 Compare June 28, 2025 21:20
@Lulu13022002 Lulu13022002 force-pushed the feature/better-stats-api branch 2 times, most recently from 9a5d7dd to c065539 Compare August 5, 2025 17:55
*
* @return the stat owner
*/
S owner();
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't fully understand the renaming to #owner
Wouldn't #type make more sense?
Owner sounds like the owning player of the statistic

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really know what to call it. Nothing seems good to me. type feels wrong, cause its not StatisticType.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about those options: #statistic, #kind, #metric?

But in general I thought #value was a good fit.

Copy link
Member Author

Choose a reason for hiding this comment

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

value feels like it should be the numeric value.

@Lulu13022002 Lulu13022002 force-pushed the feature/better-stats-api branch 2 times, most recently from fed3d15 to ebd1340 Compare October 7, 2025 19:11
@Machine-Maker Machine-Maker force-pushed the feature/better-stats-api branch 2 times, most recently from cb8b037 to 89ab2a1 Compare November 29, 2025 19:29
*
* @return the mutable statistic map
*/
public Object2IntMap<Statistic<?>> getStatisticMap() {
Copy link
Member

Choose a reason for hiding this comment

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

Only exposing a regular Map<Statistic<?>, Integer> would seem better for future proofing, Object2IntMap extends that so no extra conversion is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure then plugins can't get the primitive without (un)boxing or casting the map.

Copy link
Member

Choose a reason for hiding this comment

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

In some cases it would still help having it backed by the fu map, but not really here

@Lulu13022002 Lulu13022002 force-pushed the feature/better-stats-api branch from 9cbdabe to b9342e1 Compare January 28, 2026 21:48
@Lulu13022002 Lulu13022002 force-pushed the feature/better-stats-api branch from 9623d04 to 5cb864b Compare January 30, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting final testing

Development

Successfully merging this pull request may close these issues.

6 participants