Skip to content

Commit

Permalink
Auto Generate Missing Aliases (#7073)
Browse files Browse the repository at this point in the history
* black magic

* change generation format

* change generation format

---------

Co-authored-by: Moderocky <admin@moderocky.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 13, 2024
1 parent b36ca00 commit 0d19871
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/ch/njol/skript/util/EnumUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* @see ch.njol.skript.classes.EnumClassInfo
*/
public final class EnumUtils<E extends Enum<E>> {

private final Class<E> enumClass;
private final String languageNode;

Expand All @@ -53,7 +53,7 @@ public EnumUtils(Class<E> enumClass, String languageNode) {

Language.addListener(this::refresh);
}

/**
* Refreshes the representation of this Enum based on the currently stored language entries.
*/
Expand All @@ -69,7 +69,10 @@ void refresh() {
for (String option : options) {
option = option.toLowerCase(Locale.ENGLISH);
if (options.length == 1 && option.equals(key.toLowerCase(Locale.ENGLISH))) {
Skript.debug("Missing lang enum constant for '" + key + "'");
String[] splitKey = key.split("\\.");
String newKey = splitKey[1].replace('_', ' ').toLowerCase(Locale.ENGLISH) + " " + splitKey[0];
parseMap.put(newKey, constant);
Skript.debug("Missing lang enum constant for '" + key + "'. Using '" + newKey + "' for now.");
continue;
}

Expand Down Expand Up @@ -118,5 +121,5 @@ public String toString(E enumerator, int flags) {
public String getAllNames() {
return StringUtils.join(parseMap.keySet(), ", ");
}

}

0 comments on commit 0d19871

Please sign in to comment.