Skip to content

Commit 7f61018

Browse files
authored
Make function parameters respect the case-insensitive-variables setting. (#6388)
* Update Parameter.java * Update Parameter.java
1 parent ba63892 commit 7f61018

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/java/ch/njol/skript/lang/function/Parameter.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package ch.njol.skript.lang.function;
2020

2121
import ch.njol.skript.Skript;
22+
import ch.njol.skript.SkriptConfig;
2223
import ch.njol.skript.classes.ClassInfo;
2324
import ch.njol.skript.lang.Expression;
2425
import ch.njol.skript.lang.ParseContext;
@@ -45,8 +46,9 @@ public final class Parameter<T> {
4546

4647
/**
4748
* Name of this parameter. Will be used as name for the local variable
48-
* that contains value of it inside function. This is always in lower case;
49-
* variable names are case-insensitive.
49+
* that contains value of it inside function.
50+
* If {@link SkriptConfig#caseInsensitiveVariables} is {@code true},
51+
* then the valid variable names may not necessarily match this string in casing.
5052
*/
5153
final String name;
5254

@@ -69,7 +71,7 @@ public final class Parameter<T> {
6971

7072
@SuppressWarnings("null")
7173
public Parameter(String name, ClassInfo<T> type, boolean single, @Nullable Expression<? extends T> def) {
72-
this.name = name != null ? name.toLowerCase(Locale.ENGLISH) : null;
74+
this.name = name;
7375
this.type = type;
7476
this.def = def;
7577
this.single = single;
@@ -119,6 +121,7 @@ public static <T> Parameter<T> newInstance(String name, ClassInfo<T> type, boole
119121
@Nullable
120122
public static List<Parameter<?>> parse(String args) {
121123
List<Parameter<?>> params = new ArrayList<>();
124+
boolean caseInsensitive = SkriptConfig.caseInsensitiveVariables.value();
122125
int j = 0;
123126
for (int i = 0; i <= args.length(); i = SkriptParser.next(args, i, ParseContext.DEFAULT)) {
124127
if (i == -1) {
@@ -138,8 +141,12 @@ public static List<Parameter<?>> parse(String args) {
138141
return null;
139142
}
140143
String paramName = "" + n.group(1);
144+
// for comparing without affecting the original name, in case the config option for case insensitivity changes.
145+
String lowerParamName = paramName.toLowerCase(Locale.ENGLISH);
141146
for (Parameter<?> p : params) {
142-
if (p.name.toLowerCase(Locale.ENGLISH).equals(paramName.toLowerCase(Locale.ENGLISH))) {
147+
// only force lowercase if we don't care about case in variables
148+
String otherName = caseInsensitive ? p.name.toLowerCase(Locale.ENGLISH) : p.name;
149+
if (otherName.equals(caseInsensitive ? lowerParamName : paramName)) {
143150
Skript.error("Each argument's name must be unique, but the name '" + paramName + "' occurs at least twice.");
144151
return null;
145152
}

0 commit comments

Comments
 (0)