From 541ab170fbb3d09d2632c89b0fb2290583655458 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 9 Mar 2023 06:20:26 -0700 Subject: [PATCH 01/27] Implement a fix for the famous literal comparing issue --- .../njol/skript/conditions/CondCompare.java | 90 +++++++++++-------- .../ch/njol/skript/registrations/Classes.java | 6 +- test.sk | 4 + 3 files changed, 62 insertions(+), 38 deletions(-) create mode 100644 test.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondCompare.java b/src/main/java/ch/njol/skript/conditions/CondCompare.java index dbcb583436b..d1db49bd2d2 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCompare.java +++ b/src/main/java/ch/njol/skript/conditions/CondCompare.java @@ -22,6 +22,8 @@ import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.Skript; +import ch.njol.skript.classes.Converter.ConverterInfo; + import org.skriptlang.skript.lang.comparator.Comparator; import org.skriptlang.skript.lang.comparator.Relation; import ch.njol.skript.doc.Description; @@ -39,6 +41,8 @@ import ch.njol.skript.log.RetainingLogHandler; import ch.njol.skript.log.SkriptLogger; import ch.njol.skript.registrations.Classes; +import ch.njol.skript.registrations.Converters; + import org.skriptlang.skript.lang.comparator.Comparators; import ch.njol.skript.util.Patterns; import ch.njol.skript.util.Utils; @@ -164,28 +168,40 @@ private boolean init(String expr) { Expression third = this.third; try { if (first.getReturnType() == Object.class) { - final Expression e = first.getConvertedExpression(Object.class); - if (e == null) { + Expression expression = null; + if (second instanceof UnparsedLiteral) + expression = attemptReconstruct(first, second); + if (expression == null) + expression = first.getConvertedExpression(Object.class); + if (expression == null) { log.printErrors(); return false; } - first = e; + first = expression; } if (second.getReturnType() == Object.class) { - final Expression e = second.getConvertedExpression(Object.class); - if (e == null) { + Expression expression = null; + if (second instanceof UnparsedLiteral) + expression = attemptReconstruct(second, first); + if (expression == null) + expression = second.getConvertedExpression(Object.class); + if (expression == null) { log.printErrors(); return false; } - second = e; + second = expression; } if (third != null && third.getReturnType() == Object.class) { - final Expression e = third.getConvertedExpression(Object.class); - if (e == null) { + Expression expression = null; + if (second instanceof UnparsedLiteral) + expression = attemptReconstruct(third, first); + if (expression == null) + expression = third.getConvertedExpression(Object.class); + if (expression == null) { log.printErrors(); return false; } - this.third = third = e; + this.third = third = expression; } log.printLog(); } finally { @@ -194,20 +210,6 @@ private boolean init(String expr) { final Class f = first.getReturnType(), s = third == null ? second.getReturnType() : Utils.getSuperType(second.getReturnType(), third.getReturnType()); if (f == Object.class || s == Object.class) return true; - /* - * https://github.com/Mirreski/Skript/issues/10 - * - if(Entity.class.isAssignableFrom(s)){ - String[] split = expr.split(" "); - System.out.println(expr); - if(!split[split.length - 1].equalsIgnoreCase("player") && EntityData.parseWithoutIndefiniteArticle(split[split.length - 1]) != null){ - comp = Comparators.getComparator(f, EntityData.class); - second = SkriptParser.parseLiteral(split[split.length - 1], EntityData.class, ParseContext.DEFAULT); - }else - comp = Comparators.getComparator(f, s); - - } - *///else comp = Comparators.getComparator(f, s); @@ -251,22 +253,40 @@ private boolean init(String expr) { * @return A literal value, or null if parsing failed. */ @Nullable - private SimpleLiteral reparseLiteral(Class type, Expression expr) { - if (expr instanceof SimpleLiteral) { // Only works for simple literals - Expression source = expr.getSource(); - - // Try to get access to unparsed content of it - if (source instanceof UnparsedLiteral) { - String unparsed = ((UnparsedLiteral) source).getData(); - T data = Classes.parse(unparsed, type, ParseContext.DEFAULT); - if (data != null) { // Success, let's make a literal of it - return new SimpleLiteral<>(data, false, new UnparsedLiteral(unparsed)); - } + private SimpleLiteral reparseLiteral(Class type, Expression expression) { + Expression source = expression; + if (expression instanceof SimpleLiteral) // Only works for simple literals + source = expression.getSource(); + + // Try to get access to unparsed content of it + if (source instanceof UnparsedLiteral) { + String unparsed = ((UnparsedLiteral) source).getData(); + T data = Classes.parse(unparsed, type, ParseContext.DEFAULT); + if (data != null) { // Success, let's make a literal of it + return new SimpleLiteral<>(data, false, new UnparsedLiteral(unparsed)); } } return null; // Context-sensitive parsing failed; can't really help it } - + + @SuppressWarnings("unchecked") + private Expression attemptReconstruct(Expression one, Expression two) { + Expression expression = null; + if (expression == null) { + for (org.skriptlang.skript.lang.converter.ConverterInfo converter : org.skriptlang.skript.lang.converter.Converters.getConverterInfo()) { + // Must be convertable from other. + if (!converter.getFrom().isAssignableFrom(two.getReturnType())) + continue; + // Must be comparable if we're going to attempt to convert this UnparsedLiteral. + if (org.skriptlang.skript.lang.comparator.Comparators.getComparator(two.getReturnType(), converter.getTo()) == null) + continue; + expression = reparseLiteral(converter.getTo(), one); + } + } + if (expression == null) + expression = one.getConvertedExpression(two.getReturnType()); + return expression; + } /* * # := condition (e.g. is, is less than, contains, is enchanted with, has permission, etc.) * !# := not # diff --git a/src/main/java/ch/njol/skript/registrations/Classes.java b/src/main/java/ch/njol/skript/registrations/Classes.java index 8f48370db56..61dd0ff13d8 100644 --- a/src/main/java/ch/njol/skript/registrations/Classes.java +++ b/src/main/java/ch/njol/skript/registrations/Classes.java @@ -504,9 +504,9 @@ public static T parse(final String s, final Class c, final ParseContext c continue; if (c.isAssignableFrom(conv.getTo())) { log.clear(); - final Object o = parseSimple(s, conv.getFrom(), context); - if (o != null) { - t = (T) ((Converter) conv.getConverter()).convert(o); + Object object = parseSimple(s, conv.getFrom(), context); + if (object != null) { + t = (T) ((Converter) conv.getConverter()).convert(object); if (t != null) { log.printLog(); return t; diff --git a/test.sk b/test.sk new file mode 100644 index 00000000000..8be05bb28ef --- /dev/null +++ b/test.sk @@ -0,0 +1,4 @@ + +on block damage: + event-block is fire: + cancel event \ No newline at end of file From 1d10b81d8c606dda9e0f2190f38848a01cf4fa1c Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 9 Mar 2023 21:14:10 -0700 Subject: [PATCH 02/27] Clean up and get ready for pull request --- .../njol/skript/conditions/CondCompare.java | 67 +++++++++++-------- .../ch/njol/skript/test/runner/EffAssert.java | 5 +- .../njol/skript/test/runner/TestTracker.java | 7 ++ .../regressions/4769-fire-visualeffect.sk | 12 ++++ 4 files changed, 62 insertions(+), 29 deletions(-) create mode 100644 src/test/skript/tests/regressions/4769-fire-visualeffect.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondCompare.java b/src/main/java/ch/njol/skript/conditions/CondCompare.java index d1db49bd2d2..3de49023e05 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCompare.java +++ b/src/main/java/ch/njol/skript/conditions/CondCompare.java @@ -22,10 +22,12 @@ import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.Skript; -import ch.njol.skript.classes.Converter.ConverterInfo; import org.skriptlang.skript.lang.comparator.Comparator; import org.skriptlang.skript.lang.comparator.Relation; +import org.skriptlang.skript.lang.converter.ConverterInfo; +import org.skriptlang.skript.lang.converter.Converters; + import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; @@ -33,6 +35,7 @@ import ch.njol.skript.lang.Condition; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.ExpressionList; +import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.ParseContext; import ch.njol.skript.lang.SkriptParser.ParseResult; import ch.njol.skript.lang.UnparsedLiteral; @@ -41,7 +44,6 @@ import ch.njol.skript.log.RetainingLogHandler; import ch.njol.skript.log.SkriptLogger; import ch.njol.skript.registrations.Classes; -import ch.njol.skript.registrations.Converters; import org.skriptlang.skript.lang.comparator.Comparators; import ch.njol.skript.util.Patterns; @@ -49,9 +51,6 @@ import ch.njol.util.Checker; import ch.njol.util.Kleenean; -/** - * @author Peter Güttinger - */ @Name("Comparison") @Description({"A very general condition, it simply compares two values. Usually you can only compare for equality (e.g. block is/isn't of <type>), " + "but some values can also be compared using greater than/less than. In that case you can also test for whether an object is between two others.", @@ -97,19 +96,18 @@ public class CondCompare extends Condition { Skript.registerCondition(CondCompare.class, patterns.getPatterns()); } - @SuppressWarnings("null") private Expression first; - @SuppressWarnings("null") private Expression second; + @Nullable private Expression third; - @SuppressWarnings("null") + private Relation relation; - @SuppressWarnings("rawtypes") + @Nullable + @SuppressWarnings("rawtypes") private Comparator comp; - @SuppressWarnings("null") @Override public boolean init(final Expression[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { first = vars[0]; @@ -164,13 +162,13 @@ public static String f(final Expression e) { @SuppressWarnings({"unchecked"}) private boolean init(String expr) { - final RetainingLogHandler log = SkriptLogger.startRetainingLog(); + RetainingLogHandler log = SkriptLogger.startRetainingLog(); Expression third = this.third; try { if (first.getReturnType() == Object.class) { Expression expression = null; - if (second instanceof UnparsedLiteral) - expression = attemptReconstruct(first, second); + if (first instanceof UnparsedLiteral) + expression = attemptReconstruct((UnparsedLiteral) first, second); if (expression == null) expression = first.getConvertedExpression(Object.class); if (expression == null) { @@ -182,7 +180,7 @@ private boolean init(String expr) { if (second.getReturnType() == Object.class) { Expression expression = null; if (second instanceof UnparsedLiteral) - expression = attemptReconstruct(second, first); + expression = attemptReconstruct((UnparsedLiteral) second, first); if (expression == null) expression = second.getConvertedExpression(Object.class); if (expression == null) { @@ -193,8 +191,8 @@ private boolean init(String expr) { } if (third != null && third.getReturnType() == Object.class) { Expression expression = null; - if (second instanceof UnparsedLiteral) - expression = attemptReconstruct(third, first); + if (third instanceof UnparsedLiteral) + expression = attemptReconstruct((UnparsedLiteral) third, first); if (expression == null) expression = third.getConvertedExpression(Object.class); if (expression == null) { @@ -207,12 +205,12 @@ private boolean init(String expr) { } finally { log.stop(); } - final Class f = first.getReturnType(), s = third == null ? second.getReturnType() : Utils.getSuperType(second.getReturnType(), third.getReturnType()); + Class f = first.getReturnType(), s = third == null ? second.getReturnType() : Utils.getSuperType(second.getReturnType(), third.getReturnType()); if (f == Object.class || s == Object.class) return true; - + comp = Comparators.getComparator(f, s); - + if (comp == null) { // Try to re-parse with more context /* * SkriptParser sees that CondCompare takes two objects. Most of the time, @@ -239,10 +237,10 @@ private boolean init(String expr) { } } - + return comp != null; } - + /** * Attempts to parse given expression again as a literal of given type. * This will only work if the expression is a literal and its unparsed @@ -269,24 +267,37 @@ private SimpleLiteral reparseLiteral(Class type, Expression express return null; // Context-sensitive parsing failed; can't really help it } + /** + * Attempts to transform an UnparsedLiteral into a type that is comparable to another. + * For example 'fire' will be VisualEffect without this, but if the user attempts to compare 'fire' + * with a block. This method will see if 'fire' can be compared to the block, and it will find ItemType. + * Essentially solving something a human sees as comparable, but Skript doesn't understand. + * + * @param one The UnparsedLiteral expression to attempt to reconstruct. + * @param two any expression to grab the return type from. + * @return The newly formed Literal, will be SimpleLiteral in most cases. + */ @SuppressWarnings("unchecked") - private Expression attemptReconstruct(Expression one, Expression two) { + private Literal attemptReconstruct(UnparsedLiteral one, Expression two) { Expression expression = null; + // Must handle numbers first. + expression = one.getConvertedExpression(Number.class); if (expression == null) { - for (org.skriptlang.skript.lang.converter.ConverterInfo converter : org.skriptlang.skript.lang.converter.Converters.getConverterInfo()) { - // Must be convertable from other. + for (ConverterInfo converter : Converters.getConverterInfo()) { + // We're comparing the 'two' expression, so we need the 'from' for comparing. if (!converter.getFrom().isAssignableFrom(two.getReturnType())) continue; - // Must be comparable if we're going to attempt to convert this UnparsedLiteral. - if (org.skriptlang.skript.lang.comparator.Comparators.getComparator(two.getReturnType(), converter.getTo()) == null) + // Must be comparable if we're going to attempt to convert this UnparsedLiteral. Otherwise why attempt something that won't work. + if (Comparators.getComparator(two.getReturnType(), converter.getTo()) == null) continue; expression = reparseLiteral(converter.getTo(), one); } } if (expression == null) expression = one.getConvertedExpression(two.getReturnType()); - return expression; + return (Literal) expression; } + /* * # := condition (e.g. is, is less than, contains, is enchanted with, has permission, etc.) * !# := not # @@ -322,7 +333,7 @@ private Expression attemptReconstruct(Expression one, Expression two) { * neither a nor b # x or y === a !# x or y && b !# x or y // nor = and */ @Override - @SuppressWarnings({"null", "unchecked"}) + @SuppressWarnings("unchecked") public boolean check(final Event e) { final Expression third = this.third; return first.check(e, (Checker) o1 -> diff --git a/src/main/java/ch/njol/skript/test/runner/EffAssert.java b/src/main/java/ch/njol/skript/test/runner/EffAssert.java index 4f78665295d..d61a19dc9bd 100644 --- a/src/main/java/ch/njol/skript/test/runner/EffAssert.java +++ b/src/main/java/ch/njol/skript/test/runner/EffAssert.java @@ -20,6 +20,7 @@ import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; +import org.skriptlang.skript.lang.script.Script; import ch.njol.skript.Skript; import ch.njol.skript.doc.Description; @@ -46,6 +47,7 @@ public class EffAssert extends Effect { @Nullable private Condition condition; + private Script script; private Expression errorMsg; private boolean shouldFail; @@ -56,6 +58,7 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye String conditionString = parseResult.regexes.get(0).group(); errorMsg = (Expression) exprs[0]; shouldFail = parseResult.mark != 0; + script = getParser().getCurrentScript(); ParseLogHandler logHandler = SkriptLogger.startParseLogHandler(); try { @@ -91,7 +94,7 @@ public TriggerItem walk(Event event) { if (SkriptJUnitTest.getCurrentJUnitTest() != null) { TestTracker.junitTestFailed(SkriptJUnitTest.getCurrentJUnitTest(), message); } else { - TestTracker.testFailed(message); + TestTracker.testFailed(message, script); } return null; } diff --git a/src/main/java/ch/njol/skript/test/runner/TestTracker.java b/src/main/java/ch/njol/skript/test/runner/TestTracker.java index fb6b2a0df40..de78cf743f2 100644 --- a/src/main/java/ch/njol/skript/test/runner/TestTracker.java +++ b/src/main/java/ch/njol/skript/test/runner/TestTracker.java @@ -24,6 +24,7 @@ import java.util.Set; import org.eclipse.jdt.annotation.Nullable; +import org.skriptlang.skript.lang.script.Script; import ch.njol.skript.test.utils.TestResults; @@ -54,6 +55,12 @@ public static void testFailed(String msg) { failedTests.put(currentTest, msg); } + public static void testFailed(String msg, Script script) { + String file = script.getConfig().getFileName(); + file = file.substring(file.lastIndexOf("\\") + 1); + failedTests.put(currentTest, msg + " [" + file + "]"); + } + public static void junitTestFailed(String junit, String msg) { failedTests.put(junit, msg); } diff --git a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk new file mode 100644 index 00000000000..0a62623db58 --- /dev/null +++ b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk @@ -0,0 +1,12 @@ +test "fire visual effect": + set {_block} to block at spawn of world "world" + set block at spawn of world "world" to fire + assert block at spawn of world "world" is fire with "failed to compare fire (itemtype) with a block" + set block at spawn of world "world" to {_block} + play 5 fire at spawn of world "world" + assert "fire" parsed as visual effect is fire with "failed to compare visual effects" + assert "fire" parsed as visual effect is "fire" parsed as itemtype to fail with "failed to compare visual effects ##2" + spawn a chicken at spawn of world "world": + assert event-entity is a chicken with "failed to compare a chicken" + assert event-entity is a "chicken" parsed as itemtype to fail with "failed to compare a chicken ##2" + clear event-entity From d95b00abe1f8e48843879e4b7895f9edbe441834 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 9 Mar 2023 21:19:32 -0700 Subject: [PATCH 03/27] Clean up and get ready for pull request --- test.sk | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 test.sk diff --git a/test.sk b/test.sk deleted file mode 100644 index 8be05bb28ef..00000000000 --- a/test.sk +++ /dev/null @@ -1,4 +0,0 @@ - -on block damage: - event-block is fire: - cancel event \ No newline at end of file From 009f5c2e70546dd39b31d3bb0ddf9fdd2d4be4a6 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 9 Mar 2023 22:21:01 -0700 Subject: [PATCH 04/27] Add more regression tests for more issues --- .../njol/skript/test/runner/EvtTestCase.java | 56 +++++++++------ .../skript/test/runner/SkriptJUnitTest.java | 10 +-- .../tests/regression/HangingEntity_4871.java | 69 +++++++++++++++++++ .../skript/tests/junit/HangingEntity_4871.sk | 7 ++ .../4773-composter-the-imposter.sk | 5 ++ .../tests/regressions/4871-hanging-entity.sk | 9 +++ .../syntaxes/expressions/ExprBlockData.sk | 2 +- 7 files changed, 132 insertions(+), 26 deletions(-) create mode 100644 src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java create mode 100644 src/test/skript/tests/junit/HangingEntity_4871.sk create mode 100644 src/test/skript/tests/regressions/4773-composter-the-imposter.sk create mode 100644 src/test/skript/tests/regressions/4871-hanging-entity.sk diff --git a/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java b/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java index eb6bbd93b4f..ac56fdcbbaf 100644 --- a/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java +++ b/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java @@ -18,6 +18,8 @@ */ package ch.njol.skript.test.runner; +import org.bukkit.Location; +import org.bukkit.block.Block; import org.bukkit.event.Event; import org.eclipse.jdt.annotation.Nullable; @@ -27,25 +29,39 @@ import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; public class EvtTestCase extends SkriptEvent { - + static { - if (TestMode.ENABLED) + if (TestMode.ENABLED) { Skript.registerEvent("Test Case", EvtTestCase.class, SkriptTestEvent.class, "test %string% [when <.+>]") - .description("Contents represent one test case.") - .examples("") - .since("2.5"); + .description("Contents represent one test case.") + .examples("") + .since("2.5"); + EventValues.registerEventValue(SkriptTestEvent.class, Block.class, new Getter() { + @Override + public @Nullable Block get(SkriptTestEvent ignored) { + return SkriptJUnitTest.getBlock(); + } + }, EventValues.TIME_NOW); + EventValues.registerEventValue(SkriptTestEvent.class, Location.class, new Getter() { + @Override + public @Nullable Location get(SkriptTestEvent ignored) { + return SkriptJUnitTest.getTestLocation(); + } + }, EventValues.TIME_NOW); + } } - - @SuppressWarnings("null") + private Expression name; - + @Nullable private Condition condition; - - @SuppressWarnings({"null", "unchecked"}) + @Override + @SuppressWarnings("unchecked") public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseResult parseResult) { name = (Expression) args[0]; if (!parseResult.regexes.isEmpty()) { // Do not parse or run unless condition is met @@ -54,27 +70,27 @@ public boolean init(Literal[] args, int matchedPattern, SkriptParser.ParseRes } return true; } - + @Override - public boolean check(Event e) { - String n = name.getSingle(e); - if (n == null) { + public boolean check(Event event) { + String n = name.getSingle(event); + if (n == null) return false; - } Skript.info("Running test case " + n); TestTracker.testStarted(n); return true; } - + @Override public boolean shouldLoadEvent() { return condition != null ? condition.check(new SkriptTestEvent()) : true; } - + @Override - public String toString(@Nullable Event e, boolean debug) { - if (e != null) - return "test " + name.getSingle(e); + public String toString(@Nullable Event event, boolean debug) { + if (event != null) + return "test " + name.getSingle(event); return "test case"; } + } diff --git a/src/main/java/ch/njol/skript/test/runner/SkriptJUnitTest.java b/src/main/java/ch/njol/skript/test/runner/SkriptJUnitTest.java index ed9fb6d026e..8431dc9a6a3 100644 --- a/src/main/java/ch/njol/skript/test/runner/SkriptJUnitTest.java +++ b/src/main/java/ch/njol/skript/test/runner/SkriptJUnitTest.java @@ -86,14 +86,14 @@ public final void cleanup() { /** * @return the test world. */ - protected World getTestWorld() { + public static World getTestWorld() { return Bukkit.getWorlds().get(0); } /** * @return the testing location at the spawn of the testing world. */ - protected Location getTestLocation() { + public static Location getTestLocation() { return getTestWorld().getSpawnLocation().add(0, 1, 0); } @@ -102,7 +102,7 @@ protected Location getTestLocation() { * * @return Pig that has been spawned. */ - protected Pig spawnTestPig() { + public static Pig spawnTestPig() { if (delay <= 0D) delay = 1; // A single tick allows the piggy to spawn before server shutdown. return (Pig) getTestWorld().spawnEntity(getTestLocation(), EntityType.PIG); @@ -114,7 +114,7 @@ protected Pig spawnTestPig() { * @param material The material to set the block to. * @return the Block after it has been updated. */ - protected Block setBlock(Material material) { + public static Block setBlock(Material material) { Block block = getBlock(); block.setType(material); return block; @@ -125,7 +125,7 @@ protected Block setBlock(Material material) { * * @return the Block after it has been updated. */ - protected Block getBlock() { + public static Block getBlock() { return getTestWorld().getSpawnLocation().add(10, 1, 0).getBlock(); } diff --git a/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java b/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java new file mode 100644 index 00000000000..a7a383f3e27 --- /dev/null +++ b/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java @@ -0,0 +1,69 @@ +/** + * This file is part of Skript. + * + * Skript is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Skript is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Skript. If not, see . + * + * Copyright Peter Güttinger, SkriptLang team and contributors + */ +package org.skriptlang.skript.test.tests.regression; + +import java.util.Optional; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.ItemFrame; +import org.bukkit.event.hanging.HangingBreakEvent; +import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import ch.njol.skript.test.runner.SkriptJUnitTest; + +public class HangingEntity_4871 extends SkriptJUnitTest { + + static { + // Only needed when we trigger an event or something that isn't instant. + setShutdownDelay(1); + } + + private Material before; + + @Before + public void setupItemFrame() { + // Ensure it's in the ground for the item frame to attach to a wall. + Location location = getTestLocation().subtract(0, 2, 0); + before = location.getBlock().getType(); + location.getBlock().setType(Material.AIR); + getTestWorld().spawnEntity(location, EntityType.ITEM_FRAME); + } + + @Test + public void testDamage() { + Location location = getTestLocation().subtract(0, 2, 0); + Optional optional = location.getNearbyEntitiesByType(ItemFrame.class, 1).stream().findFirst(); + assert optional.isPresent(); + HangingBreakEvent event = new HangingBreakEvent(optional.get(), RemoveCause.DEFAULT); + Bukkit.getPluginManager().callEvent(event); + } + + @After + public void cleanupItemFrame() { + Location location = getTestLocation().subtract(0, 2, 0); + location.getBlock().setType(before); + } + +} diff --git a/src/test/skript/tests/junit/HangingEntity_4871.sk b/src/test/skript/tests/junit/HangingEntity_4871.sk new file mode 100644 index 00000000000..1bc59de84df --- /dev/null +++ b/src/test/skript/tests/junit/HangingEntity_4871.sk @@ -0,0 +1,7 @@ +test "hanging entity compare": + ensure junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" completes "item frame" + +on break: + junit test is "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" + assert hanging entity is an item frame with "item frame compare failed" + complete objective "item frame" for junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" diff --git a/src/test/skript/tests/regressions/4773-composter-the-imposter.sk b/src/test/skript/tests/regressions/4773-composter-the-imposter.sk new file mode 100644 index 00000000000..229c5344e9a --- /dev/null +++ b/src/test/skript/tests/regressions/4773-composter-the-imposter.sk @@ -0,0 +1,5 @@ +test "composter the imposter" when running minecraft "1.14.4": + set {_block} to block at spawn of world "world" + set block at spawn of world "world" to composter + assert block at spawn of world "world" is composter with "failed to compare composter (itemtype) with a block" + set block at spawn of world "world" to {_block} diff --git a/src/test/skript/tests/regressions/4871-hanging-entity.sk b/src/test/skript/tests/regressions/4871-hanging-entity.sk new file mode 100644 index 00000000000..68d85a8aa0c --- /dev/null +++ b/src/test/skript/tests/regressions/4871-hanging-entity.sk @@ -0,0 +1,9 @@ +on script load: + # Setup our objective for this script test to complete with the JUnit test. + ensure junit test "org.skriptlang.skript.test.tests.regression.SimpleJUnitTest" completes "piggy died" + +on break: + if hanging entity is item frame: + broadcast "item frame" + else if hanging entity is glow item frame: + broadcast "glow item frame" diff --git a/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk b/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk index 1916c370f95..87f5a2cdce2 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk @@ -1,4 +1,4 @@ -test "block data" when running minecraft "1.15.2": +test "block data" when running minecraft "1.16.5": set {_b} to block at spawn of world "world" set block at {_b} to campfire[lit=false;waterlogged=true] assert block at {_b} is an unlit campfire with "block at spawn should be an unlit campfire" From efdcb0f0bdedf973b4fc61f1e9fbf6508fdc2290 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 9 Mar 2023 22:45:40 -0700 Subject: [PATCH 05/27] Add more regression tests for more issues --- .../tests/regression/HangingEntity_4871.java | 21 ++++++++++++++++++- .../skript/tests/junit/HangingEntity_4871.sk | 10 +++++++++ .../tests/regressions/2711-item-compares.sk | 12 +++++++++++ .../tests/regressions/3303-item durability.sk | 17 +++++---------- .../tests/regressions/4871-hanging-entity.sk | 9 -------- 5 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 src/test/skript/tests/regressions/2711-item-compares.sk delete mode 100644 src/test/skript/tests/regressions/4871-hanging-entity.sk diff --git a/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java b/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java index a7a383f3e27..55b46dbc5a0 100644 --- a/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java +++ b/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java @@ -40,7 +40,7 @@ public class HangingEntity_4871 extends SkriptJUnitTest { setShutdownDelay(1); } - private Material before; + private Material before, before2; @Before public void setupItemFrame() { @@ -49,6 +49,14 @@ public void setupItemFrame() { before = location.getBlock().getType(); location.getBlock().setType(Material.AIR); getTestWorld().spawnEntity(location, EntityType.ITEM_FRAME); + + // TODO Aliases for 'glow item frame' not on master branch for this code +// if (Skript.isRunningMinecraft(1, 17, 1)) { +// Location location2 = getTestLocation().subtract(4, 2, 0); +// before2 = location2.getBlock().getType(); +// location2.getBlock().setType(Material.AIR); +// getTestWorld().spawnEntity(location2, EntityType.GLOW_ITEM_FRAME); +// } } @Test @@ -58,12 +66,23 @@ public void testDamage() { assert optional.isPresent(); HangingBreakEvent event = new HangingBreakEvent(optional.get(), RemoveCause.DEFAULT); Bukkit.getPluginManager().callEvent(event); +// if (Skript.isRunningMinecraft(1, 17, 1)) { +// Location location2 = getTestLocation().subtract(4, 2, 0); +// Optional optional2 = location2.getNearbyEntitiesByType(GlowItemFrame.class, 1).stream().findFirst(); +// assert optional2.isPresent(); +// HangingBreakEvent event2 = new HangingBreakEvent(optional2.get(), RemoveCause.DEFAULT); +// Bukkit.getPluginManager().callEvent(event2); +// } } @After public void cleanupItemFrame() { Location location = getTestLocation().subtract(0, 2, 0); location.getBlock().setType(before); +// if (Skript.isRunningMinecraft(1, 17, 1)) { +// Location location2 = getTestLocation().subtract(4, 2, 0); +// location2.getBlock().setType(before2); +// } } } diff --git a/src/test/skript/tests/junit/HangingEntity_4871.sk b/src/test/skript/tests/junit/HangingEntity_4871.sk index 1bc59de84df..f218c5121b8 100644 --- a/src/test/skript/tests/junit/HangingEntity_4871.sk +++ b/src/test/skript/tests/junit/HangingEntity_4871.sk @@ -1,7 +1,17 @@ test "hanging entity compare": ensure junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" completes "item frame" +# Aliases not on master branch for this code +#test "hanging entity glowing item frame" when running minecraft "1.17.1": +# ensure junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" completes "glowing item frame" + on break: junit test is "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" assert hanging entity is an item frame with "item frame compare failed" complete objective "item frame" for junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" + +# Aliases not on master branch for this code +#on break of glowing item frame: +# junit test is "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" +# assert hanging entity is a glow item frame with "glowing item frame compare failed" +# complete objective "glowing item frame" for junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" diff --git a/src/test/skript/tests/regressions/2711-item-compares.sk b/src/test/skript/tests/regressions/2711-item-compares.sk new file mode 100644 index 00000000000..991b7cda983 --- /dev/null +++ b/src/test/skript/tests/regressions/2711-item-compares.sk @@ -0,0 +1,12 @@ +test "item durability": + set {_i} to a diamond sword + set durability of {_i} to 500 + assert durability of {_i} = 500 with "Durability of item should have been 500" + +test "block data value" when running below minecraft "1.13.2": + set block at spawn of world "world" to farmland + set {_b} to block above block at spawn of world "world" + set block at {_b} to fully grown wheat plant + assert data value of block at {_b} = 7 with "Data value of block should have been 7" + set data value of block at {_b} to 1 + assert data value of block at {_b} = 1 with "Data value of block should have been 1" diff --git a/src/test/skript/tests/regressions/3303-item durability.sk b/src/test/skript/tests/regressions/3303-item durability.sk index 991b7cda983..33c21d221c0 100644 --- a/src/test/skript/tests/regressions/3303-item durability.sk +++ b/src/test/skript/tests/regressions/3303-item durability.sk @@ -1,12 +1,5 @@ -test "item durability": - set {_i} to a diamond sword - set durability of {_i} to 500 - assert durability of {_i} = 500 with "Durability of item should have been 500" - -test "block data value" when running below minecraft "1.13.2": - set block at spawn of world "world" to farmland - set {_b} to block above block at spawn of world "world" - set block at {_b} to fully grown wheat plant - assert data value of block at {_b} = 7 with "Data value of block should have been 7" - set data value of block at {_b} to 1 - assert data value of block at {_b} = 1 with "Data value of block should have been 1" +test "item compares": + set {_test} to a player head + assert {_test} is a player head with "failed to compare against a head" + set {_test} to a door + assert {_test} is any door, any wood door, birch door or a closed birch door with "failed to compare against a door" diff --git a/src/test/skript/tests/regressions/4871-hanging-entity.sk b/src/test/skript/tests/regressions/4871-hanging-entity.sk deleted file mode 100644 index 68d85a8aa0c..00000000000 --- a/src/test/skript/tests/regressions/4871-hanging-entity.sk +++ /dev/null @@ -1,9 +0,0 @@ -on script load: - # Setup our objective for this script test to complete with the JUnit test. - ensure junit test "org.skriptlang.skript.test.tests.regression.SimpleJUnitTest" completes "piggy died" - -on break: - if hanging entity is item frame: - broadcast "item frame" - else if hanging entity is glow item frame: - broadcast "glow item frame" From ebdc88d01f307bb840305714c3ce22940b7745ce Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 9 Mar 2023 22:56:03 -0700 Subject: [PATCH 06/27] Add more regression tests for more issues --- src/test/skript/tests/regressions/3303-item durability.sk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/skript/tests/regressions/3303-item durability.sk b/src/test/skript/tests/regressions/3303-item durability.sk index 33c21d221c0..9f1874f2421 100644 --- a/src/test/skript/tests/regressions/3303-item durability.sk +++ b/src/test/skript/tests/regressions/3303-item durability.sk @@ -1,5 +1,5 @@ test "item compares": - set {_test} to a player head - assert {_test} is a player head with "failed to compare against a head" + set {_test} to a dragon head + assert {_test} is a dragon head with "failed to compare against a head" set {_test} to a door assert {_test} is any door, any wood door, birch door or a closed birch door with "failed to compare against a door" From a2f535f7349d8334a54887e00b914f1ceb591fb5 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 9 Mar 2023 23:19:06 -0700 Subject: [PATCH 07/27] override wrong .sk test file --- .../tests/regressions/2711-item-compares.sk | 17 +++++------------ .../tests/regressions/3303-item durability.sk | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/test/skript/tests/regressions/2711-item-compares.sk b/src/test/skript/tests/regressions/2711-item-compares.sk index 991b7cda983..9f1874f2421 100644 --- a/src/test/skript/tests/regressions/2711-item-compares.sk +++ b/src/test/skript/tests/regressions/2711-item-compares.sk @@ -1,12 +1,5 @@ -test "item durability": - set {_i} to a diamond sword - set durability of {_i} to 500 - assert durability of {_i} = 500 with "Durability of item should have been 500" - -test "block data value" when running below minecraft "1.13.2": - set block at spawn of world "world" to farmland - set {_b} to block above block at spawn of world "world" - set block at {_b} to fully grown wheat plant - assert data value of block at {_b} = 7 with "Data value of block should have been 7" - set data value of block at {_b} to 1 - assert data value of block at {_b} = 1 with "Data value of block should have been 1" +test "item compares": + set {_test} to a dragon head + assert {_test} is a dragon head with "failed to compare against a head" + set {_test} to a door + assert {_test} is any door, any wood door, birch door or a closed birch door with "failed to compare against a door" diff --git a/src/test/skript/tests/regressions/3303-item durability.sk b/src/test/skript/tests/regressions/3303-item durability.sk index 9f1874f2421..2eb4b57377a 100644 --- a/src/test/skript/tests/regressions/3303-item durability.sk +++ b/src/test/skript/tests/regressions/3303-item durability.sk @@ -1,5 +1,12 @@ -test "item compares": - set {_test} to a dragon head - assert {_test} is a dragon head with "failed to compare against a head" - set {_test} to a door - assert {_test} is any door, any wood door, birch door or a closed birch door with "failed to compare against a door" +test "item durability": + set {_i} to a diamond sword + set durability of {_i} to 500 + assert durability of {_i} = 500 with "Durability of item should have been 500" + +test "block data value" when running below minecraft "1.13.2": + set block at spawn of world "world" to farmland + set {_b} to block above block at spawn of world "world" + set block at {_b} to fully grown wheat plant + assert data value of block at {_b} = 7 with "Data value of block should have been 7" + set data value of block at {_b} to 1 + assert data value of block at {_b} = 1 with "Data value of block should have been 1" \ No newline at end of file From f6797281864a7febf7cf698c2127d988384d5b1f Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Fri, 14 Apr 2023 03:09:56 -0600 Subject: [PATCH 08/27] Update src/main/java/ch/njol/skript/conditions/CondCompare.java Co-authored-by: Kenzie --- src/main/java/ch/njol/skript/conditions/CondCompare.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCompare.java b/src/main/java/ch/njol/skript/conditions/CondCompare.java index 3de49023e05..476b6c89e00 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCompare.java +++ b/src/main/java/ch/njol/skript/conditions/CondCompare.java @@ -283,7 +283,7 @@ private Literal attemptReconstruct(UnparsedLiteral one, Expression two) { // Must handle numbers first. expression = one.getConvertedExpression(Number.class); if (expression == null) { - for (ConverterInfo converter : Converters.getConverterInfo()) { + for (ConverterInfo converter : Converters.getConverterInfos()) { // We're comparing the 'two' expression, so we need the 'from' for comparing. if (!converter.getFrom().isAssignableFrom(two.getReturnType())) continue; From 748d32571a4138a4a34862ea769aaa480674e215 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Tue, 25 Apr 2023 03:12:55 -0600 Subject: [PATCH 09/27] Update src/test/skript/tests/regressions/2711-item-compares.sk Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- src/test/skript/tests/regressions/2711-item-compares.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/skript/tests/regressions/2711-item-compares.sk b/src/test/skript/tests/regressions/2711-item-compares.sk index 9f1874f2421..064f6cc7cff 100644 --- a/src/test/skript/tests/regressions/2711-item-compares.sk +++ b/src/test/skript/tests/regressions/2711-item-compares.sk @@ -1,4 +1,4 @@ -test "item compares": +test "item comparison": set {_test} to a dragon head assert {_test} is a dragon head with "failed to compare against a head" set {_test} to a door From 76340ceb794cbe111e25a1513517d664c684a0c5 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Tue, 25 Apr 2023 03:13:42 -0600 Subject: [PATCH 10/27] Update src/test/skript/tests/regressions/4769-fire-visualeffect.sk Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> --- src/test/skript/tests/regressions/4769-fire-visualeffect.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk index 0a62623db58..9792c7465f6 100644 --- a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk +++ b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk @@ -1,4 +1,4 @@ -test "fire visual effect": +test "fire visual effect comparison": set {_block} to block at spawn of world "world" set block at spawn of world "world" to fire assert block at spawn of world "world" is fire with "failed to compare fire (itemtype) with a block" From 71f3da0d128be62997404466f2c39e8264f01d02 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 25 Apr 2023 18:55:21 -0600 Subject: [PATCH 11/27] Added tests wern't properly setting back block --- src/test/skript/tests/regressions/4769-fire-visualeffect.sk | 2 +- .../skript/tests/regressions/4773-composter-the-imposter.sk | 2 +- .../regressions/pull-5566-block iterator being 100 always.sk | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk index 9792c7465f6..4e9b21b5f60 100644 --- a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk +++ b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk @@ -1,5 +1,5 @@ test "fire visual effect comparison": - set {_block} to block at spawn of world "world" + set {_block} to block data of block at spawn of world "world" set block at spawn of world "world" to fire assert block at spawn of world "world" is fire with "failed to compare fire (itemtype) with a block" set block at spawn of world "world" to {_block} diff --git a/src/test/skript/tests/regressions/4773-composter-the-imposter.sk b/src/test/skript/tests/regressions/4773-composter-the-imposter.sk index 229c5344e9a..de5237cebee 100644 --- a/src/test/skript/tests/regressions/4773-composter-the-imposter.sk +++ b/src/test/skript/tests/regressions/4773-composter-the-imposter.sk @@ -1,5 +1,5 @@ test "composter the imposter" when running minecraft "1.14.4": - set {_block} to block at spawn of world "world" + set {_block} to block data of block at spawn of world "world" set block at spawn of world "world" to composter assert block at spawn of world "world" is composter with "failed to compare composter (itemtype) with a block" set block at spawn of world "world" to {_block} diff --git a/src/test/skript/tests/regressions/pull-5566-block iterator being 100 always.sk b/src/test/skript/tests/regressions/pull-5566-block iterator being 100 always.sk index 3eb14b86d94..bb654f8dfcd 100644 --- a/src/test/skript/tests/regressions/pull-5566-block iterator being 100 always.sk +++ b/src/test/skript/tests/regressions/pull-5566-block iterator being 100 always.sk @@ -1,5 +1,5 @@ # Test not related to a made issue. Details at pull request. test "100 blocks fix": - assert blocks 5 below spawn of world "world" contains air, grass block, dirt block, dirt block, bedrock block and void air with "Failed to get correct blocks" + assert blocks 5 below spawn of world "world" contains air, grass block, dirt block, dirt block, bedrock block and void air with "Failed to get correct blocks %blocks 5 below spawn of world "world"%" assert size of blocks 3 below location below spawn of world "world" is 4 with "Failed to match asserted size" From 5f520c603033b594191c2afb0b7082cbbbd2e0a6 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 25 Apr 2023 18:58:46 -0600 Subject: [PATCH 12/27] Added tests wern't properly setting back block --- src/test/skript/tests/regressions/4769-fire-visualeffect.sk | 2 +- .../skript/tests/regressions/4773-composter-the-imposter.sk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk index 4e9b21b5f60..8559e7a9fb0 100644 --- a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk +++ b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk @@ -1,5 +1,5 @@ test "fire visual effect comparison": - set {_block} to block data of block at spawn of world "world" + set {_block} to type of block at spawn of world "world" set block at spawn of world "world" to fire assert block at spawn of world "world" is fire with "failed to compare fire (itemtype) with a block" set block at spawn of world "world" to {_block} diff --git a/src/test/skript/tests/regressions/4773-composter-the-imposter.sk b/src/test/skript/tests/regressions/4773-composter-the-imposter.sk index de5237cebee..7fb0fdc677e 100644 --- a/src/test/skript/tests/regressions/4773-composter-the-imposter.sk +++ b/src/test/skript/tests/regressions/4773-composter-the-imposter.sk @@ -1,5 +1,5 @@ test "composter the imposter" when running minecraft "1.14.4": - set {_block} to block data of block at spawn of world "world" + set {_block} to type of block at spawn of world "world" set block at spawn of world "world" to composter assert block at spawn of world "world" is composter with "failed to compare composter (itemtype) with a block" set block at spawn of world "world" to {_block} From 9c72c720c5a5fbf71ffcd46b0dd0e8cea6d2b21c Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 25 Apr 2023 19:03:14 -0600 Subject: [PATCH 13/27] Apply changes --- .../java/ch/njol/skript/conditions/CondCompare.java | 13 +++++++------ .../test/tests/regression/HangingEntity_4871.java | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCompare.java b/src/main/java/ch/njol/skript/conditions/CondCompare.java index 476b6c89e00..8dbf51cfa35 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCompare.java +++ b/src/main/java/ch/njol/skript/conditions/CondCompare.java @@ -205,11 +205,12 @@ private boolean init(String expr) { } finally { log.stop(); } - Class f = first.getReturnType(), s = third == null ? second.getReturnType() : Utils.getSuperType(second.getReturnType(), third.getReturnType()); - if (f == Object.class || s == Object.class) + Class firstReturnType = first.getReturnType(); + Class secondReturnType = third == null ? second.getReturnType() : Utils.getSuperType(second.getReturnType(), third.getReturnType()); + if (firstReturnType == Object.class || secondReturnType == Object.class) return true; - comp = Comparators.getComparator(f, s); + comp = Comparators.getComparator(firstReturnType, secondReturnType); if (comp == null) { // Try to re-parse with more context /* @@ -224,15 +225,15 @@ private boolean init(String expr) { * Some damage types not working (issue #2184) would be a good example * of issues that SkriptParser's lack of context can cause. */ - SimpleLiteral reparsedSecond = reparseLiteral(first.getReturnType(), second); + SimpleLiteral reparsedSecond = reparseLiteral(firstReturnType, second); if (reparsedSecond != null) { second = reparsedSecond; - comp = Comparators.getComparator(f, second.getReturnType()); + comp = Comparators.getComparator(firstReturnType, second.getReturnType()); } else { SimpleLiteral reparsedFirst = reparseLiteral(second.getReturnType(), first); if (reparsedFirst != null) { first = reparsedFirst; - comp = Comparators.getComparator(first.getReturnType(), s); + comp = Comparators.getComparator(first.getReturnType(), secondReturnType); } } diff --git a/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java b/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java index 55b46dbc5a0..a4a47383d2b 100644 --- a/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java +++ b/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java @@ -40,7 +40,8 @@ public class HangingEntity_4871 extends SkriptJUnitTest { setShutdownDelay(1); } - private Material before, before2; + private Material before; + //private Material before2; @Before public void setupItemFrame() { From b9c9c9325fc2f65afc6be06c4eb090802fad2914 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Fri, 19 May 2023 18:00:00 -0600 Subject: [PATCH 14/27] Update src/test/skript/tests/regressions/pull-5566-block iterator being 100 always.sk Co-authored-by: Patrick Miller --- .../regressions/pull-5566-block iterator being 100 always.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/skript/tests/regressions/pull-5566-block iterator being 100 always.sk b/src/test/skript/tests/regressions/pull-5566-block iterator being 100 always.sk index bb654f8dfcd..ef77c2955f5 100644 --- a/src/test/skript/tests/regressions/pull-5566-block iterator being 100 always.sk +++ b/src/test/skript/tests/regressions/pull-5566-block iterator being 100 always.sk @@ -1,5 +1,5 @@ # Test not related to a made issue. Details at pull request. test "100 blocks fix": - assert blocks 5 below spawn of world "world" contains air, grass block, dirt block, dirt block, bedrock block and void air with "Failed to get correct blocks %blocks 5 below spawn of world "world"%" + assert blocks 5 below spawn of world "world" contains air, grass block, dirt block, dirt block, bedrock block and void air with "Failed to get correct blocks (got '%blocks 5 below spawn of world "world"%')" assert size of blocks 3 below location below spawn of world "world" is 4 with "Failed to match asserted size" From ad841ce507de799d714d4ea4e75d62807eb15e60 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Fri, 19 May 2023 18:00:57 -0600 Subject: [PATCH 15/27] Update src/test/skript/tests/regressions/3303-item durability.sk Co-authored-by: Patrick Miller --- src/test/skript/tests/regressions/3303-item durability.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/skript/tests/regressions/3303-item durability.sk b/src/test/skript/tests/regressions/3303-item durability.sk index 2eb4b57377a..991b7cda983 100644 --- a/src/test/skript/tests/regressions/3303-item durability.sk +++ b/src/test/skript/tests/regressions/3303-item durability.sk @@ -9,4 +9,4 @@ test "block data value" when running below minecraft "1.13.2": set block at {_b} to fully grown wheat plant assert data value of block at {_b} = 7 with "Data value of block should have been 7" set data value of block at {_b} to 1 - assert data value of block at {_b} = 1 with "Data value of block should have been 1" \ No newline at end of file + assert data value of block at {_b} = 1 with "Data value of block should have been 1" From f9537d7c0e95b0bc64f26ebec67d614a3808b8e5 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Fri, 19 May 2023 18:13:16 -0600 Subject: [PATCH 16/27] Update src/main/java/ch/njol/skript/test/runner/EvtTestCase.java Co-authored-by: Patrick Miller --- src/main/java/ch/njol/skript/test/runner/EvtTestCase.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java b/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java index ac56fdcbbaf..be43f030487 100644 --- a/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java +++ b/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java @@ -42,7 +42,8 @@ public class EvtTestCase extends SkriptEvent { .since("2.5"); EventValues.registerEventValue(SkriptTestEvent.class, Block.class, new Getter() { @Override - public @Nullable Block get(SkriptTestEvent ignored) { + @Nullable + public Block get(SkriptTestEvent ignored) { return SkriptJUnitTest.getBlock(); } }, EventValues.TIME_NOW); From cf77032d0b7eb1373f7530be9a2c18e325c2dea5 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Fri, 19 May 2023 18:13:26 -0600 Subject: [PATCH 17/27] Update src/main/java/ch/njol/skript/test/runner/EvtTestCase.java Co-authored-by: Patrick Miller --- src/main/java/ch/njol/skript/test/runner/EvtTestCase.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java b/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java index be43f030487..cec92f1dadc 100644 --- a/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java +++ b/src/main/java/ch/njol/skript/test/runner/EvtTestCase.java @@ -49,7 +49,8 @@ public Block get(SkriptTestEvent ignored) { }, EventValues.TIME_NOW); EventValues.registerEventValue(SkriptTestEvent.class, Location.class, new Getter() { @Override - public @Nullable Location get(SkriptTestEvent ignored) { + @Nullable + public Location get(SkriptTestEvent ignored) { return SkriptJUnitTest.getTestLocation(); } }, EventValues.TIME_NOW); From 9bab3aaa9a8066d458c3417b12fc073f15460115 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Mon, 22 May 2023 15:40:47 -0600 Subject: [PATCH 18/27] Apply changes --- .../njol/skript/conditions/CondCompare.java | 24 ++--- .../tests/regression/HangingEntity_4871.java | 89 ------------------- .../skript/tests/junit/HangingEntity_4871.sk | 17 ---- 3 files changed, 12 insertions(+), 118 deletions(-) delete mode 100644 src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java delete mode 100644 src/test/skript/tests/junit/HangingEntity_4871.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondCompare.java b/src/main/java/ch/njol/skript/conditions/CondCompare.java index 8dbf51cfa35..9bce0061841 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCompare.java +++ b/src/main/java/ch/njol/skript/conditions/CondCompare.java @@ -106,7 +106,7 @@ public class CondCompare extends Condition { @Nullable @SuppressWarnings("rawtypes") - private Comparator comp; + private Comparator comparator; @Override public boolean init(final Expression[] vars, final int matchedPattern, final Kleenean isDelayed, final ParseResult parser) { @@ -136,7 +136,7 @@ public boolean init(final Expression[] vars, final int matchedPattern, final } } @SuppressWarnings("rawtypes") - final Comparator comp = this.comp; + final Comparator comp = this.comparator; if (comp != null) { if (third == null) { if (!relation.isImpliedBy(Relation.EQUAL, Relation.NOT_EQUAL) && !comp.supportsOrdering()) { @@ -210,9 +210,9 @@ private boolean init(String expr) { if (firstReturnType == Object.class || secondReturnType == Object.class) return true; - comp = Comparators.getComparator(firstReturnType, secondReturnType); + comparator = Comparators.getComparator(firstReturnType, secondReturnType); - if (comp == null) { // Try to re-parse with more context + if (comparator == null) { // Try to re-parse with more context /* * SkriptParser sees that CondCompare takes two objects. Most of the time, * this works fine. However, when there are multiple conflicting literals, @@ -228,18 +228,18 @@ private boolean init(String expr) { SimpleLiteral reparsedSecond = reparseLiteral(firstReturnType, second); if (reparsedSecond != null) { second = reparsedSecond; - comp = Comparators.getComparator(firstReturnType, second.getReturnType()); + comparator = Comparators.getComparator(firstReturnType, second.getReturnType()); } else { SimpleLiteral reparsedFirst = reparseLiteral(second.getReturnType(), first); if (reparsedFirst != null) { first = reparsedFirst; - comp = Comparators.getComparator(first.getReturnType(), secondReturnType); + comparator = Comparators.getComparator(first.getReturnType(), secondReturnType); } } } - return comp != null; + return comparator != null; } /** @@ -340,14 +340,14 @@ public boolean check(final Event e) { return first.check(e, (Checker) o1 -> second.check(e, (Checker) o2 -> { if (third == null) - return relation.isImpliedBy(comp != null ? comp.compare(o1, o2) : Comparators.compare(o1, o2)); + return relation.isImpliedBy(comparator != null ? comparator.compare(o1, o2) : Comparators.compare(o1, o2)); return third.check(e, (Checker) o3 -> { boolean isBetween; - if (comp != null) { + if (comparator != null) { isBetween = - (Relation.GREATER_OR_EQUAL.isImpliedBy(comp.compare(o1, o2)) && Relation.SMALLER_OR_EQUAL.isImpliedBy(comp.compare(o1, o3))) + (Relation.GREATER_OR_EQUAL.isImpliedBy(comparator.compare(o1, o2)) && Relation.SMALLER_OR_EQUAL.isImpliedBy(comparator.compare(o1, o3))) // Check OPPOSITE (switching o2 / o3) - || (Relation.GREATER_OR_EQUAL.isImpliedBy(comp.compare(o1, o3)) && Relation.SMALLER_OR_EQUAL.isImpliedBy(comp.compare(o1, o2))); + || (Relation.GREATER_OR_EQUAL.isImpliedBy(comparator.compare(o1, o3)) && Relation.SMALLER_OR_EQUAL.isImpliedBy(comparator.compare(o1, o2))); } else { isBetween = (Relation.GREATER_OR_EQUAL.isImpliedBy(Comparators.compare(o1, o2)) && Relation.SMALLER_OR_EQUAL.isImpliedBy(Comparators.compare(o1, o3))) @@ -369,7 +369,7 @@ public String toString(final @Nullable Event e, final boolean debug) { else s = first.toString(e, debug) + " is " + (isNegated() ? "not " : "") + "between " + second.toString(e, debug) + " and " + third.toString(e, debug); if (debug) - s += " (comparator: " + comp + ")"; + s += " (comparator: " + comparator + ")"; return s; } diff --git a/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java b/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java deleted file mode 100644 index a4a47383d2b..00000000000 --- a/src/test/java/org/skriptlang/skript/test/tests/regression/HangingEntity_4871.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * This file is part of Skript. - * - * Skript is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Skript is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Skript. If not, see . - * - * Copyright Peter Güttinger, SkriptLang team and contributors - */ -package org.skriptlang.skript.test.tests.regression; - -import java.util.Optional; - -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.ItemFrame; -import org.bukkit.event.hanging.HangingBreakEvent; -import org.bukkit.event.hanging.HangingBreakEvent.RemoveCause; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import ch.njol.skript.test.runner.SkriptJUnitTest; - -public class HangingEntity_4871 extends SkriptJUnitTest { - - static { - // Only needed when we trigger an event or something that isn't instant. - setShutdownDelay(1); - } - - private Material before; - //private Material before2; - - @Before - public void setupItemFrame() { - // Ensure it's in the ground for the item frame to attach to a wall. - Location location = getTestLocation().subtract(0, 2, 0); - before = location.getBlock().getType(); - location.getBlock().setType(Material.AIR); - getTestWorld().spawnEntity(location, EntityType.ITEM_FRAME); - - // TODO Aliases for 'glow item frame' not on master branch for this code -// if (Skript.isRunningMinecraft(1, 17, 1)) { -// Location location2 = getTestLocation().subtract(4, 2, 0); -// before2 = location2.getBlock().getType(); -// location2.getBlock().setType(Material.AIR); -// getTestWorld().spawnEntity(location2, EntityType.GLOW_ITEM_FRAME); -// } - } - - @Test - public void testDamage() { - Location location = getTestLocation().subtract(0, 2, 0); - Optional optional = location.getNearbyEntitiesByType(ItemFrame.class, 1).stream().findFirst(); - assert optional.isPresent(); - HangingBreakEvent event = new HangingBreakEvent(optional.get(), RemoveCause.DEFAULT); - Bukkit.getPluginManager().callEvent(event); -// if (Skript.isRunningMinecraft(1, 17, 1)) { -// Location location2 = getTestLocation().subtract(4, 2, 0); -// Optional optional2 = location2.getNearbyEntitiesByType(GlowItemFrame.class, 1).stream().findFirst(); -// assert optional2.isPresent(); -// HangingBreakEvent event2 = new HangingBreakEvent(optional2.get(), RemoveCause.DEFAULT); -// Bukkit.getPluginManager().callEvent(event2); -// } - } - - @After - public void cleanupItemFrame() { - Location location = getTestLocation().subtract(0, 2, 0); - location.getBlock().setType(before); -// if (Skript.isRunningMinecraft(1, 17, 1)) { -// Location location2 = getTestLocation().subtract(4, 2, 0); -// location2.getBlock().setType(before2); -// } - } - -} diff --git a/src/test/skript/tests/junit/HangingEntity_4871.sk b/src/test/skript/tests/junit/HangingEntity_4871.sk deleted file mode 100644 index f218c5121b8..00000000000 --- a/src/test/skript/tests/junit/HangingEntity_4871.sk +++ /dev/null @@ -1,17 +0,0 @@ -test "hanging entity compare": - ensure junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" completes "item frame" - -# Aliases not on master branch for this code -#test "hanging entity glowing item frame" when running minecraft "1.17.1": -# ensure junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" completes "glowing item frame" - -on break: - junit test is "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" - assert hanging entity is an item frame with "item frame compare failed" - complete objective "item frame" for junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" - -# Aliases not on master branch for this code -#on break of glowing item frame: -# junit test is "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" -# assert hanging entity is a glow item frame with "glowing item frame compare failed" -# complete objective "glowing item frame" for junit test "org.skriptlang.skript.test.tests.regression.HangingEntity_4871" From e6e0dbc218f018fdab9ea39f1e2abd4d29e03df4 Mon Sep 17 00:00:00 2001 From: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com> Date: Fri, 26 May 2023 13:00:25 -0600 Subject: [PATCH 19/27] Update src/main/java/ch/njol/skript/conditions/CondCompare.java Co-authored-by: _tud --- src/main/java/ch/njol/skript/conditions/CondCompare.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCompare.java b/src/main/java/ch/njol/skript/conditions/CondCompare.java index 9bce0061841..99e12141e2c 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCompare.java +++ b/src/main/java/ch/njol/skript/conditions/CondCompare.java @@ -160,7 +160,7 @@ public static String f(final Expression e) { return Classes.getSuperClassInfo(e.getReturnType()).getName().withIndefiniteArticle(); } - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") private boolean init(String expr) { RetainingLogHandler log = SkriptLogger.startRetainingLog(); Expression third = this.third; From 976ed977fd56423b9258bd747d8b600ea9202c2f Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 26 May 2023 13:03:58 -0600 Subject: [PATCH 20/27] Apply changes --- src/main/java/ch/njol/skript/conditions/CondCompare.java | 8 ++++---- src/test/skript/tests/misc/entitydata with expressions.sk | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 src/test/skript/tests/misc/entitydata with expressions.sk diff --git a/src/main/java/ch/njol/skript/conditions/CondCompare.java b/src/main/java/ch/njol/skript/conditions/CondCompare.java index 99e12141e2c..348f1bbc37f 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCompare.java +++ b/src/main/java/ch/njol/skript/conditions/CondCompare.java @@ -168,7 +168,7 @@ private boolean init(String expr) { if (first.getReturnType() == Object.class) { Expression expression = null; if (first instanceof UnparsedLiteral) - expression = attemptReconstruct((UnparsedLiteral) first, second); + expression = attemptReconstruction((UnparsedLiteral) first, second); if (expression == null) expression = first.getConvertedExpression(Object.class); if (expression == null) { @@ -180,7 +180,7 @@ private boolean init(String expr) { if (second.getReturnType() == Object.class) { Expression expression = null; if (second instanceof UnparsedLiteral) - expression = attemptReconstruct((UnparsedLiteral) second, first); + expression = attemptReconstruction((UnparsedLiteral) second, first); if (expression == null) expression = second.getConvertedExpression(Object.class); if (expression == null) { @@ -192,7 +192,7 @@ private boolean init(String expr) { if (third != null && third.getReturnType() == Object.class) { Expression expression = null; if (third instanceof UnparsedLiteral) - expression = attemptReconstruct((UnparsedLiteral) third, first); + expression = attemptReconstruction((UnparsedLiteral) third, first); if (expression == null) expression = third.getConvertedExpression(Object.class); if (expression == null) { @@ -279,7 +279,7 @@ private SimpleLiteral reparseLiteral(Class type, Expression express * @return The newly formed Literal, will be SimpleLiteral in most cases. */ @SuppressWarnings("unchecked") - private Literal attemptReconstruct(UnparsedLiteral one, Expression two) { + private Literal attemptReconstruction(UnparsedLiteral one, Expression two) { Expression expression = null; // Must handle numbers first. expression = one.getConvertedExpression(Number.class); diff --git a/src/test/skript/tests/misc/entitydata with expressions.sk b/src/test/skript/tests/misc/entitydata with expressions.sk new file mode 100644 index 00000000000..04794cf8483 --- /dev/null +++ b/src/test/skript/tests/misc/entitydata with expressions.sk @@ -0,0 +1,6 @@ +test "entity data with expressions": + loop diamond, iron ingot, gold ingot and dirt: + spawn dropped loop-value at spawn of world "world": + add event-entity to {_entities::*} + assert size of {_entities::*} is 4 with "failed to collect all dropped items" + clear values within {_entities::*} From ea6ce6cdd863f1eb4206320428c1120efdc22fb9 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Fri, 26 May 2023 13:04:25 -0600 Subject: [PATCH 21/27] Apply changes --- src/test/skript/tests/misc/entitydata with expressions.sk | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 src/test/skript/tests/misc/entitydata with expressions.sk diff --git a/src/test/skript/tests/misc/entitydata with expressions.sk b/src/test/skript/tests/misc/entitydata with expressions.sk deleted file mode 100644 index 04794cf8483..00000000000 --- a/src/test/skript/tests/misc/entitydata with expressions.sk +++ /dev/null @@ -1,6 +0,0 @@ -test "entity data with expressions": - loop diamond, iron ingot, gold ingot and dirt: - spawn dropped loop-value at spawn of world "world": - add event-entity to {_entities::*} - assert size of {_entities::*} is 4 with "failed to collect all dropped items" - clear values within {_entities::*} From 7482db7a83fc76179dc10559ee40229a9d2f5d12 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 30 May 2023 05:01:24 -0600 Subject: [PATCH 22/27] Change compare gathering --- .../njol/skript/conditions/CondCompare.java | 19 +++++++++++++------ .../regressions/4769-fire-visualeffect.sk | 3 +++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/njol/skript/conditions/CondCompare.java b/src/main/java/ch/njol/skript/conditions/CondCompare.java index 348f1bbc37f..707f2626e83 100644 --- a/src/main/java/ch/njol/skript/conditions/CondCompare.java +++ b/src/main/java/ch/njol/skript/conditions/CondCompare.java @@ -22,8 +22,10 @@ import org.eclipse.jdt.annotation.Nullable; import ch.njol.skript.Skript; +import ch.njol.skript.classes.ClassInfo; import org.skriptlang.skript.lang.comparator.Comparator; +import org.skriptlang.skript.lang.comparator.ComparatorInfo; import org.skriptlang.skript.lang.comparator.Relation; import org.skriptlang.skript.lang.converter.ConverterInfo; import org.skriptlang.skript.lang.converter.Converters; @@ -284,14 +286,19 @@ private Literal attemptReconstruction(UnparsedLiteral one, Expression two) // Must handle numbers first. expression = one.getConvertedExpression(Number.class); if (expression == null) { - for (ConverterInfo converter : Converters.getConverterInfos()) { - // We're comparing the 'two' expression, so we need the 'from' for comparing. - if (!converter.getFrom().isAssignableFrom(two.getReturnType())) + for (ClassInfo classinfo : Classes.getClassInfos()) { + if (classinfo.getParser() == null) continue; - // Must be comparable if we're going to attempt to convert this UnparsedLiteral. Otherwise why attempt something that won't work. - if (Comparators.getComparator(two.getReturnType(), converter.getTo()) == null) + ComparatorInfo comparator = Comparators.getComparatorInfo(two.getReturnType(), classinfo.getC()); + if (comparator == null) continue; - expression = reparseLiteral(converter.getTo(), one); + // We don't care about comparators that take in an object. This just causes more issues accepting and increases iterations by half. + // Let getConvertedExpression deal with it in the end if no other possible reparses against the remaining classinfos exist. + if (comparator.getFirstType() == Object.class) + continue; + expression = reparseLiteral(classinfo.getC(), one); + if (expression != null) + break; } } if (expression == null) diff --git a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk index 8559e7a9fb0..ee0f837f19c 100644 --- a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk +++ b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk @@ -1,4 +1,7 @@ test "fire visual effect comparison": + assert a block is a block with "failed to compare block classinfo against block classinfo" + assert an itemtype is an itemtype with "failed to compare itemtype classinfo against itemtype classinfo" + assert an diamond is an itemtype with "failed to compare itemtype 'diamond' against itemtype classinfo" set {_block} to type of block at spawn of world "world" set block at spawn of world "world" to fire assert block at spawn of world "world" is fire with "failed to compare fire (itemtype) with a block" From e4fd0fa7807118fba9e11b446481fdfd01437ede Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 30 May 2023 05:04:06 -0600 Subject: [PATCH 23/27] Grammar in test --- src/test/skript/tests/regressions/4769-fire-visualeffect.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk index ee0f837f19c..3965e6c877f 100644 --- a/src/test/skript/tests/regressions/4769-fire-visualeffect.sk +++ b/src/test/skript/tests/regressions/4769-fire-visualeffect.sk @@ -1,7 +1,7 @@ test "fire visual effect comparison": assert a block is a block with "failed to compare block classinfo against block classinfo" assert an itemtype is an itemtype with "failed to compare itemtype classinfo against itemtype classinfo" - assert an diamond is an itemtype with "failed to compare itemtype 'diamond' against itemtype classinfo" + assert a diamond is an itemtype with "failed to compare itemtype 'diamond' against itemtype classinfo" set {_block} to type of block at spawn of world "world" set block at spawn of world "world" to fire assert block at spawn of world "world" is fire with "failed to compare fire (itemtype) with a block" From bc8e7eab899152bfcdfa70b1dd26f2034b59ae0e Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 30 May 2023 05:10:53 -0600 Subject: [PATCH 24/27] Revert block data version changes --- src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk b/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk index 87f5a2cdce2..1916c370f95 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk @@ -1,4 +1,4 @@ -test "block data" when running minecraft "1.16.5": +test "block data" when running minecraft "1.15.2": set {_b} to block at spawn of world "world" set block at {_b} to campfire[lit=false;waterlogged=true] assert block at {_b} is an unlit campfire with "block at spawn should be an unlit campfire" From 084da819175b6823c53a62dd5017306309a5611e Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Tue, 30 May 2023 05:15:34 -0600 Subject: [PATCH 25/27] Lower block data test to 1.14.4 --- src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk b/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk index 1916c370f95..8fd992f8ce1 100644 --- a/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk +++ b/src/test/skript/tests/syntaxes/expressions/ExprBlockData.sk @@ -1,4 +1,4 @@ -test "block data" when running minecraft "1.15.2": +test "block data" when running minecraft "1.14.4": set {_b} to block at spawn of world "world" set block at {_b} to campfire[lit=false;waterlogged=true] assert block at {_b} is an unlit campfire with "block at spawn should be an unlit campfire" From c0d4068b816ce43d218d032565ac8ce94d0b7f65 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 1 Jun 2023 23:22:27 -0600 Subject: [PATCH 26/27] Change separator --- src/main/java/ch/njol/skript/test/runner/TestTracker.java | 3 ++- src/test/skript/tests/misc/dummy.sk | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/njol/skript/test/runner/TestTracker.java b/src/main/java/ch/njol/skript/test/runner/TestTracker.java index de78cf743f2..dde781c344f 100644 --- a/src/main/java/ch/njol/skript/test/runner/TestTracker.java +++ b/src/main/java/ch/njol/skript/test/runner/TestTracker.java @@ -18,6 +18,7 @@ */ package ch.njol.skript.test.runner; +import java.io.File; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -57,7 +58,7 @@ public static void testFailed(String msg) { public static void testFailed(String msg, Script script) { String file = script.getConfig().getFileName(); - file = file.substring(file.lastIndexOf("\\") + 1); + file = file.substring(file.lastIndexOf(File.separator) + 1); failedTests.put(currentTest, msg + " [" + file + "]"); } diff --git a/src/test/skript/tests/misc/dummy.sk b/src/test/skript/tests/misc/dummy.sk index abf6c02d80e..358ba8c6417 100644 --- a/src/test/skript/tests/misc/dummy.sk +++ b/src/test/skript/tests/misc/dummy.sk @@ -1,2 +1,3 @@ test "redundant": - assert "true" is "true" with "logic failed" \ No newline at end of file + assert "true" is "true" with "logic failed" + assert "true" is "false" with "logic failed" \ No newline at end of file From 0464f8b0fa7d0b72fe7f13af825b0320a875ab06 Mon Sep 17 00:00:00 2001 From: TheLimeGlass Date: Thu, 1 Jun 2023 23:22:55 -0600 Subject: [PATCH 27/27] Remove test line from test --- src/test/skript/tests/misc/dummy.sk | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/skript/tests/misc/dummy.sk b/src/test/skript/tests/misc/dummy.sk index 358ba8c6417..d31e8fd53b7 100644 --- a/src/test/skript/tests/misc/dummy.sk +++ b/src/test/skript/tests/misc/dummy.sk @@ -1,3 +1,2 @@ test "redundant": assert "true" is "true" with "logic failed" - assert "true" is "false" with "logic failed" \ No newline at end of file