-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Better Stats API #12699
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
Open
Machine-Maker
wants to merge
3
commits into
PaperMC:main
Choose a base branch
from
Machine-Maker:feature/better-stats-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Better Stats API #12699
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
573 changes: 573 additions & 0 deletions
573
paper-api/src/generated/java/io/papermc/paper/registry/keys/CustomStatisticKeys.java
Large diffs are not rendered by default.
Oops, something went wrong.
97 changes: 97 additions & 0 deletions
97
paper-api/src/generated/java/io/papermc/paper/registry/keys/StatisticTypeKeys.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package io.papermc.paper.registry.keys; | ||
|
|
||
| import static net.kyori.adventure.key.Key.key; | ||
|
|
||
| import io.papermc.paper.annotation.GeneratedClass; | ||
| import io.papermc.paper.registry.RegistryKey; | ||
| import io.papermc.paper.registry.TypedKey; | ||
| import io.papermc.paper.statistic.StatisticType; | ||
| import net.kyori.adventure.key.Key; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Vanilla keys for {@link RegistryKey#STAT_TYPE}. | ||
| * | ||
| * @apiNote The fields provided here are a direct representation of | ||
| * what is available from the vanilla game source. They may be | ||
| * changed (including removals) on any Minecraft version | ||
| * bump, so cross-version compatibility is not provided on the | ||
| * same level as it is on most of the other API. | ||
| */ | ||
| @SuppressWarnings({ | ||
| "unused", | ||
| "SpellCheckingInspection" | ||
| }) | ||
| @NullMarked | ||
| @GeneratedClass | ||
| public final class StatisticTypeKeys { | ||
| /** | ||
| * {@code minecraft:broken} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<StatisticType<?>> BROKEN = create(key("broken")); | ||
|
|
||
| /** | ||
| * {@code minecraft:crafted} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<StatisticType<?>> CRAFTED = create(key("crafted")); | ||
|
|
||
| /** | ||
| * {@code minecraft:custom} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<StatisticType<?>> CUSTOM = create(key("custom")); | ||
|
|
||
| /** | ||
| * {@code minecraft:dropped} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<StatisticType<?>> DROPPED = create(key("dropped")); | ||
|
|
||
| /** | ||
| * {@code minecraft:killed} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<StatisticType<?>> KILLED = create(key("killed")); | ||
|
|
||
| /** | ||
| * {@code minecraft:killed_by} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<StatisticType<?>> KILLED_BY = create(key("killed_by")); | ||
|
|
||
| /** | ||
| * {@code minecraft:mined} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<StatisticType<?>> MINED = create(key("mined")); | ||
|
|
||
| /** | ||
| * {@code minecraft:picked_up} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<StatisticType<?>> PICKED_UP = create(key("picked_up")); | ||
|
|
||
| /** | ||
| * {@code minecraft:used} | ||
| * | ||
| * @apiNote This field is version-dependant and may be removed in future Minecraft versions | ||
| */ | ||
| public static final TypedKey<StatisticType<?>> USED = create(key("used")); | ||
|
|
||
| private StatisticTypeKeys() { | ||
| } | ||
|
|
||
| private static TypedKey<StatisticType<?>> create(final Key key) { | ||
| return TypedKey.create(RegistryKey.STAT_TYPE, key); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
paper-api/src/main/java/io/papermc/paper/event/player/PlayerRequestStatisticsEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package io.papermc.paper.event.player; | ||
|
|
||
| import io.papermc.paper.statistic.Statistic; | ||
| import it.unimi.dsi.fastutil.objects.Object2IntMap; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.event.Cancellable; | ||
| import org.bukkit.event.HandlerList; | ||
| import org.bukkit.event.player.PlayerEvent; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| /** | ||
| * Called when the player requests their statistics. | ||
| */ | ||
| @NullMarked | ||
| public class PlayerRequestStatisticsEvent extends PlayerEvent implements Cancellable { | ||
|
|
||
| private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
|
||
| private final Object2IntMap<Statistic<?>> statisticMap; | ||
| private boolean cancelled; | ||
|
|
||
| @ApiStatus.Internal | ||
| public PlayerRequestStatisticsEvent(final Player player, final Object2IntMap<Statistic<?>> statisticMap) { | ||
| super(player); | ||
| this.statisticMap = statisticMap; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the statistic map to be sent to the player. | ||
| * | ||
| * @return the mutable statistic map | ||
| */ | ||
| public Object2IntMap<Statistic<?>> getStatisticMap() { | ||
| return this.statisticMap; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isCancelled() { | ||
| return this.cancelled; | ||
| } | ||
|
|
||
| @Override | ||
| public void setCancelled(final boolean cancel) { | ||
| this.cancelled = cancel; | ||
| } | ||
|
|
||
| @Override | ||
| public HandlerList getHandlers() { | ||
| return HANDLER_LIST; | ||
| } | ||
|
|
||
| public static HandlerList getHandlerList() { | ||
| return HANDLER_LIST; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
paper-api/src/main/java/io/papermc/paper/statistic/CustomStatistic.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package io.papermc.paper.statistic; | ||
|
|
||
| import net.kyori.adventure.translation.Translatable; | ||
| import org.bukkit.Keyed; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| /** | ||
| * Represents a statistic of the type {@link StatisticTypes#CUSTOM}. | ||
| * | ||
| * @see CustomStatistics | ||
| */ | ||
| @ApiStatus.NonExtendable | ||
| public interface CustomStatistic extends Keyed, Translatable { | ||
|
|
||
| /** | ||
| * Gets the statistic with the given custom stat. | ||
| * | ||
| * @return the statistic for the custom stat | ||
| */ | ||
| default Statistic<CustomStatistic> stat() { | ||
| return StatisticTypes.CUSTOM.forValue(this); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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