Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.skriptlang.skript.bukkit.potion.util.SkriptPotionEffect;
import org.skriptlang.skript.lang.comparator.Comparator;
import org.skriptlang.skript.lang.comparator.Comparators;
import org.skriptlang.skript.lang.comparator.Relation;
Expand Down Expand Up @@ -446,16 +448,20 @@ public boolean supportsOrdering() {
});

// Object - ClassInfo
Comparators.registerComparator(Object.class, ClassInfo.class, new Comparator<Object, ClassInfo>() {
@Override
public Relation compare(Object o, ClassInfo c) {
return Relation.get(c.getC().isInstance(o) || o instanceof ClassInfo && c.getC().isAssignableFrom(((ClassInfo<?>) o).getC()));
}

@Override
public boolean supportsOrdering() {
return false;
Comparators.registerComparator(Object.class, ClassInfo.class, (object, classInfo) -> {
if (classInfo.getC().isInstance(object)) {
return Relation.EQUAL;
}
Class<?> objectClass;
if (object instanceof ClassInfo<?> objectClassInfo) {
objectClass = objectClassInfo.getC();
} else if (object instanceof SkriptPotionEffect) { // compatibility: treat SkriptPotionEffect the same as PotionEffect
objectClass = PotionEffect.class;
} else {
return Relation.NOT_EQUAL;
}
//noinspection unchecked
return Relation.get(classInfo.getC().isAssignableFrom(objectClass));
});

// DamageCause - ItemType
Expand Down
2 changes: 2 additions & 0 deletions src/test/skript/tests/bukkit/potion module.sk
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ test "potion effect creation":
assert amplifier of {_potion} is 5 with "amplifier is not 5"
assert {_potion} is infinite with "potion is infinite"

assert {_potion} is a potion effect with "potion effect is not a potion effect"

# ExprPotionEffects
test "potion effects of entities/items":
# setup
Expand Down
Loading