Skip to content

Commit

Permalink
Merge branch 'dev/patch' into fix/exprnamed-invalid-array-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLimeGlass authored Dec 15, 2023
2 parents c51dc41 + 1a009cd commit 83ca24c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 34 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Dfile.encoding=UTF-8

groupid=ch.njol
name=skript
version=2.7.2
version=2.7.3
jarName=Skript.jar
testEnv=java17/paper-1.20.2
testEnvJavaVersion=17
18 changes: 9 additions & 9 deletions src/main/java/ch/njol/skript/SkriptEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ private static void check(Event event, EventPriority priority) {
boolean hasTrigger = false;
for (Trigger trigger : triggers) {
SkriptEvent triggerEvent = trigger.getEvent();
if (triggerEvent.getEventPriority() == priority && Boolean.TRUE.equals(Task.callSync(() -> triggerEvent.check(event)))) {
if (
triggerEvent.getEventPriority() == priority
&& triggerEvent.canExecuteAsynchronously() ? triggerEvent.check(event) : Boolean.TRUE.equals(Task.callSync(() -> triggerEvent.check(event)))
) {
hasTrigger = true;
break;
}
Expand All @@ -130,7 +133,7 @@ private static void check(Event event, EventPriority priority) {

logEventStart(event);
}

boolean isCancelled = event instanceof Cancellable && ((Cancellable) event).isCancelled() && !listenCancelled.contains(event.getClass());
boolean isResultDeny = !(event instanceof PlayerInteractEvent && (((PlayerInteractEvent) event).getAction() == Action.LEFT_CLICK_AIR || ((PlayerInteractEvent) event).getAction() == Action.RIGHT_CLICK_AIR) && ((PlayerInteractEvent) event).useItemInHand() != Result.DENY);

Expand All @@ -155,15 +158,12 @@ private static void check(Event event, EventPriority priority) {
};

if (trigger.getEvent().canExecuteAsynchronously()) {
// check should be performed on the main thread
if (Boolean.FALSE.equals(Task.callSync(() -> triggerEvent.check(event))))
continue;
execute.run();
if (triggerEvent.check(event))
execute.run();
} else { // Ensure main thread
Task.callSync(() -> {
if (!triggerEvent.check(event))
return null;
execute.run();
if (triggerEvent.check(event))
execute.run();
return null; // we don't care about a return value
});
}
Expand Down
29 changes: 26 additions & 3 deletions src/main/java/ch/njol/skript/classes/data/DefaultComparators.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,26 @@
import ch.njol.skript.aliases.ItemData;
import ch.njol.skript.aliases.ItemType;
import ch.njol.skript.classes.ClassInfo;
import org.skriptlang.skript.lang.comparator.Comparator;
import ch.njol.skript.entity.BoatChestData;
import ch.njol.skript.entity.BoatData;
import ch.njol.skript.entity.EntityData;
import ch.njol.skript.entity.RabbitData;
import org.skriptlang.skript.lang.comparator.Comparators;
import ch.njol.skript.util.BlockUtils;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.EnchantmentType;
import ch.njol.skript.util.Experience;
import ch.njol.skript.util.WeatherType;
import ch.njol.skript.util.GameruleValue;
import ch.njol.skript.util.StructureType;
import ch.njol.skript.util.Time;
import ch.njol.skript.util.Timeperiod;
import ch.njol.skript.util.Timespan;
import ch.njol.skript.util.WeatherType;
import ch.njol.skript.util.slot.EquipmentSlot;
import ch.njol.skript.util.slot.Slot;
import ch.njol.skript.util.slot.SlotWithIndex;
import ch.njol.util.StringUtils;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
Expand All @@ -61,6 +60,8 @@
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.skriptlang.skript.lang.comparator.Comparator;
import org.skriptlang.skript.lang.comparator.Comparators;
import org.skriptlang.skript.lang.comparator.Relation;

import java.util.Objects;
Expand Down Expand Up @@ -630,6 +631,28 @@ public boolean supportsOrdering() {
return false;
}
});

// Location - Location
Comparators.registerComparator(Location.class, Location.class, new Comparator<Location, Location>() {
@Override
public Relation compare(Location first, Location second) {
return Relation.get(
// compare worlds
Objects.equals(first.getWorld(), second.getWorld()) &&
// compare xyz coords
first.toVector().equals(second.toVector()) &&
// normalize yaw and pitch to [-180, 180) and [-90, 90] respectively
// before comparing them
Location.normalizeYaw(first.getYaw()) == Location.normalizeYaw(second.getYaw()) &&
Location.normalizePitch(first.getPitch()) == Location.normalizePitch(second.getPitch())
);
}

@Override
public boolean supportsOrdering() {
return false;
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ public DefaultConverters() {}
if (holder instanceof DoubleChest)
return holder.getInventory().getLocation().getBlock();
return null;
});
}, Converter.NO_CHAINING);

