diff --git a/src/main/java/io/github/syst3ms/skriptparser/effects/EffEscape.java b/src/main/java/io/github/syst3ms/skriptparser/effects/EffEscape.java index 8dd7b33be..b8a9d3132 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/effects/EffEscape.java +++ b/src/main/java/io/github/syst3ms/skriptparser/effects/EffEscape.java @@ -63,7 +63,7 @@ public Optional walk(TriggerContext ctx) { ? ((SelfReferencing) val).getActualNext() : val.getNext()); - // Because otherwise SelfReferencing sections will getFirst reference to themselves + // Because otherwise SelfReferencing sections will first reference to themselves if (current.filter(val -> val instanceof Finishing).isEmpty()) am--; } diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/CondExprCompare.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/CondExprCompare.java index 9bf39f86d..cdbfde271 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/CondExprCompare.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/CondExprCompare.java @@ -133,7 +133,7 @@ public boolean init(Expression[] expressions, int matchedPattern, ParseContex || firstEach && first.isSingle() != second.isSingle() || second.isSingle() != third.isSingle())) { /* - * What is ruled out here is using "each" when "getSecond" and "third" don't match in number or in and/or type. + * What is ruled out here is using "each" when "second" and "third" don't match in number or in and/or type. * Otherwise these are fundamentally the same checks as above but when "third" is present. */ logger.error( diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExecExprListOperators.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExecExprListOperators.java index 86404bc08..e6a887c06 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExecExprListOperators.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExecExprListOperators.java @@ -16,8 +16,8 @@ * Basic list operators that return the following elements: * * However, this syntax can also be used as an effect. If this is the case, instead of returning @@ -32,7 +32,7 @@ * @author Mwexim * @name List Operators * @type EFFECT/EXPRESSION - * @pattern extract [the] (last|getFirst|%integer%(st|nd|rd|th)) element out [of] %objects% + * @pattern extract [the] (last|first|%integer%(st|nd|rd|th)) element out [of] %objects% * @pattern pop %objects% * @pattern (shift | poll) %objects% * @pattern splice %objects% (from %integer% to %integer%|starting (at|from) %integer%|up to %integer%) [[with] step %integer%] @@ -45,14 +45,14 @@ public class ExecExprListOperators extends ExecutableExpression { ExecExprListOperators.class, Object.class, false, - "extract [the] (0:last|1:getFirst|2:%integer%(st|nd|rd|th)) element out [of] %objects%", + "extract [the] (0:last|1:first|2:%integer%(st|nd|rd|th)) element out [of] %objects%", "pop %objects%", "(shift|poll) %objects%", "splice %objects% (0:from %integer% to %integer%|1:starting (at|from) %integer%|2:up to %integer%) [[with] step %integer%]" ); } - // 0 = last, 1 = getFirst, 2 = indexed, 3 = spliced + // 0 = last, 1 = first, 2 = indexed, 3 = spliced private int type; private Expression list; private Expression index; diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExecExprReplace.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExecExprReplace.java index 1d7463c08..c01b04408 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExecExprReplace.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExecExprReplace.java @@ -23,8 +23,8 @@ * @author Mwexim * @name Replace * @type EFFECT/EXPRESSION - * @pattern replace [(all|every|[the] getFirst|[the] last)] [regex [pattern[s]]] %strings% in %strings% with %string% - * @pattern replace [(all|every|[the] getFirst|[the] last)] [regex [pattern[s]]] %strings% with %string% in %strings% + * @pattern replace [(all|every|[the] first|[the] last)] [regex [pattern[s]]] %strings% in %strings% with %string% + * @pattern replace [(all|every|[the] first|[the] last)] [regex [pattern[s]]] %strings% with %string% in %strings% * @see ExprElement * @since ALPHA */ @@ -32,8 +32,8 @@ public class ExecExprReplace extends ExecutableExpression { static { // TODO add "new" so we can add docs Parser.getMainRegistration().addExecutableExpression(ExecExprReplace.class, String.class, false, - "replace [(0:all|0:every|1:[the] getFirst|2:[the] last)] [:regex [pattern[s]]] %strings% in %strings% with %string%", - "replace [(0:all|0:every|1:[the] getFirst|2:[the] last)] [:regex [pattern[s]]] %strings% with %string% in %strings%" + "replace [(0:all|0:every|1:[the] first|2:[the] last)] [:regex [pattern[s]]] %strings% in %strings% with %string%", + "replace [(0:all|0:every|1:[the] first|2:[the] last)] [:regex [pattern[s]]] %strings% with %string% in %strings%" ); } @@ -136,7 +136,7 @@ public String[] getValues(TriggerContext ctx, boolean isEffect) { @Override public String toString(TriggerContext ctx, boolean debug) { return "replace " - + new String[]{"all ", "getFirst ", "last "}[type] + toMatch.toString(ctx, debug) + + new String[]{"all ", "first ", "last "}[type] + toMatch.toString(ctx, debug) + " in " + toReplace.toString(ctx, debug) + " with " + replacement.toString(ctx, debug); } diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAmount.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAmount.java index 3710bd104..be72184df 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAmount.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprAmount.java @@ -13,7 +13,7 @@ /** * The amount of elements in a given list. - * Note that when getting the size of a list variable, it will only return the size of the getFirst layer of elements. + * Note that when getting the size of a list variable, it will only return the size of the first layer of elements. * If you want to get the whole list size, including nested layers in a variable, use the recursive size instead. * * @author Olyno, Mwexim diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDateInformation.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDateInformation.java index ff8f362da..d940e435e 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDateInformation.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDateInformation.java @@ -19,7 +19,7 @@ * @author Mwexim * @name Date Information * @type EXPRESSION - * @pattern [the] (year[s]|month[s]|day[s] (of|in) year|day[s] (of|in) month|day[s] (of|in) week|hour[s]|minute[s]|getSecond[s]|milli[getSecond][s]) (of|in) %date/time% + * @pattern [the] (year[s]|month[s]|day[s] (of|in) year|day[s] (of|in) month|day[s] (of|in) week|hour[s]|minute[s]|second[s]|milli[second][s]) (of|in) %date/time% * @pattern [the] (era|month|weekday|day [(of|in) week]) [name] (of|in) [date] %date% * @since ALPHA */ @@ -32,8 +32,8 @@ public class ExprDateInformation implements Expression { {"day[s] (of|in) week", (Function) val -> val.getDayOfWeek().getValue()}, {"hour[s]", (Function) LocalDateTime::getHour}, {"minute[s]", (Function) LocalDateTime::getMinute}, - {"getSecond[s]", (Function) LocalDateTime::getSecond}, - {"milli[getSecond][s]", (Function) val -> val.getNano() / 1_000_000} + {"second[s]", (Function) LocalDateTime::getSecond}, + {"milli[second][s]", (Function) val -> val.getNano() / 1_000_000} }); private static final PatternInfos> STRING_VALUES = new PatternInfos<>(new Object[][]{ diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDefaultValue.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDefaultValue.java index 1b5343ef4..6a5c3eb9f 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDefaultValue.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDefaultValue.java @@ -6,7 +6,7 @@ import io.github.syst3ms.skriptparser.parsing.ParseContext; /** - * A shorthand expression for giving things a default value. If the getFirst thing isn't set, the getSecond thing will be returned. + * A shorthand expression for giving things a default value. If the first thing isn't set, the second thing will be returned. * * @author Olyno * @name Default Value @@ -18,7 +18,7 @@ public class ExprDefaultValue implements Expression { Parser.getMainRegistration().newExpression(ExprDefaultValue.class, Object.class, false, "%objects% (otherwise|?) %objects%") .name("Default Value") - .description("Returns the getFirst expression if it's set, otherwise the getSecond expression.") + .description("Returns the first expression if it's set, otherwise the second expression.") .examples("set {_var} to {_otherVarIfSet} otherwise \"world\"", "send {_varIfSet} ? \"ruh roh, no message\"") .since("1.0.0"); diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDurationSinceUntil.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDurationSinceUntil.java index 641e4e73d..5029b1749 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDurationSinceUntil.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprDurationSinceUntil.java @@ -10,8 +10,8 @@ /** * Compares the given date with the current date. - * Note that the getFirst pattern is to compare with the past - * and the getSecond one to compare with the future. + * Note that the first pattern is to compare with the past + * and the second one to compare with the future. * Note that the accuracy can be off some milliseconds. * * @author Mwexim diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprElement.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprElement.java index 591cf455b..3e323815c 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprElement.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprElement.java @@ -16,8 +16,8 @@ * @author Mwexim * @name Element * @type EXPRESSION - * @pattern ([the] getFirst | [the] last | [a] random | [the] % integer % ( st | nd | rd | th)) element out [of] %objects% - * @pattern [the] (getFirst|last) %integer% elements out [of] %objects% + * @pattern ([the] first | [the] last | [a] random | [the] % integer % ( st | nd | rd | th)) element out [of] %objects% + * @pattern [the] (first|last) %integer% elements out [of] %objects% * @pattern %integer% random elements out [of] %objects% * @pattern %objects%\[%integer%\] * @since ALPHA @@ -27,8 +27,8 @@ public class ExprElement implements Expression { static { Parser.getMainRegistration().newExpression(ExprElement.class, Object.class, true, - "(0:[the] getFirst|1:[the] last|2:[a] random|3:[the] %integer%(st|nd|rd|th)) element [out] of %objects%", - "[the] (0:getFirst|1:last) %integer% elements [out] of %objects%", + "(0:[the] first|1:[the] last|2:[a] random|3:[the] %integer%(st|nd|rd|th)) element [out] of %objects%", + "[the] (0:first|1:last) %integer% elements [out] of %objects%", "%integer% random elements [out] of %objects%", "%objects%\\[%integer%\\]") .name("Element") diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprLoopValue.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprLoopValue.java index e030067e9..aa4cb36c3 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprLoopValue.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprLoopValue.java @@ -75,7 +75,7 @@ public Function, Optional> ge return sections -> { int j = 1; SecLoop loop = null; - // The closest section is getFirst, let's reverse this behavior for convenience + // The closest section is first, let's reverse this behavior for convenience Collections.reverse(sections); for (SecLoop l : sections) { Class loopedType = l.getLoopedExpression().getReturnType(); diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprStringOccurrence.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprStringOccurrence.java index fbc26d215..09fd54d73 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprStringOccurrence.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprStringOccurrence.java @@ -7,21 +7,21 @@ import io.github.syst3ms.skriptparser.util.DoubleOptional; /** - * The index of the getFirst or last occurrence of a given string in a string. + * The index of the first or last occurrence of a given string in a string. * Note that indices in Skript start at 1. * * @author Mwexim * @name Occurrence * @type EXPRESSION - * @pattern [the] (getFirst|last) occurrence of %string% in %string% + * @pattern [the] (first|last) occurrence of %string% in %string% * @since ALPHA */ public class ExprStringOccurrence implements Expression { static { Parser.getMainRegistration().newExpression(ExprStringOccurrence.class, Number.class, true, - "[the] (0:getFirst|1:last) occurrence of %string% in %string%") + "[the] (0:first|1:last) occurrence of %string% in %string%") .name("Occurrence") - .description("Returns the index of the getFirst or last occurrence of a given string in a string.") + .description("Returns the index of the first or last occurrence of a given string in a string.") .since("1.0.0") .register(); } @@ -50,7 +50,7 @@ public Number[] getValues(TriggerContext ctx) { @Override public String toString(TriggerContext ctx, boolean debug) { - return (first ? "getFirst" : "last") + " occurrence of " + needle.toString(ctx, debug) + " in " + haystack.toString(ctx, debug); + return (first ? "first" : "last") + " occurrence of " + needle.toString(ctx, debug) + " in " + haystack.toString(ctx, debug); } } diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprSubstring.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprSubstring.java index 0ea8a6153..9752b2b23 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprSubstring.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprSubstring.java @@ -19,8 +19,8 @@ public class ExprSubstring implements Expression { static { Parser.getMainRegistration().newExpression(ExprSubstring.class, String.class, true, "[the] (part|sub[ ](text|string)) of %string% (between|from) [(ind(ex[es]|ices)|char[acter][s])] %integer% (and|to) [(index|char[acter])] %integer%", - "[the] (0:getFirst|1:last) [%integer%] char[acter][s] (of|in) %string%", - "[the] %integer% (0:getFirst|1:last) char[acter]s (of|in) %string%") + "[the] (0:first|1:last) [%integer%] char[acter][s] (of|in) %string%", + "[the] %integer% (0:first|1:last) char[acter]s (of|in) %string%") .name("Substring") .description("Extracts a part of a string.") .since("1.0.0") @@ -93,7 +93,7 @@ public String toString(TriggerContext ctx, boolean debug) { return "substring of " + value.toString(ctx, debug) + " from " + lower.toString(ctx, debug) + " to " + upper.toString(ctx, debug); } else { - return (first ? "getFirst " : "last ") + (lower != null ? lower.toString(ctx, debug) : "") + return (first ? "first " : "last ") + (lower != null ? lower.toString(ctx, debug) : "") + " characters of " + value.toString(ctx, debug); } } diff --git a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprTernary.java b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprTernary.java index d5b8f9cd0..7b419edaf 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprTernary.java +++ b/src/main/java/io/github/syst3ms/skriptparser/expressions/ExprTernary.java @@ -20,7 +20,7 @@ public class ExprTernary implements Expression { "%objects% if %=boolean%[,] (otherwise|else) %objects%", "%=boolean% ? %objects% \\: %objects%") .name("Ternary") - .description("Returns the getFirst object if the boolean is true, otherwise the getSecond object.") + .description("Returns the first object if the boolean is true, otherwise the second object.") .since("1.0.0") .register(); } diff --git a/src/main/java/io/github/syst3ms/skriptparser/file/FileParser.java b/src/main/java/io/github/syst3ms/skriptparser/file/FileParser.java index b7b585cc5..6e709ba2b 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/file/FileParser.java +++ b/src/main/java/io/github/syst3ms/skriptparser/file/FileParser.java @@ -22,7 +22,7 @@ public class FileParser { * * @param fileName the name of the file the lines belong to * @param lines the list of lines to parse - * @param expectedIndentation the indentation level the getFirst line is expected to be at + * @param expectedIndentation the indentation level the first line is expected to be at * @param lastLine a parameter that keeps track of the line count throughout recursive calls of this method when * parsing sections * @param logger the logger diff --git a/src/main/java/io/github/syst3ms/skriptparser/lang/CodeSection.java b/src/main/java/io/github/syst3ms/skriptparser/lang/CodeSection.java index dce182ecf..94c0807b3 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/lang/CodeSection.java +++ b/src/main/java/io/github/syst3ms/skriptparser/lang/CodeSection.java @@ -90,7 +90,7 @@ public final void setItems(List items) { } /** - * @return the getFirst item of this section, or the item after the section if it's empty, or {@code null} if there is + * @return the first item of this section, or the item after the section if it's empty, or {@code null} if there is * no item after this section, in the latter case */ public final Optional getFirst() { diff --git a/src/main/java/io/github/syst3ms/skriptparser/lang/Statement.java b/src/main/java/io/github/syst3ms/skriptparser/lang/Statement.java index c73e26d33..740b2a370 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/lang/Statement.java +++ b/src/main/java/io/github/syst3ms/skriptparser/lang/Statement.java @@ -13,6 +13,7 @@ */ public abstract class Statement implements SyntaxElement { public static Consumer illegalStateRunnable; + public static Consumer exceptionHandler; @Nullable protected CodeSection parent; @Nullable @@ -22,11 +23,15 @@ public static void setIllegalStateHandler(Consumer consum Statement.illegalStateRunnable = consumer; } + public static void setExceptionHandler(Consumer consumer) { + Statement.exceptionHandler = consumer; + } + /** * Runs all code starting at a given point sequentially. * Do note this will not clear local variables after running. * - * @param start the Statement the method should getFirst run + * @param start the Statement the method should first run * @param context the context * @return {@code true} if the code ran normally, and {@code false} if any exception occurred */ @@ -48,8 +53,12 @@ public static boolean runAll(Statement start, TriggerContext context) { } return false; } catch (Exception e) { + if (exceptionHandler != null) { + exceptionHandler.accept(e); + } System.err.println("An exception occurred. Stack trace:"); e.printStackTrace(); + } return false; } diff --git a/src/main/java/io/github/syst3ms/skriptparser/lang/TriggerMap.java b/src/main/java/io/github/syst3ms/skriptparser/lang/TriggerMap.java index c06047eb1..e3f6b1bb1 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/lang/TriggerMap.java +++ b/src/main/java/io/github/syst3ms/skriptparser/lang/TriggerMap.java @@ -77,8 +77,11 @@ public static List getTriggersByContext(Clas * @param Trigger context type */ public static void callTriggersByContext(T context) { - getTriggersByContext(context.getClass()).forEach(t -> Statement.runAll(t, context)); - Variables.clearLocalVariables(context); + getTriggersByContext(context.getClass()).forEach(t -> { + Statement.runAll(t, context); + Variables.clearLocalVariables(context); + }); + } } diff --git a/src/main/java/io/github/syst3ms/skriptparser/lang/Variable.java b/src/main/java/io/github/syst3ms/skriptparser/lang/Variable.java index b5d0974f6..1a4b68fb8 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/lang/Variable.java +++ b/src/main/java/io/github/syst3ms/skriptparser/lang/Variable.java @@ -29,7 +29,7 @@ /** * A reference to a variable, whose value is only known at runtime. It can be local to the event, meaning it isn't - * defined outside of the event it was getFirst defined in. It can also be a list of multiple values. It can also be both. + * defined outside of the event it was first defined in. It can also be a list of multiple values. It can also be both. * * @param the common supertype of the possibly multiple values of the variable */ diff --git a/src/main/java/io/github/syst3ms/skriptparser/lang/VariableString.java b/src/main/java/io/github/syst3ms/skriptparser/lang/VariableString.java index 4c2072de3..a6dcadd13 100644 --- a/src/main/java/io/github/syst3ms/skriptparser/lang/VariableString.java +++ b/src/main/java/io/github/syst3ms/skriptparser/lang/VariableString.java @@ -8,6 +8,7 @@ import io.github.syst3ms.skriptparser.registration.tags.Tag; import io.github.syst3ms.skriptparser.registration.tags.TagManager; import io.github.syst3ms.skriptparser.types.TypeManager; +import io.github.syst3ms.skriptparser.types.TypeManager.StringMode; import io.github.syst3ms.skriptparser.util.CollectionUtils; import io.github.syst3ms.skriptparser.util.StringUtils; import org.jetbrains.annotations.Contract; @@ -27,10 +28,12 @@ public class VariableString extends TaggedExpression { */ private final Object[] data; private final boolean simple; + private final StringMode stringMode; - private VariableString(Object[] data) { + private VariableString(Object[] data, StringMode stringMode) { this.data = data; this.simple = data.length == 1 && data[0] instanceof String; + this.stringMode = stringMode; } /** @@ -41,7 +44,7 @@ private VariableString(Object[] data) { * @return {@code null} if either: *