-
-
Notifications
You must be signed in to change notification settings - Fork 399
Add infinite timespans #7956
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
sovdeeth
wants to merge
3
commits into
SkriptLang:dev/feature
Choose a base branch
from
sovdeeth:feature/forever
base: dev/feature
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.
+194
−29
Open
Add infinite timespans #7956
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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,50 @@ | ||
package ch.njol.skript.expressions; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.Description; | ||
import ch.njol.skript.doc.Example; | ||
import ch.njol.skript.doc.Name; | ||
import ch.njol.skript.doc.Since; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.lang.util.SimpleLiteral; | ||
import ch.njol.skript.util.Timespan; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("An Eternity") | ||
@Description({"Represents a timespan with an infinite duration. " + | ||
"An eternity is also created when arithmetic results in a timespan larger than about 292 million years.", | ||
"Infinite timespans generally follow the rules of infinity, where most math operations do nothing. " + | ||
"However, operations that would return NaN with numbers will instead return a timespan of 0 seconds.", | ||
"Note that an eternity will often be treated as the longest duration something supports, rather than a true eternity." | ||
}) | ||
@Example("set fire to the player for an eternity") | ||
@Since("INSERT VERSION") | ||
public class LitEternity extends SimpleLiteral<Timespan> { | ||
|
||
static { | ||
Skript.registerExpression(LitEternity.class, Timespan.class, ExpressionType.SIMPLE, | ||
"[an] eternity", | ||
"forever", | ||
"[an] (indefinite|infinite) (duration|timespan)" | ||
); | ||
sovdeeth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
public LitEternity() { | ||
super(new Timespan[]{Timespan.infinite()}, Timespan.class, true); | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { | ||
sovdeeth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "an eternity"; | ||
} | ||
|
||
} |
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
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
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
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,28 @@ | ||
test "eternity": | ||
set {_a} to forever | ||
assert {_a} is forever with "comparison failed" | ||
assert {_a} is an eternity with "comparison failed" | ||
assert {_a} is an infinite duration with "comparison failed" | ||
|
||
add 10 seconds to {_a} | ||
assert {_a} is an eternity with "adding changed infinity" | ||
|
||
remove 10 seconds from {_a} | ||
assert {_a} is an eternity with "subtraction changed infinity" | ||
|
||
assert {_a} / 10 seconds is infinity value with "division by timespan didn't return infinity" | ||
assert isNaN({_a} / {_a}) is true with "division by eternity didn't return NaN" | ||
|
||
assert {_a} / 10 is an eternity with "division by number didn't return eternity" | ||
assert {_a} * 10 is an eternity with "multiplication by number didn't return eternity" | ||
|
||
assert 1 second * infinity value is an eternity with "timespan * infinity wasn't an eternity" | ||
assert infinity value * 1 second is an eternity with "timespan * infinity wasn't an eternity" | ||
|
||
assert -infinity value * 1 second is not set with "timespan * -infinity was set" | ||
|
||
assert 1 year * 10000000000 is an eternity with "overflow did not create an eternity" | ||
|
||
set {_a} to a potion effect of speed for an eternity | ||
assert {_a} is infinite with "potion effect was not infinite" | ||
assert {_a} is infinite | ||
sovdeeth marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Uh oh!
There was an error while loading. Please reload this page.