// InventoryHolder - Entity
Converters.registerConverter(InventoryHolder.class, Entity.class, holder -> {
if (holder instanceof Entity)
return (Entity) holder;
return null;
});
}, Converter.NO_CHAINING);

// Enchantment - EnchantmentType
Converters.registerConverter(Enchantment.class, EnchantmentType.class, e -> new EnchantmentType(e, -1));
Expand Down
36 changes: 17 additions & 19 deletions src/main/java/ch/njol/skript/expressions/ExprSets.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
*/
package ch.njol.skript.expressions;

import java.util.Iterator;
import java.util.function.Supplier;

import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import com.google.common.collect.Lists;

import ch.njol.skript.Skript;
import ch.njol.skript.classes.ClassInfo;
import ch.njol.skript.doc.Description;
Expand All @@ -31,33 +39,26 @@
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.util.Utils;
import ch.njol.util.Kleenean;
import com.google.common.collect.Lists;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;

import java.util.Iterator;
import java.util.List;
import java.util.function.Supplier;

@Name("Sets")
@Description("Returns a list of all the values of a type; useful for looping.")
@Description("Returns a list of all the values of a type. Useful for looping.")
@Examples({
"loop all attribute types:",
"\tset loop-value attribute of player to 10",
"\tmessage \"Set attribute %loop-value% to 10!\""
"\tset loop-value attribute of player to 10",
"\tmessage \"Set attribute %loop-value% to 10!\""
})
@Since("<i>unknown</i> (before 1.4.2), 2.7 (colors)")
// Class history rename order: LoopItems.class -> ExprItems.class (renamed in 2.3-alpha1) -> ExprSets.class (renamed in 2.7.0)
@Since("1.0 pre-5, 2.7 (classinfo)")
public class ExprSets extends SimpleExpression<Object> {

static {
Skript.registerExpression(ExprSets.class, Object.class, ExpressionType.COMBINED,
"[all [[of] the]|the|every] %*classinfo%"
);
Skript.registerExpression(ExprSets.class, Object.class, ExpressionType.PATTERN_MATCHES_EVERYTHING,
"[all [[of] the]|the|every] %*classinfo%");
}

private ClassInfo<?> classInfo;
@Nullable
private Supplier<? extends Iterator<?>> supplier;
private ClassInfo<?> classInfo;

@Override
@SuppressWarnings("unchecked")
Expand All @@ -78,16 +79,13 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye

@Override
protected Object[] get(Event event) {
assert supplier != null;
Iterator<?> iterator = supplier.get();
List<?> elements = Lists.newArrayList(iterator);
return elements.toArray(new Object[0]);
return Lists.newArrayList(iterator).toArray(new Object[0]);
}

@Override
@Nullable
public Iterator<?> iterator(Event event) {
assert supplier != null;
return supplier.get();
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/skript/tests/regressions/6205-location comparison.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test "compare similar locations":
set {_world} to world "world"
assert location(1, 2, 3, {_world}, 4, 5) = location(1, 2, 3, {_world}, 4, 5) with "basic location comparison failed"

assert location(1, 2, 3, {_world}, 270, 0) = location(1, 2, 3, {_world}, -90, 0) with "yaw normalization failed when comparing locations"
assert location(1, 2, 3, {_world}, 0, 270) = location(1, 2, 3, {_world}, 0, 90) with "pitch normalization failed when comparing locations"
assert location(1, 2, 3, {_world}, 270, 270) = location(1, 2, 3, {_world}, -90, 90) with "yaw and pitch normalization failed when comparing locations"

assert location(1, (-1/infinity value), 3, {_world}, (-1/infinity value), (-1/infinity value)) = location(1, 0, 3, {_world}, 0, 0) with "0 and -0.0 are not equal when comparing locations"

0 comments on commit 83ca24c

Please sign in to comment.