Skip to content

Commit e60c773

Browse files
committed
OS.byName to search for an OS without just the key
1 parent 73bddf7 commit e60c773

File tree

1 file changed

+16
-5
lines changed
  • json-data-utils/src/main/java/net/minecraftforge/util/data

1 file changed

+16
-5
lines changed

json-data-utils/src/main/java/net/minecraftforge/util/data/OS.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
* Enum representing the operating system.
1818
*/
1919
public enum OS {
20-
AIX ("aix", "aix"),
20+
AIX ("aix"),
2121
/** @apiNote When working with Minecraft natives, this will be treated as {@link #LINUX}. */
2222
ALPINE ("apline_linux", "alpine"),
23-
LINUX ("linux", "linux", "unix"),
23+
LINUX ("linux", "unix"),
2424
/** @apiNote When working with Minecraft natives, this will be treated as {@link #LINUX}. */
2525
MUSL ("linux_musl", "musl"),
2626
/** @apiNote When working with Minecraft natives, this is primarily referred to as {@code osx}. */
2727
MACOS ("macos", "mac", "osx", "darwin"),
28-
QNX ("qnx", "qnx"),
28+
QNX ("qnx"),
2929
SOLARIS("solaris", "sunos"),
3030
WINDOWS("windows", "win"),
3131
UNKNOWN("unknown");
@@ -37,8 +37,8 @@ public enum OS {
3737
private final String key;
3838
private final String[] names;
3939

40-
private OS(String key, String... names) {
41-
this.key = key;
40+
OS(String... names) {
41+
this.key = names[0];
4242
this.names = names;
4343
}
4444

@@ -66,6 +66,17 @@ public String key() {
6666
return null;
6767
}
6868

69+
public static @Nullable OS byName(String name) {
70+
for (OS value : $values) {
71+
for (String n : value.names) {
72+
if (n.equals(name))
73+
return value;
74+
}
75+
}
76+
77+
return null;
78+
}
79+
6980
/**
7081
* Returns the mandatory file extension for executables on this OS.
7182
*

0 commit comments

Comments
 (0)