Skip to content

Commit c3f4a4f

Browse files
committed
Replace ExprSpecialNumber with specific literals, make value optional
1 parent 5dce04a commit c3f4a4f

4 files changed

Lines changed: 130 additions & 58 deletions

File tree

src/main/java/ch/njol/skript/expressions/ExprSpecialNumber.java

Lines changed: 0 additions & 58 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ch.njol.skript.expressions;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Example;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.Expression;
9+
import ch.njol.skript.lang.ExpressionType;
10+
import ch.njol.skript.lang.SkriptParser.ParseResult;
11+
import ch.njol.skript.lang.util.SimpleLiteral;
12+
import ch.njol.util.Kleenean;
13+
import org.bukkit.event.Event;
14+
import org.jetbrains.annotations.Nullable;
15+
16+
@Name("Infinity")
17+
@Description("A number representing positive infinity.")
18+
@Example("if {_number} is infinity:")
19+
@Since("2.2-dev32d")
20+
public class LitInfinity extends SimpleLiteral<Double> {
21+
22+
static {
23+
Skript.registerExpression(LitInfinity.class, Double.class, ExpressionType.SIMPLE,
24+
"[positive] (infinity|∞) [value]",
25+
"value of [positive] (infinity|∞)");
26+
}
27+
28+
public LitInfinity() {
29+
super(Double.POSITIVE_INFINITY, false);
30+
}
31+
32+
@Override
33+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
34+
return true;
35+
}
36+
37+
@Override
38+
public String toString(@Nullable Event event, boolean debug) {
39+
return "infinity";
40+
}
41+
42+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package ch.njol.skript.expressions;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Example;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.Expression;
9+
import ch.njol.skript.lang.ExpressionType;
10+
import ch.njol.skript.lang.SkriptParser.ParseResult;
11+
import ch.njol.skript.lang.util.SimpleLiteral;
12+
import ch.njol.util.Kleenean;
13+
import org.bukkit.event.Event;
14+
import org.jetbrains.annotations.Nullable;
15+
16+
@Name("NaN")
17+
@Description({
18+
"A number representing an undefined value. NaN occurs as a result of illegal math, like dividing 0 by 0.",
19+
"NaN is deliberately not equal to any other number, including itself.",
20+
})
21+
@Example("if {_number} is not {_number}:")
22+
@Example("if isNaN({_number}) is true:")
23+
@Since("2.2-dev32d")
24+
public class LitNaN extends SimpleLiteral<Double> {
25+
26+
static {
27+
Skript.registerExpression(LitNaN.class, Double.class, ExpressionType.SIMPLE,
28+
"NaN [value]",
29+
"value of NaN");
30+
}
31+
32+
public LitNaN() {
33+
super(Double.NaN, false);
34+
}
35+
36+
@Override
37+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
38+
return true;
39+
}
40+
41+
@Override
42+
public String toString(@Nullable Event event, boolean debug) {
43+
return "NaN";
44+
}
45+
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ch.njol.skript.expressions;
2+
3+
import ch.njol.skript.Skript;
4+
import ch.njol.skript.doc.Description;
5+
import ch.njol.skript.doc.Example;
6+
import ch.njol.skript.doc.Name;
7+
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.lang.Expression;
9+
import ch.njol.skript.lang.ExpressionType;
10+
import ch.njol.skript.lang.SkriptParser.ParseResult;
11+
import ch.njol.skript.lang.util.SimpleLiteral;
12+
import ch.njol.util.Kleenean;
13+
import org.bukkit.event.Event;
14+
import org.jetbrains.annotations.Nullable;
15+
16+
@Name("Negative Infinity")
17+
@Description("A number representing negative infinity.")
18+
@Example("if {_number} is -infinity:")
19+
@Since("2.2-dev32d")
20+
public class LitNegativeInfinity extends SimpleLiteral<Double> {
21+
22+
static {
23+
Skript.registerExpression(LitInfinity.class, Double.class, ExpressionType.SIMPLE,
24+
"(-|minus |negative )(infinity|∞) [value]",
25+
"value of (-|minus |negative )(infinity|∞)");
26+
}
27+
28+
public LitNegativeInfinity() {
29+
super(Double.NEGATIVE_INFINITY, false);
30+
}
31+
32+
@Override
33+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
34+
return true;
35+
}
36+
37+
@Override
38+
public String toString(@Nullable Event event, boolean debug) {
39+
return "negative infinity";
40+
}
41+
42+
}

0 commit comments

Comments
 (0)