Skip to content

Commit 677eaf3

Browse files
Merge branch 'dev/feature' into feature/simplification-2
2 parents 88bd5b1 + 5edd3bb commit 677eaf3

14 files changed

Lines changed: 330 additions & 44 deletions

File tree

LICENSING.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Skript is licensed under the [GNU General Public License (Version 3)](LICENSE).
2+
3+
However, to foster a better open-source community, and in the interest of further opening this project in the future,
4+
we ask that contributors release their code under the MIT License.
5+
Since it is less restrictive than GPLv3, it provides us and other developers
6+
with greater flexibility when making use of contributed code.
7+
8+
To learn more about this license, you can visit [choosealicense.com](https://choosealicense.com/licenses/mit/).
9+
You can also view the full text of the license below:
10+
<details>
11+
<summary>MIT License</summary>
12+
13+
```text
14+
Permission is hereby granted, free of charge, to any person obtaining a copy
15+
of this software and associated documentation files (the "Software"), to deal
16+
in the Software without restriction, including without limitation the rights
17+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18+
copies of the Software, and to permit persons to whom the Software is
19+
furnished to do so, subject to the following conditions:
20+
21+
The above copyright notice and this permission notice shall be included in all
22+
copies or substantial portions of the Software.
23+
24+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
SOFTWARE.
31+
```
32+
</details>
33+
34+
If you wish to release your contributions to this repository under the MIT License,
35+
please add your name below in your pull request.
36+
37+
When adding your name, please follow the example format below:
38+
39+
`<name> (<commit email address>)`
40+
> [!NOTE]
41+
> For name, you may choose to use your real name or GitHub account name. \
42+
> If you use more than one commit email address, please include all of them.
43+
44+
```text
45+
APickledWalrus (apickledwalrus@icloud.com, apickledwalrus@gmail.com)
46+
Sovde (10354869+sovdeeth@users.noreply.github.com)
47+
UnderscoreTud (98935832+UnderscoreTud@users.noreply.github.com)
48+
```

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,6 @@ contact us about any problems you might have with them.
191191
## Developers
192192
You can find all contributors [here](https://github.com/SkriptLang/Skript/graphs/contributors).
193193

194-
All code is owned by its writer, licensed for others under GPLv3 (see LICENSE)
195-
unless otherwise specified.
194+
All code is owned by its writer, licensed for others under GPLv3 (see [LICENSE](LICENSE)).
195+
Some contributors may choose to release their code under the MIT License.
196+
Further information can be found within [LICENSING.md](LICENSING.md).

code-conventions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ With the exception of contacting our own resources (e.g. to check for updates) c
6464
## Licensing
6565

6666
Code contributed must be licensed under GPLv3, by **you**.
67+
Some contributors may choose to release their code under the MIT License.
68+
Further information can be found within [LICENSING.md](LICENSING.md).
6769
We expect that any code you contribute is either owned by you or you have explicit permission to provide and license it to us.
6870

6971
Licenses do not need to be printed in individual files (or packages) unless the licence applying to the code in

src/main/java/ch/njol/skript/classes/data/DefaultOperations.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import ch.njol.skript.util.Date;
44
import ch.njol.skript.util.Timespan;
5-
import ch.njol.skript.util.Timespan.TimePeriod;
65
import ch.njol.skript.util.Utils;
76
import org.bukkit.util.Vector;
87
import org.skriptlang.skript.lang.arithmetic.Arithmetics;
@@ -92,36 +91,30 @@ public class DefaultOperations {
9291
// Timespan - Timespan
9392
Arithmetics.registerOperation(Operator.ADDITION, Timespan.class, Timespan::add);
9493
Arithmetics.registerOperation(Operator.SUBTRACTION, Timespan.class, Timespan::subtract);
94+
Arithmetics.registerOperation(Operator.DIVISION, Timespan.class, Timespan.class, Number.class, Timespan::divide);
9595
Arithmetics.registerDifference(Timespan.class, Timespan::difference);
9696
Arithmetics.registerDefaultValue(Timespan.class, Timespan::new);
9797

9898
// Timespan - Number
9999
// Number - Timespan
100100
Arithmetics.registerOperation(Operator.MULTIPLICATION, Timespan.class, Number.class, (left, right) -> {
101101
double scalar = right.doubleValue();
102-
if (scalar < 0 || !Double.isFinite(scalar))
102+
if (scalar < 0 || Double.isNaN(scalar))
103103
return null;
104-
double value = left.getAs(TimePeriod.MILLISECOND) * scalar;
105-
return new Timespan((long) Math.min(value, Long.MAX_VALUE));
104+
return left.multiply(scalar);
106105
}, (left, right) -> {
107106
double scalar = left.doubleValue();
108-
if (scalar < 0 || !Double.isFinite(scalar))
107+
if (scalar < 0 || Double.isNaN(scalar))
109108
return null;
110-
double value = right.getAs(TimePeriod.MILLISECOND) * scalar;
111-
return new Timespan((long) Math.min(value, Long.MAX_VALUE));
109+
return right.multiply(scalar);
112110
});
113111
Arithmetics.registerOperation(Operator.DIVISION, Timespan.class, Number.class, (left, right) -> {
114112
double scalar = right.doubleValue();
115-
if (scalar <= 0 || !Double.isFinite(scalar))
113+
if (scalar < 0 || Double.isNaN(scalar))
116114
return null;
117-
double value = left.getAs(TimePeriod.MILLISECOND) / scalar;
118-
return new Timespan((long) Math.min(value, Long.MAX_VALUE));
115+
return left.divide(scalar);
119116
});
120117

121-
// Timespan / Timespan = Number
122-
Arithmetics.registerOperation(Operator.DIVISION, Timespan.class, Timespan.class, Number.class,
123-
(left, right) -> left.getAs(TimePeriod.MILLISECOND) / (double) right.getAs(TimePeriod.MILLISECOND));
124-
125118
// Date - Timespan
126119
Arithmetics.registerOperation(Operator.ADDITION, Date.class, Timespan.class, Date::plus);
127120
Arithmetics.registerOperation(Operator.SUBTRACTION, Date.class, Timespan.class, Date::minus);

src/main/java/ch/njol/skript/conditions/CondIsInfinite.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@
22

33
import ch.njol.skript.conditions.base.PropertyCondition;
44
import ch.njol.skript.doc.Description;
5-
import ch.njol.skript.doc.Examples;
5+
import ch.njol.skript.doc.Example;
66
import ch.njol.skript.doc.Name;
77
import ch.njol.skript.doc.Since;
8+
import ch.njol.skript.util.Timespan;
89
import org.bukkit.potion.PotionEffect;
910

10-
// This class can be expanded apon for other types if needed.
1111
@Name("Is Infinite")
12-
@Description("Checks whether potion effects are infinite.")
13-
@Examples("all of the active potion effects of the player are infinite")
12+
@Description("Checks whether potion effects or timespans are infinite.")
13+
@Example("all of the active potion effects of the player are infinite")
14+
@Example("if timespan argument is infinite:")
1415
@Since("2.7")
15-
public class CondIsInfinite extends PropertyCondition<PotionEffect> {
16+
public class CondIsInfinite extends PropertyCondition<Object> {
1617

1718
static {
18-
register(CondIsInfinite.class, "infinite", "potioneffects");
19+
register(CondIsInfinite.class, "infinite", "potioneffects/timespans");
1920
}
2021

2122
@Override
22-
public boolean check(PotionEffect potion) {
23-
return potion.isInfinite();
23+
public boolean check(Object object) {
24+
if (object instanceof PotionEffect potionEffect)
25+
return potionEffect.isInfinite();
26+
if (object instanceof Timespan timespan)
27+
return timespan.isInfinite();
28+
return false;
2429
}
2530

2631
@Override

src/main/java/ch/njol/skript/effects/EffPotion.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ protected void execute(Event event) {
107107
Timespan timespan = this.duration.getSingle(event);
108108
if (timespan == null)
109109
return;
110-
duration = (int) Math.min(timespan.getAs(Timespan.TimePeriod.TICK), Integer.MAX_VALUE);
110+
if (timespan.isInfinite()) {
111+
duration = PotionEffect.INFINITE_DURATION;
112+
} else {
113+
duration = (int) Math.min(timespan.getAs(Timespan.TimePeriod.TICK), Integer.MAX_VALUE);
114+
}
111115
}
112116
for (LivingEntity entity : entities.getArray(event)) {
113117
for (PotionEffectType potionEffectType : potionEffectTypes) {

src/main/java/ch/njol/skript/effects/EffPush.java

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,83 @@
88
import ch.njol.skript.lang.Effect;
99
import ch.njol.skript.lang.Expression;
1010
import ch.njol.skript.lang.SkriptParser.ParseResult;
11+
import ch.njol.skript.lang.SyntaxStringBuilder;
1112
import ch.njol.skript.util.Direction;
1213
import ch.njol.util.Kleenean;
14+
import org.bukkit.Location;
1315
import org.bukkit.entity.Entity;
1416
import org.bukkit.event.Event;
1517
import org.bukkit.util.Vector;
1618
import org.jetbrains.annotations.Nullable;
1719

20+
import java.util.function.Function;
21+
1822
@Name("Push")
19-
@Description("Push entities around.")
23+
@Description("Push entities in a given direction or towards a specific location.")
2024
@Example("push the player upwards")
2125
@Example("push the victim downwards at speed 0.5")
22-
@Example("push player along vector from player to player's target at speed 2")
23-
@Since("1.4.6")
26+
@Example("push player towards player's target at speed 2")
27+
@Example("pull player along vector(1,1,1) at speed 1.5")
28+
@Since({"1.4.6", "INSERT VERSION (push towards)"})
2429
public class EffPush extends Effect {
2530

2631
static {
27-
Skript.registerEffect(EffPush.class, "(push|thrust) %entities% [along] %direction% [(at|with) (speed|velocity|force) %-number%]");
32+
Skript.registerEffect(EffPush.class,
33+
"(push|thrust) %entities% [along] %direction% [(at|with) [a] (speed|velocity|force) [of] %-number%]",
34+
"(push|thrust|pull) %entities% (towards|away:away from) %location% [(at|with) [a] (speed|velocity|force) [of] %-number%]");
2835
}
2936

3037
private Expression<Entity> entities;
31-
private Expression<Direction> direction;
38+
private @Nullable Expression<Direction> direction;
39+
private @Nullable Expression<Location> target;
40+
private boolean awayFrom = false;
3241
private @Nullable Expression<Number> speed = null;
3342

3443
@SuppressWarnings({"unchecked", "null"})
3544
@Override
3645
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
3746
entities = (Expression<Entity>) exprs[0];
38-
direction = (Expression<Direction>) exprs[1];
47+
if (matchedPattern == 0) {
48+
direction = (Expression<Direction>) exprs[1];
49+
} else {
50+
target = (Expression<Location>) exprs[1];
51+
awayFrom = parseResult.hasTag("away");
52+
}
3953
speed = (Expression<Number>) exprs[2];
4054
return true;
4155
}
4256

4357
@Override
4458
protected void execute(Event event) {
45-
Direction direction = this.direction.getSingle(event);
46-
if (direction == null)
47-
return;
4859
Number speed = this.speed != null ? this.speed.getSingle(event) : null;
4960
if (this.speed != null && speed == null)
5061
return;
62+
63+
Function<Entity, Vector> getDirection;
64+
if (this.direction != null) {
65+
// push along
66+
Direction direction = this.direction.getSingle(event);
67+
if (direction == null)
68+
return;
69+
getDirection = direction::getDirection;
70+
} else {
71+
// push towards
72+
assert this.target != null;
73+
Location target = this.target.getSingle(event);
74+
if (target == null)
75+
return;
76+
Vector targetVector = target.toVector();
77+
getDirection = entity -> {
78+
Vector direction = targetVector.subtract(entity.getLocation().toVector());
79+
if (awayFrom)
80+
direction.multiply(-1);
81+
return direction;
82+
};
83+
}
84+
5185
Entity[] entities = this.entities.getArray(event);
5286
for (Entity entity : entities) {
53-
Vector pushDirection = direction.getDirection(entity);
87+
Vector pushDirection = getDirection.apply(entity);
5488
if (speed != null)
5589
pushDirection.normalize().multiply(speed.doubleValue());
5690
if (!(Double.isFinite(pushDirection.getX()) && Double.isFinite(pushDirection.getY()) && Double.isFinite(pushDirection.getZ()))) {
@@ -60,11 +94,23 @@ protected void execute(Event event) {
6094
entity.setVelocity(entity.getVelocity().add(pushDirection));
6195
}
6296
}
63-
97+
6498
@Override
6599
public String toString(@Nullable Event event, boolean debug) {
66-
return "push " + entities.toString(event, debug) + " " + direction.toString(event, debug) +
67-
(speed != null ? " at speed " + speed.toString(event, debug) : "");
100+
var ssb = new SyntaxStringBuilder(event, debug).append("push", entities);
101+
if (direction != null) {
102+
ssb.append(direction);
103+
} else {
104+
assert target != null;
105+
if (awayFrom) {
106+
ssb.append("away from", target);
107+
} else {
108+
ssb.append("towards", target);
109+
}
110+
}
111+
if (speed != null)
112+
ssb.append("at a speed of", speed);
113+
return ssb.toString();
68114
}
69115

70116
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
public class ExprPotionEffect extends SimpleExpression<PotionEffect> {
2929
static {
3030
Skript.registerExpression(ExprPotionEffect.class, PotionEffect.class, ExpressionType.COMBINED,
31-
"[new] potion effect of %potioneffecttype% [potion] [[[of] tier] %-number%] [(1¦without particles)] [for %-timespan%]",
32-
"[new] ambient potion effect of %potioneffecttype% [potion] [[[of] tier] %-number%] [(1¦without particles)] [for %-timespan%]");
31+
"[a] [new] potion effect of %potioneffecttype% [potion] [[[of] tier] %-number%] [(1¦without particles)] [for %-timespan%]",
32+
"[a] [new] ambient potion effect of %potioneffecttype% [potion] [[[of] tier] %-number%] [(1¦without particles)] [for %-timespan%]");
3333
}
3434

3535
@SuppressWarnings("null")
@@ -66,8 +66,9 @@ protected PotionEffect[] get(final Event e) {
6666
int ticks = 15 * 20; // 15 second default potion length
6767
if (this.timespan != null) {
6868
Timespan timespan = this.timespan.getSingle(e);
69-
if (timespan != null)
70-
ticks = (int) timespan.getAs(Timespan.TimePeriod.TICK);
69+
if (timespan != null) {
70+
ticks = timespan.isInfinite() ? PotionEffect.INFINITE_DURATION : (int) timespan.getAs(Timespan.TimePeriod.TICK);
71+
}
7172
}
7273
return new PotionEffect[]{new PotionEffect(potionEffectType, ticks, tier, ambient, particles)};
7374
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.skript.util.Timespan;
13+
import ch.njol.util.Kleenean;
14+
import org.bukkit.event.Event;
15+
import org.jetbrains.annotations.Nullable;
16+
17+
@Name("An Eternity")
18+
@Description({"Represents a timespan with an infinite duration. " +
19+
"An eternity is also created when arithmetic results in a timespan larger than about 292 million years.",
20+
"Infinite timespans generally follow the rules of infinity, where most math operations do nothing. " +
21+
"However, operations that would return NaN with numbers will instead return a timespan of 0 seconds.",
22+
"Note that an eternity will often be treated as the longest duration something supports, rather than a true eternity."
23+
})
24+
@Example("set fire to the player for an eternity")
25+
@Since("INSERT VERSION")
26+
public class LitEternity extends SimpleLiteral<Timespan> {
27+
28+
static {
29+
Skript.registerExpression(LitEternity.class, Timespan.class, ExpressionType.SIMPLE,
30+
"[an] eternity",
31+
"forever",
32+
"[an] (indefinite|infinite) (duration|timespan)");
33+
}
34+
35+
public LitEternity() {
36+
super(new Timespan[]{Timespan.infinite()}, Timespan.class, true);
37+
}
38+
39+
@Override
40+
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) {
41+
return true;
42+
}
43+
44+
@Override
45+
public String toString(@Nullable Event event, boolean debug) {
46+
return "an eternity";
47+
}
48+
49+
}

0 commit comments

Comments
 (0)