Skip to content

Commit c89828f

Browse files
Merge branch 'dev/feature' into dev/ExprTestPlayer
2 parents b9fb366 + 20057d9 commit c89828f

File tree

7 files changed

+58
-14
lines changed

7 files changed

+58
-14
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ org.gradle.parallel=true
55

66
groupid=ch.njol
77
name=skript
8-
version=2.11.1
8+
version=2.11.2
99
jarName=Skript.jar
1010
testEnv=java21/paper-1.21.5
1111
testEnvJavaVersion=21

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import ch.njol.skript.util.*;
1414
import ch.njol.skript.util.slot.InventorySlot;
1515
import ch.njol.skript.util.slot.Slot;
16-
import com.destroystokyo.paper.event.block.AnvilDamagedEvent;
1716
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
1817
import com.destroystokyo.paper.event.entity.EndermanAttackPlayerEvent;
1918
import com.destroystokyo.paper.event.entity.ProjectileCollideEvent;
@@ -547,8 +546,6 @@ else if (hand == EquipmentSlot.OFF_HAND)
547546
EventValues.registerEventValue(EntityMoveEvent.class, Location.class, EntityMoveEvent::getFrom);
548547
EventValues.registerEventValue(EntityMoveEvent.class, Location.class, EntityMoveEvent::getTo, TIME_FUTURE);
549548
}
550-
//PlayerToggleFlightEvent
551-
EventValues.registerEventValue(PlayerToggleFlightEvent.class, Player.class, PlayerEvent::getPlayer);
552549
//CreatureSpawnEvent
553550
EventValues.registerEventValue(CreatureSpawnEvent.class, SpawnReason.class, CreatureSpawnEvent::getSpawnReason);
554551
//FireworkExplodeEvent

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import ch.njol.skript.util.Timespan;
55
import ch.njol.skript.util.Timespan.TimePeriod;
66
import ch.njol.skript.util.Utils;
7-
import ch.njol.util.Math2;
87
import org.bukkit.util.Vector;
98
import org.skriptlang.skript.lang.arithmetic.Arithmetics;
109
import org.skriptlang.skript.lang.arithmetic.Operator;
@@ -91,9 +90,9 @@ public class DefaultOperations {
9190
});
9291

9392
// Timespan - Timespan
94-
Arithmetics.registerOperation(Operator.ADDITION, Timespan.class, (left, right) -> new Timespan(Math2.addClamped(left.getAs(TimePeriod.MILLISECOND), right.getAs(TimePeriod.MILLISECOND))));
95-
Arithmetics.registerOperation(Operator.SUBTRACTION, Timespan.class, (left, right) -> new Timespan(Math.max(0, left.getAs(TimePeriod.MILLISECOND) - right.getAs(TimePeriod.MILLISECOND))));
96-
Arithmetics.registerDifference(Timespan.class, (left, right) -> new Timespan(Math.abs(left.getAs(TimePeriod.MILLISECOND) - right.getAs(TimePeriod.MILLISECOND))));
93+
Arithmetics.registerOperation(Operator.ADDITION, Timespan.class, Timespan::add);
94+
Arithmetics.registerOperation(Operator.SUBTRACTION, Timespan.class, Timespan::subtract);
95+
Arithmetics.registerDifference(Timespan.class, Timespan::difference);
9796
Arithmetics.registerDefaultValue(Timespan.class, Timespan::new);
9897

9998
// Timespan - Number

src/main/java/ch/njol/skript/events/EvtClick.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,16 @@ public boolean check(Event event) {
178178
if (entity != null) {
179179
if (object instanceof EntityData<?> entityData) {
180180
return entityData.isInstance(entity);
181-
} else {
182-
Relation compare = DefaultComparators.entityItemComparator.compare(EntityData.fromEntity(entity), (ItemType) object);
181+
} else if (object instanceof ItemType itemType) {
182+
// for cases like `on right click on oak boat` try to compare the boat item to the boat entity
183+
// therefore blockdata check isn't needed here
184+
Relation compare = DefaultComparators.entityItemComparator.compare(EntityData.fromEntity(entity), itemType);
183185
return Relation.EQUAL.isImpliedBy(compare);
184186
}
185187
} else if (object instanceof ItemType itemType) {
186188
return itemType.isOfType(block);
187-
} else if (blockDataCheck != null && object instanceof BlockData blockData) {
188-
return blockDataCheck.matches(blockData);
189+
} else if (object instanceof BlockData blockData) {
190+
return blockDataCheck != null && blockDataCheck.matches(blockData);
189191
}
190192
return false;
191193
});

