generated from srnyx/plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MinecraftVersion.java
51 lines (47 loc) · 1.41 KB
/
MinecraftVersion.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package xyz.srnyx.annoyingapi;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a Minecraft version
*/
public class MinecraftVersion {
/**
* The version string
*/
@NotNull public final String version;
/**
* The major version
*/
public final int major;
/**
* The minor version
*/
public final int minor;
/**
* The patch version
*/
@Nullable public final Integer patch;
/**
* The version as a unique integer
*/
public final int value;
/**
* Creates a new {@link MinecraftVersion}
*
* @param version {@link #version}
*
* @throws IllegalArgumentException if the version does not match the format {@code MAJOR.MINOR} or {@code MAJOR.MINOR.PATCH}
*/
public MinecraftVersion(@NotNull String version) {
this.version = version;
final String[] split = version.split("\\.");
try {
this.major = Integer.parseInt(split[0]);
this.minor = Integer.parseInt(split[1]);
this.patch = split.length > 2 ? Integer.parseInt(split[2]) : null;
} catch (final IndexOutOfBoundsException | NumberFormatException e) {
throw new IllegalArgumentException("Invalid version: " + version, e);
}
this.value = major * 100 + minor * 10 + (patch == null ? 0 : patch);
}
}