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

Rework number parser and angle support #7139

Merged
merged 40 commits into from
Dec 15, 2024
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1001e4f
init commit
Efnilite Oct 9, 2024
f461b24
oops
Efnilite Oct 9, 2024
b3849ce
Merge branch 'dev/feature' into angle
Efnilite Oct 9, 2024
9998616
removed unnecessary checks
Efnilite Oct 9, 2024
efbb1af
Merge remote-tracking branch 'origin/angle' into angle
Efnilite Oct 9, 2024
52d028a
update other syntaxes
Efnilite Oct 9, 2024
b4a1f37
move to parser
Efnilite Oct 9, 2024
cef8b87
oops
Efnilite Oct 9, 2024
c5d5c25
big work
Efnilite Oct 10, 2024
b378a30
forgot !
Efnilite Oct 10, 2024
036adf3
fix doubleValue call
Efnilite Oct 10, 2024
491c7cf
fix parenthesis
Efnilite Oct 11, 2024
fcd2c60
add expression
Efnilite Oct 11, 2024
46b507e
update tests
Efnilite Oct 12, 2024
8d552b9
requested changes
Efnilite Oct 12, 2024
27d0c78
oops
Efnilite Oct 12, 2024
6ee87f1
remove unnecessary converter application
Efnilite Oct 12, 2024
79ce823
remove converter
Efnilite Oct 12, 2024
87b9e84
le fix
Efnilite Oct 13, 2024
a0212de
Merge branch 'dev/feature' into angle
Efnilite Oct 13, 2024
18bf9c7
fix merge w/ display entities
Efnilite Oct 13, 2024
ad27be8
most "regular" regex
Efnilite Oct 13, 2024
cfd09ce
Merge branch 'dev/feature' into angle
sovdeeth Oct 15, 2024
38543ca
fix tests
Efnilite Oct 17, 2024
983e376
fix _ support
Efnilite Oct 17, 2024
a6b27bc
fix rotate
Efnilite Oct 17, 2024
e392b57
Merge branch 'dev/feature' into angle
Efnilite Oct 26, 2024
8d0e8c5
Merge branch 'dev/feature' into angle
Efnilite Oct 28, 2024
686ddc3
minor changes
Efnilite Oct 28, 2024
b5168cc
remove double return
Efnilite Oct 28, 2024
6707d0d
fix ExprRotate
Efnilite Oct 28, 2024
f9afddb
Merge branch 'dev/feature' into angle
Efnilite Nov 1, 2024
e4cd70b
Merge branch 'dev/feature' into angle
Efnilite Nov 5, 2024
d8daf93
Merge branch 'dev/feature' into angle
sovdeeth Nov 8, 2024
656e4ad
Merge branch 'dev/feature' into angle
Efnilite Nov 10, 2024
a9402b5
Merge branch 'dev/feature' into angle
Efnilite Nov 14, 2024
dacf629
oopsie
Efnilite Nov 20, 2024
ae2765a
Merge branch 'dev/feature' into angle
Moderocky Nov 30, 2024
28742ef
Merge branch 'dev/feature' into angle
Efnilite Dec 6, 2024
abd2873
Merge branch 'dev/feature' into angle
sovdeeth Dec 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add expression
  • Loading branch information
Efnilite committed Oct 11, 2024
commit fcd2c60663b4b83fbce9541a15bcb42342a0c0b5
78 changes: 78 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprAngle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ch.njol.skript.expressions;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
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.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

@Name("Angle")
@Description({
"Represents the passed number value in degrees.",
"If radians is specified, converts the passed value to degrees. This conversion may not be entirely accurate, " +
"due to floating point precision.",
Efnilite marked this conversation as resolved.
Show resolved Hide resolved
})
@Examples({
"set {_angle} to 90 degrees",
"{_angle} is 90 # true",
"180 degrees is pi # true",
"pi radians is 180 degrees # true"
})
@Since("INSERT VERSION")
public class ExprAngle extends SimpleExpression<Number> {

static {
Skript.registerExpression(ExprAngle.class, Number.class, ExpressionType.SIMPLE,
"%number% [in ]deg[ree][s]",
"%number% [in ]rad[ian][s]");
Efnilite marked this conversation as resolved.
Show resolved Hide resolved
}

private Expression<Number> angle;
private boolean isRadians;

@Override
public boolean init(Expression<?>[] expressions, int matchedPattern,
Kleenean isDelayed, ParseResult parseResult) {
//noinspection unchecked
angle = (Expression<Number>) expressions[0];
isRadians = matchedPattern == 1;
return true;
}

@Override
protected Number @Nullable [] get(Event event) {
Number number = angle.getSingle(event);

if (number == null)
return null;

if (isRadians) {
return new Double[]{Math.toDegrees(number.doubleValue())};
}
Efnilite marked this conversation as resolved.
Show resolved Hide resolved

return new Number[]{number};
}

@Override
public boolean isSingle() {
return true;
}

@Override
public Class<? extends Number> getReturnType() {
return Number.class;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return angle.toString(event, debug) + (isRadians ? " degrees" : " radians");
}

}
Efnilite marked this conversation as resolved.
Show resolved Hide resolved