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

Update ExprTime #7082

Merged
merged 10 commits into from
Sep 22, 2024
Merged

Update ExprTime #7082

merged 10 commits into from
Sep 22, 2024

Conversation

Efnilite
Copy link
Member

Description

Resolves #7081.

  • Makes changing the time of worlds more predictable.
  • Updates the description to include a mention to the minecraft <timespan> syntax, as not using this to update the world's time results in confusing behaviour. Also explains that removing time from a world will move the clock forward a day.
  • Updated formatting.
  • Added test.

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

@Efnilite Efnilite added the bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. label Sep 15, 2024
Copy link
Contributor

@Asleeepp Asleeepp left a comment

Choose a reason for hiding this comment

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

since these are suggestions that arent really necessary ill just approve (even though my approval does nothing)

src/main/java/ch/njol/skript/expressions/ExprTime.java Outdated Show resolved Hide resolved
Comment on lines 90 to 114
long ticks = 0;
if (time instanceof Time) {
if (mode != ChangeMode.SET) {
ticks = ((Time) time).getTicks() - TIME_TO_TIMESPAN_OFFSET; // allows for using "add 2:00" without going to new day
} else {
ticks = ((Time) time).getTicks();
}
} else if (time instanceof Timespan) {
ticks = ((Timespan) time).getAs(Timespan.TimePeriod.TICK);
} else if (time instanceof Timeperiod) {
ticks = ((Timeperiod) time).start;
}

for (World world : worlds) {
switch (mode) {
case ADD:
world.setTime(world.getTime() + ticks);
break;
case REMOVE:
world.setTime(world.getTime() - ticks);
break;
case SET:
world.setTime(ticks);
break;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you could add the for loop to a helper method, and call the method in each of the instanceof checks, this avoids the need for the ticks variable (except for in time instanceof Time)

of course you dont have to do this, i just think it'll look a little neater

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea but i think this is easier to understand. if the team thinks your approach is better, i'll change it

Copy link
Contributor

@Fusezion Fusezion left a comment

Choose a reason for hiding this comment

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

Glad to see the speed in which this was fixed, I fully forgot mc time even existed, here's some task to show my appreciation

@sovdeeth sovdeeth added the patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version. label Sep 19, 2024
@sovdeeth sovdeeth merged commit 19985d9 into SkriptLang:dev/patch Sep 22, 2024
6 checks passed
@Efnilite Efnilite deleted the fix-time branch September 24, 2024 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants