Skip to content

Conversation

@Burbulinis
Copy link
Contributor

@Burbulinis Burbulinis commented Feb 1, 2025

Description

This PR aims to add player statistics and closes the beloved and old issue #4687! Here's a slight glimpse of how statistics will look like:

set {_int value} to statistic leave game statistic of player # returns an int, but eh... 'played time of player' exists set {_play time} to statistic ticks played statistic of player # or set {_play time} to statistic play one minute statistic of player # here comes some fun set {_usage count} to statistic use item statistic for grass block of player set {_pig kill count} to statistic kill entity statistic for a pig of player on player statistic increase: send "Wow! The %event-statistic% increased! It's now %future statistic value%" on player statistic increase of use item statistic: send event-itemtype on player statistic increase of leave game statistic: broadcast "wow... %player% left for the %future statistic value%th time..."

Target Minecraft Versions: any
Requirements: none
Related Issues: #4687

@Efnilite Efnilite added the feature Pull request adding a new feature. label Feb 1, 2025
@Burbulinis Burbulinis requested a review from Efnilite February 1, 2025 21:41
@sovdeeth
Copy link
Member

sovdeeth commented Feb 2, 2025

I think the strings should be parsed into actual Statistics whenever possible, for faster comparison and to allow proper errors.
Which leads to asking why they're strings to begin with? Why not just an enum classinfo? jump statistic, walk one cm stat, etc

@Burbulinis
Copy link
Contributor Author

Burbulinis commented Feb 22, 2025

I think the strings should be parsed into actual Statistics whenever possible, for faster comparison and to allow proper errors. Which leads to asking why they're strings to begin with? Why not just an enum classinfo? jump statistic, walk one cm stat, etc

I have made them actual enums now. My initial thought was that they should be strings, because there's a lot of enums. But I've looked at the default lang file and I saw that there are even more (of other enums) compared to statistics.


static {
Skript.registerExpression(ExprNewStatisticValue.class, Number.class, ExpressionType.SIMPLE,
"(future|new) statistic [value]", "(past|previous) statistic [value]");
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole class should be an EventValueExpression. What you do is register the numbers as event values TIME_FUTURE and TIME_PAST then the EventValueExpression will automatically be able to grab the future and past values. This is because there is already a syntax for future and past in ExprEventValue

Copy link
Contributor Author

@Burbulinis Burbulinis Feb 25, 2025

Choose a reason for hiding this comment

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

I've already tried that (if you specifically mean registering the event value within the event), but it didn't work.
I registered the event value for an integer, a number and neither past/future event-integer or event-number worked

edit: I also prefer this expression over event-number because just by looking at event-number i cannot know what it is

Copy link
Member

Choose a reason for hiding this comment

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

I'd like to re-open this a bit because Lime is correct that a EVE would be more appropriate, since then you use setTime to control past/future automatically. However, I think that would leave the syntax as statistic [value] which would interfere with the classinfo itself. That said, statistic value is a less ambiguous name and doesn't conflict at all, which I think I would prefer to see.

@Burbulinis Burbulinis requested a review from sovdeeth February 25, 2025 20:22
@Burbulinis Burbulinis requested a review from a team as a code owner March 29, 2025 22:00
@Burbulinis Burbulinis requested review from cheeezburga and removed request for a team March 29, 2025 22:00
@Burbulinis Burbulinis requested a review from erenkarakal March 29, 2025 22:00
@Burbulinis
Copy link
Contributor Author

i have no clue what happened to tests

@sovdeeth sovdeeth force-pushed the feature/statistic branch from d2556c8 to 986470e Compare March 29, 2025 23:58

static {
Skript.registerEvent("Player Statistic Change", EvtPlayerStatisticChange.class, PlayerStatisticIncrementEvent.class,
"player statistic (change|increase|increment) [of %-statistics% statistic[s]]",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"player statistic (change|increase|increment) [of %-statistics% statistic[s]]",
"player statistic (change|increase|increment) [of %-statistics% statistic[s]]",

static {
Skript.registerExpression(ExprNewStatisticValue.class, Number.class, ExpressionType.SIMPLE,
"(future|new) statistic [value]", "(past|previous) statistic [value]");
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to re-open this a bit because Lime is correct that a EVE would be more appropriate, since then you use setTime to control past/future automatically. However, I think that would leave the syntax as statistic [value] which would interfere with the classinfo itself. That said, statistic value is a less ambiguous name and doesn't conflict at all, which I think I would prefer to see.

}
}

private boolean shouldStop(Statistic statistic, Object ofType) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private boolean shouldStop(Statistic statistic, Object ofType) {
private boolean checkTyping(Statistic statistic, Object ofType) {

some short javadocs for this method and the others would be nice

@skriptlang-automation skriptlang-automation bot added needs reviews A PR that needs additional reviews and removed needs reviews A PR that needs additional reviews labels May 15, 2025
@sovdeeth
Copy link
Member

sovdeeth commented Jun 3, 2025

Do you still intend to work on this?

@Burbulinis Burbulinis closed this Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Pull request adding a new feature.

5 participants