Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class CondExprCompare extends ConditionalExpression {
"if {_string} is not equal to {_string2}:",
"if 1 = 1:")
.since("1.0.0")
.setPriority(0)
.register();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class CondExprContains extends ConditionalExpression {
"%string% [1:does(n't| not)] contain[s] %string%",
"%objects% [1:do[es](n't| not)] contain[s] %objects%"
)
.setPriority(2)
.name("Contains")
.description("Checks if a given list of objects contain a given element. You can also check if a string contains another string.")
.examples("if {_string} contains \"hello\":",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
import io.github.syst3ms.skriptparser.file.FileElement;
import io.github.syst3ms.skriptparser.lang.Expression;
import io.github.syst3ms.skriptparser.lang.Variable;
import io.github.syst3ms.skriptparser.lang.base.ConvertedExpression;
import io.github.syst3ms.skriptparser.log.ErrorType;
import io.github.syst3ms.skriptparser.log.SkriptLogger;
import io.github.syst3ms.skriptparser.parsing.ParserState;
import io.github.syst3ms.skriptparser.parsing.SyntaxParser;
import io.github.syst3ms.skriptparser.types.PatternType;
import io.github.syst3ms.skriptparser.types.conversions.Converters;

import java.util.Optional;
import java.util.function.Function;

public class ExpressionLoader<T> extends OptionLoader {

Expand Down Expand Up @@ -60,20 +57,8 @@ public boolean loadEntry(SectionConfiguration config, FileElement element, Parse
}

Expression<?> expression = exprOptional.get();
if (Variable.class.isAssignableFrom(expression.getClass())) {
Class<?> returnType = expression.getReturnType();

if (!this.typeClass.isAssignableFrom(returnType)) {
Optional<? extends Function<?, Optional<? extends T>>> converter = Converters.getConverter(returnType, this.typeClass);
if (converter.isPresent()) {
ConvertedExpression<?, T> tConvertedExpression = ConvertedExpression.newInstance(expression, this.typeClass, converter.get());
config.getData().put(this.key, tConvertedExpression);
return true;
}

logger.error("Expression '" + s + "' does not return a " + typeClass.getSimpleName() + " found: " + expression.getReturnType().getSimpleName(), ErrorType.SEMANTIC_ERROR);
return false;
}
if (expression instanceof Variable<?> var) {
var.setReturnType(this.typeClass);
}

config.getData().put(this.key, expression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public <T> Optional<T> getValue(String key, Class<T> cls) {
public <T> Optional<Expression<T>> getExpression(String key, Class<T> cls) {
Object o = this.data.get(key);
if (o instanceof Expression<?> expression && cls.isAssignableFrom(expression.getReturnType())) {
return (Optional<Expression<T>>) Optional.of((T) expression);
return Optional.of((Expression<T>) expression);
}
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,25 @@ public String deserialize(Gson gson, JsonElement element) {
return gson.fromJson(element, String.class);
}
})
.arithmetic(new Arithmetic<String, String>() {
@Override
public String difference(String first, String second) {
return first.substring(second.length());
}
@Override
public String add(String value, String difference) {
return value + difference;
}
@Override
public String subtract(String value, String difference) {
return value.substring(0, value.length() - difference.length());
}

@Override
public Class<? extends String> getRelativeType() {
return String.class;
}
})
.register();

registration.newType(Boolean.class, "boolean", "boolean@s")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ public abstract class SyntaxRegistrar<C extends SyntaxElement> implements Regist
protected final List<String> patterns = new ArrayList<>();
protected final Map<String, Object> data = new HashMap<>();
protected Documentation documentation = new Documentation();
protected int priority;
protected int priority = 5;

SyntaxRegistrar(Class<C> c, String... patterns) {
this.c = c;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,26 @@ public class StructFunction extends Structure {
static {
Parser.getMainRegistration()
.newStructure(StructFunction.class, "*[:local[ ]] func[tion] <" + Functions.FUNCTION_NAME_REGEX + ">" +
"\\([params:%*functionparameters%]\\)[return: \\:\\: <.+>]")
"\\([params:%*functionparameters%]\\)[return: (\\:\\:|returns|-\\>) <.+>]")
.setHandledContexts(FunctionContext.class)
.name("Function")
.description("Creates a function that can be called from other scripts.")
.description("Creates a function that can be called from other scripts.",
"`local` indicates a function that can only be called from the same script.")
.since("1.0.0")
.examples("function getName(p: player) :: string:",
"\treturn name of {_p}",
"",
"function getLocation(e: entity) returns location:",
"\treturn location of {_e}",
"",
"function getWorld(e: entity) -> world:",
"\treturn world of {_e}",
"",
"function spawn(p: players):",
"\tteleport {_p::*} to {spawn}",
"",
"function broadcast(m: string, p: players):",
"\tsend {_m} to {_p::*}")
.register();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.syst3ms.skriptparser.util.color;

import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -116,6 +117,7 @@ public static Color of(long hex, boolean isAlpha) {
* @see #COLOR_PATTERN
*/
public static Optional<Color> ofHex(String hex) {
hex = hex.toLowerCase(Locale.ROOT);
if (!hex.matches(COLOR_PATTERN.pattern()))
return Optional.empty();

Expand Down
Loading