Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e9ba651
Use ParsingStack for parent detection instead of cascading simplifica…
sovdeeth Apr 30, 2025
a6a80ff
properly implement ExprArithmetic simplification
sovdeeth Apr 30, 2025
f91a30b
Fix Direction and ConvertedExpression simplification
sovdeeth Apr 30, 2025
cf7fdb6
slight change to contract wording
sovdeeth Apr 30, 2025
e6dc0c7
Docs for Simplifiable
sovdeeth Apr 30, 2025
54ff5c3
Tests
sovdeeth Apr 30, 2025
7fa2967
Add config toggle
sovdeeth Apr 30, 2025
78431c7
Make toggle not user-facing
sovdeeth Apr 30, 2025
665a02b
Add more wrapper methods to SimplifiedLiteral and implement simplify(…
sovdeeth May 1, 2025
58abba7
remove debug stuff
sovdeeth May 1, 2025
ae74429
Support proper wrapper + converted expression simplification (hopefully)
sovdeeth May 14, 2025
abcc42f
Requested Changes
sovdeeth May 14, 2025
83e12e8
Move package to ch.njol
sovdeeth May 14, 2025
f732017
Merge branch 'dev/feature' into feature/simplification-2
sovdeeth May 14, 2025
8c8e3a7
requested changes
sovdeeth May 20, 2025
8e252ff
don't simplify lists into single literals
sovdeeth May 20, 2025
6facf33
Merge branch 'dev/feature' into feature/simplification-2
sovdeeth Jun 4, 2025
699cf5a
re-implement indexOf simplify()
sovdeeth Jun 4, 2025
f27cdeb
allow empty data arrays in SimpleLiteral
sovdeeth Jun 5, 2025
17b47f1
Merge branch 'dev/feature' into feature/simplification-2
sovdeeth Jun 26, 2025
3bbe413
fix merge
sovdeeth Jun 26, 2025
ca0f980
update tests
sovdeeth Jun 26, 2025
88bd5b1
Merge branch 'dev/feature' into feature/simplification-2
sovdeeth Jul 1, 2025
677eaf3
Merge branch 'dev/feature' into feature/simplification-2
APickledWalrus Jul 1, 2025
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
4 changes: 4 additions & 0 deletions src/main/java/ch/njol/skript/SkriptConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ private static void userDisableHooks(Class<? extends Hook<?>> hookClass, boolean
public static final Option<Integer> variableChangesUntilSave = new Option<>("variable changes until save", 1000)
.setter(FlatFileStorage::setRequiredChangesForResave);

// intentionally not present in the config presented to the user. Users must manually add this option to disable it.
public static final Option<Boolean> simplifySyntaxesOnParse = new Option<>("simplify syntax on parse", true)
Comment thread
sovdeeth marked this conversation as resolved.
.optional(true);

/**
* This should only be used in special cases
*/
Expand Down
29 changes: 12 additions & 17 deletions src/main/java/ch/njol/skript/effects/EffMessage.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
package ch.njol.skript.effects;

import java.util.List;
import java.util.UUID;

import ch.njol.skript.registrations.Classes;
import ch.njol.skript.util.LiteralUtils;
import ch.njol.skript.util.chat.MessageComponent;
import ch.njol.util.coll.CollectionUtils;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.RequiredPlugins;
import ch.njol.skript.doc.Since;
import ch.njol.skript.doc.*;
import ch.njol.skript.expressions.ExprColoured;
import ch.njol.skript.lang.Effect;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionList;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.VariableString;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.util.LiteralUtils;
import ch.njol.skript.util.chat.BungeeConverter;
import ch.njol.skript.util.chat.ChatMessages;
import ch.njol.skript.util.chat.MessageComponent;
import ch.njol.util.Kleenean;
import ch.njol.util.coll.CollectionUtils;
import net.md_5.bungee.api.chat.BaseComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.UUID;

@Name("Message")
@Description({"Sends a message to the given player. Only styles written",
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/ch/njol/skript/expressions/ExprARGB.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package ch.njol.skript.expressions;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Keywords;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.doc.*;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Color;
import ch.njol.util.Kleenean;
import ch.njol.skript.lang.simplification.SimplifiedLiteral;

import java.util.Locale;
import java.util.function.Function;
Expand Down Expand Up @@ -54,6 +52,13 @@ protected String getPropertyName() {
return color.name().toLowerCase(Locale.ENGLISH);
}

@Override
public Expression<? extends Integer> simplify() {
if (getExpr() instanceof Literal<? extends Color>)
return SimplifiedLiteral.fromExpression(this);
return this;
}

/**
* helper enum for getting argb values of {@link Color}s.
*/
Expand Down
28 changes: 18 additions & 10 deletions src/main/java/ch/njol/skript/expressions/ExprAlphabetList.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package ch.njol.skript.expressions;

import java.util.Arrays;

import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.lang.simplification.SimplifiedLiteral;

import java.util.Arrays;

@Name("Alphabetical Sort")
@Description("Sorts given strings in alphabetical order.")
Expand All @@ -38,8 +39,8 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye

@Override
@Nullable
protected String[] get(Event e) {
String[] sorted = texts.getAll(e).clone(); // Not yet sorted
protected String[] get(Event event) {
String[] sorted = texts.getAll(event).clone(); // Not yet sorted
Arrays.sort(sorted); // Now sorted
return sorted;
}
Expand All @@ -55,8 +56,15 @@ public boolean isSingle() {
}

@Override
public String toString(@Nullable Event e, boolean debug) {
return "alphabetically sorted strings: " + texts.toString(e, debug);
public Expression<? extends String> simplify() {
if (texts instanceof Literal<String>)
return SimplifiedLiteral.fromExpression(this);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "alphabetically sorted " + texts.toString(event, debug);
}

}
}
30 changes: 19 additions & 11 deletions src/main/java/ch/njol/skript/expressions/ExprAltitude.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package ch.njol.skript.expressions;

import org.bukkit.Location;

import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Example;
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.Literal;
import org.bukkit.Location;
import ch.njol.skript.lang.simplification.SimplifiedLiteral;

/**
* @author Peter Güttinger
*/
@Name("Altitude")
@Description("Effectively an alias of 'y-<a href='#ExprCoordinate'>coordinate</a> of …', it represents the height of some object above bedrock.")
@Examples({"on damage:",
" altitude of the attacker is higher than the altitude of the victim",
" set damage to damage * 1.2"})
@Description("Effectively an alias of 'y-<a href='#ExprCoordinate'>coordinate</a> of …', it represents the height of some location within the world.")
@Example("""
on damage:
altitude of the attacker is higher than the altitude of the victim
set damage to damage * 1.2
""")
@Since("1.4.3")
public class ExprAltitude extends SimplePropertyExpression<Location, Number> {

Expand All @@ -37,5 +38,12 @@ protected String getPropertyName() {
public Class<? extends Number> getReturnType() {
return Number.class;
}


@Override
public Expression<? extends Number> simplify() {
if (getExpr() instanceof Literal<? extends Location>)
return SimplifiedLiteral.fromExpression(this);
return this;
}

}
9 changes: 9 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprAngle.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.lang.simplification.SimplifiedLiteral;

@Name("Angle")
@Description({
Expand Down Expand Up @@ -72,6 +74,13 @@ public Class<? extends Number> getReturnType() {
return Number.class;
}

@Override
public Expression<? extends Number> simplify() {
if (angle instanceof Literal<?>)
return SimplifiedLiteral.fromExpression(this);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return angle.toString(event, debug) + " in " + (isRadians ? "degrees" : "radians");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"set {_item} to thing banner pattern item"
})
@Since("2.10")
// TODO: turn this into a Literal
public class ExprBannerItem extends SimpleExpression<ItemType> {

private static final Map<Object, Material> bannerMaterials = new HashMap<>();
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ch/njol/skript/expressions/ExprBiome.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.njol.skript.expressions;

import ch.njol.skript.lang.Literal;
import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.event.Event;
Expand All @@ -17,6 +18,7 @@
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.util.Direction;
import ch.njol.util.Kleenean;
import ch.njol.skript.lang.simplification.SimplifiedLiteral;

/**
* @author Peter Güttinger
Expand Down Expand Up @@ -74,12 +76,18 @@ public Class<? extends Biome> getReturnType() {
return Biome.class;
}

@Override
public Expression<? extends Biome> simplify() {
if (getExpr() instanceof Literal<? extends Location>)
return SimplifiedLiteral.fromExpression(this);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "the biome at " + getExpr().toString(event, debug);
}

@SuppressWarnings("unchecked")
@Override
public boolean setTime(int time) {
super.setTime(time, getExpr());
Expand Down
19 changes: 6 additions & 13 deletions src/main/java/ch/njol/skript/expressions/ExprBlock.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package ch.njol.skript.expressions;

import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;

import ch.njol.skript.Skript;
import org.skriptlang.skript.lang.converter.Converter;
import org.skriptlang.skript.lang.converter.ConverterInfo;
import ch.njol.skript.doc.Description;
import ch.njol.skript.doc.Examples;
import ch.njol.skript.doc.Name;
Expand All @@ -20,6 +13,11 @@
import ch.njol.skript.lang.util.ConvertedExpression;
import ch.njol.skript.util.Direction;
import ch.njol.util.Kleenean;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import org.skriptlang.skript.lang.converter.ConverterInfo;

/**
* @author Peter Güttinger
Expand Down Expand Up @@ -48,12 +46,7 @@ public boolean init(final Expression<?>[] exprs, final int matchedPattern, final
if (exprs.length > 0) {
setExpr(new ConvertedExpression<>(Direction.combine((Expression<? extends Direction>) exprs[0],
(Expression<? extends Location>) exprs[1]), Block.class,
new ConverterInfo<>(Location.class, Block.class, new Converter<Location, Block>() {
@Override
public Block convert(final Location l) {
return l.getBlock();
}
}, 0)));
new ConverterInfo<>(Location.class, Block.class, Location::getBlock, 0)));
return true;
} else {
setExpr(new EventValueExpression<>(Block.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.Literal;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.lang.simplification.SimplifiedLiteral;

@Name("Character from Codepoint")
@Description("Returns the character at the specified codepoint")
Expand Down Expand Up @@ -43,6 +46,13 @@ public Class<? extends String> getReturnType() {
return String.class;
}

@Override
public Expression<? extends String> simplify() {
if (getExpr() instanceof Literal<? extends Integer>)
return SimplifiedLiteral.fromExpression(this);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "character at codepoint " + getExpr().toString(event, debug);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import ch.njol.skript.doc.Since;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.util.Kleenean;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.event.Event;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.lang.simplification.SimplifiedLiteral;

@Name("Characters Between")
@Description({
Expand Down Expand Up @@ -95,6 +97,13 @@ public Class<? extends String> getReturnType() {
return String.class;
}

@Override
public Expression<? extends String> simplify() {
if (start instanceof Literal<?> && end instanceof Literal<?>)
return SimplifiedLiteral.fromExpression(this);
return this;
}

@Override
public String toString(@Nullable Event event, boolean debug) {
return "all the " + (isAlphanumeric ? "alphanumeric " : "") + "characters between " + start.toString(event, debug) + " and " + end.toString(event, debug);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/ch/njol/skript/expressions/ExprCodepoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import ch.njol.skript.doc.Name;
import ch.njol.skript.doc.Since;
import ch.njol.skript.expressions.base.SimplePropertyExpression;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.Literal;
import org.jetbrains.annotations.Nullable;
import ch.njol.skript.lang.simplification.SimplifiedLiteral;

@Name("Character Codepoint")
@Description("Returns the Unicode codepoint of a character")
Expand Down Expand Up @@ -48,6 +51,13 @@ public Class<? extends Integer> getReturnType() {
return Integer.class;
}

@Override
public Expression<? extends Integer> simplify() {
if (getExpr() instanceof Literal<? extends String>)
return SimplifiedLiteral.fromExpression(this);
return this;
}

@Override
protected String getPropertyName() {
return "codepoint";
Expand Down
Loading