diff --git a/src/main/java/ch/njol/skript/classes/ClassInfo.java b/src/main/java/ch/njol/skript/classes/ClassInfo.java
index 2ba7776f61d..56b24d4dceb 100644
--- a/src/main/java/ch/njol/skript/classes/ClassInfo.java
+++ b/src/main/java/ch/njol/skript/classes/ClassInfo.java
@@ -1,21 +1,3 @@
-/**
- * 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 ch.njol.skript.classes;
import ch.njol.skript.SkriptAPIException;
@@ -29,6 +11,8 @@
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import org.skriptlang.skript.lang.arithmetic.Arithmetics;
+import org.skriptlang.skript.lang.arithmetic.Operator;
import java.util.Arrays;
import java.util.HashSet;
@@ -37,8 +21,6 @@
import java.util.function.Supplier;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import org.skriptlang.skript.lang.arithmetic.Operator;
-import org.skriptlang.skript.lang.arithmetic.Arithmetics;
/**
* @author Peter Güttinger
diff --git a/src/main/java/ch/njol/skript/classes/EnumClassInfo.java b/src/main/java/ch/njol/skript/classes/EnumClassInfo.java
index e644d967d19..6bd18633cf5 100644
--- a/src/main/java/ch/njol/skript/classes/EnumClassInfo.java
+++ b/src/main/java/ch/njol/skript/classes/EnumClassInfo.java
@@ -1,27 +1,12 @@
-/**
- * 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 ch.njol.skript.classes;
import ch.njol.skript.expressions.base.EventValueExpression;
import ch.njol.skript.lang.DefaultExpression;
import ch.njol.skript.lang.ParseContext;
import ch.njol.skript.util.EnumUtils;
+import ch.njol.skript.util.StringMode;
+import ch.njol.util.coll.iterator.ArrayIterator;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -33,41 +18,41 @@
public class EnumClassInfo> extends ClassInfo {
/**
- * @param c The class
+ * @param enumClass The class
* @param codeName The name used in patterns
* @param languageNode The language node of the type
*/
- public EnumClassInfo(Class c, String codeName, String languageNode) {
- this(c, codeName, languageNode, new EventValueExpression<>(c));
+ public EnumClassInfo(Class enumClass, String codeName, String languageNode) {
+ this(enumClass, codeName, languageNode, new EventValueExpression<>(enumClass));
}
/**
- * @param c The class
+ * @param enumClass The class
* @param codeName The name used in patterns
* @param languageNode The language node of the type
* @param defaultExpression The default expression of the type
*/
- public EnumClassInfo(Class c, String codeName, String languageNode, DefaultExpression defaultExpression) {
- super(c, codeName);
- EnumUtils enumUtils = new EnumUtils<>(c, languageNode);
+ public EnumClassInfo(Class enumClass, String codeName, String languageNode, DefaultExpression defaultExpression) {
+ super(enumClass, codeName);
+ EnumUtils enumUtils = new EnumUtils<>(enumClass, languageNode);
usage(enumUtils.getAllNames())
- .serializer(new EnumSerializer<>(c))
+ .serializer(new EnumSerializer<>(enumClass))
.defaultExpression(defaultExpression)
+ .supplier(() -> new ArrayIterator<>(enumClass.getEnumConstants()))
.parser(new Parser() {
@Override
- @Nullable
- public T parse(String s, ParseContext context) {
- return enumUtils.parse(s);
+ public @Nullable T parse(String input, ParseContext context) {
+ return enumUtils.parse(input);
}
@Override
- public String toString(T o, int flags) {
- return enumUtils.toString(o, flags);
+ public @NotNull String toString(T constant, int flags) {
+ return enumUtils.toString(constant, StringMode.MESSAGE);
}
@Override
- public String toVariableNameString(T o) {
- return o.name();
+ public @NotNull String toVariableNameString(T constant) {
+ return enumUtils.toString(constant, StringMode.VARIABLE_NAME);
}
});
}
diff --git a/src/main/java/ch/njol/skript/util/EnumUtils.java b/src/main/java/ch/njol/skript/util/EnumUtils.java
index 942d7ad0a20..527db142a9a 100644
--- a/src/main/java/ch/njol/skript/util/EnumUtils.java
+++ b/src/main/java/ch/njol/skript/util/EnumUtils.java
@@ -111,6 +111,16 @@ public String toString(E enumerator, int flags) {
return s != null ? s : enumerator.name();
}
+ /**
+ * This method returns the string representation of an enumerator
+ * @param enumerator The enumerator to represent as a string
+ * @param flag not currently used
+ * @return A string representation of the enumerator
+ */
+ public String toString(E enumerator, StringMode flag) {
+ return toString(enumerator, flag.ordinal());
+ }
+
/**
* @return A comma-separated string containing a list of all names representing the enumerators.
* Note that some entries may represent the same enumerator.