src/main/java/ch/njol/skript/expressions/arithmetic/ArithmeticChain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public class ArithmeticChain<L, R, T> implements ArithmeticGettable<T> {
3434
private final ArithmeticGettable<R> right;
3535
private final Operator operator;
3636
private final Class<? extends T> returnType;
37-
@Nullable
38-
private OperationInfo<? extends L, ? extends R, ? extends T> operationInfo;
37+
private final @Nullable OperationInfo<? extends L, ? extends R, ? extends T> operationInfo;
3938

4039
public ArithmeticChain(ArithmeticGettable<L> left, Operator operator, ArithmeticGettable<R> right, @Nullable OperationInfo<L, R, T> operationInfo) {
4140
this.left = left;
@@ -63,6 +62,7 @@ public T get(Event event) {
6362
if (leftClass == Object.class && rightClass == Object.class)
6463
return null;
6564

65+
OperationInfo<? extends L, ? extends R, ? extends T> operationInfo = this.operationInfo;
6666
if (left == null && leftClass == Object.class) {
6767
operationInfo = lookupOperationInfo(rightClass, OperationInfo::getRight);
6868
} else if (right == null && rightClass == Object.class) {

src/main/java/ch/njol/skript/util/Timespan.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import ch.njol.skript.localization.GeneralWords;
66
import ch.njol.skript.localization.Language;
77
import ch.njol.skript.localization.Noun;
8+
import ch.njol.util.Math2;
89
import ch.njol.util.NonNullPair;
910
import ch.njol.util.coll.CollectionUtils;
1011
import ch.njol.yggdrasil.YggdrasilSerializable;
@@ -254,6 +255,36 @@ public Duration getDuration() {
254255
return Duration.ofMillis(millis);
255256
}
256257

258+
/**
259+
* Safely adds the specified timespan to this timespan, handling potential overflow.
260+
* @param timespan The timespan to add to this timespan
261+
* @return a new Timespan object
262+
*/
263+
public Timespan add(Timespan timespan) {
264+
long millis = Math2.addClamped(this.millis, timespan.getAs(TimePeriod.MILLISECOND));
265+
return new Timespan(millis);
266+
}
267+
268+
/**
269+
* Safely subtracts the specified timespan from this timespan, handling potential underflow.
270+
* @param timespan The timespan to subtract from this timespan
271+
* @return a new Timespan object
272+
*/
273+
public Timespan subtract(Timespan timespan) {
274+
long millis = Math.max(0, this.millis - timespan.getAs(TimePeriod.MILLISECOND));
275+
return new Timespan(millis);
276+
}
277+
278+
/**
279+
* Calculates the difference between the specified timespan and this timespan.
280+
* @param timespan The timespan to get the difference of
281+
* @return a new Timespan object
282+
*/
283+
public Timespan difference(Timespan timespan) {
284+
long millis = Math.abs(this.millis - timespan.getAs(TimePeriod.MILLISECOND));
285+
return new Timespan(millis);
286+
}
287+
257288
@Override
258289
public long get(TemporalUnit unit) {
259290
if (unit instanceof TimePeriod period)

src/test/skript/tests/syntaxes/expressions/ExprArithmetic.sk

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,18 @@ test "arithmetic return types":
263263
# however, we can get more specific return types by returning the superclass of the return types of all Object-Number operations
264264
set {_location} to location(0,10,0,"world")
265265
assert (y-coordinate of {_location} - 4) is 6 with "y-coordinate of {_location} - 4 is not 6 (got '%y-coordinate of {_location} - 4%')"
266+
267+
test "arithmetic type switcheroo":
268+
# operation info swap test
269+
set {_a} to 1
270+
set {_b} to 1
271+
loop 2 times:
272+
set {_x} to {_a} * {_b}
273+
assert {_x} is set with "Failed to get a result"
274+
set {_b} to a random vector
275+
276+
# operation info trick test
277+
set {_a} to "Hello"
278+
loop 2 times:
279+
set {_x} to {_a} + {_b}
280+
set {_b} to 5

0 commit comments

Comments
 (0)