Arclight/arclight-api/src/main/java/io/izzel/arclight/api/ArclightVersion.java

71 lines
1.9 KiB
Java
Raw Normal View History

2020-06-02 14:32:43 +00:00
package io.izzel.arclight.api;
import java.util.Objects;
public class ArclightVersion {
2020-07-06 15:37:46 +00:00
public static final ArclightVersion v1_14 = new ArclightVersion("1.14.4", 1140, "v1_14_R1");
public static final ArclightVersion v1_15 = new ArclightVersion("1.15.2", 1152, "v1_15_R1");
2020-06-02 14:32:43 +00:00
private final String name;
private final int num;
2020-07-06 15:37:46 +00:00
private final String pkg;
2020-06-02 14:32:43 +00:00
2020-07-06 15:37:46 +00:00
public ArclightVersion(String name, int num, String pkg) {
2020-06-02 14:32:43 +00:00
this.name = name;
this.num = num;
2020-07-06 15:37:46 +00:00
this.pkg = pkg;
2020-06-02 14:32:43 +00:00
}
public String getName() {
return name;
}
2020-07-06 15:37:46 +00:00
public String packageName() {
return pkg;
}
2020-06-02 14:32:43 +00:00
@Override
public String toString() {
return "ArclightVersion{" +
"name='" + name + '\'' +
", num=" + num +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ArclightVersion that = (ArclightVersion) o;
return num == that.num &&
Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(name, num);
}
private static ArclightVersion version;
2020-07-06 15:37:46 +00:00
public static ArclightVersion current() {
if (ArclightVersion.version == null) throw new IllegalStateException("Version is not set!");
return version;
}
2020-06-02 14:32:43 +00:00
public static void setVersion(ArclightVersion version) {
if (ArclightVersion.version != null) throw new IllegalStateException("Version is already set!");
if (version == null) throw new IllegalArgumentException("Version cannot be null!");
ArclightVersion.version = version;
}
public static boolean atLeast(ArclightVersion v) {
return v.num <= version.num;
}
public static boolean lesserThan(ArclightVersion v) {
return v.num > version.num;
}
}