Plex-FAWE/worldedit-core/src/main/java/com/fastasyncworldedit/core/FaweVersion.java
dordsor21 8c0195970b
Add and apply .editorconfig from P2 (#1195)
* Consistenty use javax annotations.
 - Unfortunately jetbrains annotations seem to be exposed transitively via core somewhere, but with the correct IDE settings, annotations can be defaulted to javax
 - Cleaning up of import order in #1195
 - Must be merged before #1195

* Add and apply .editorconfig from P2
 - Does not rearrange entries

* Address some comments

* add back some javadoc comments

* Address final comments

Co-authored-by: NotMyFault <mc.cache@web.de>
2021-07-24 16:34:05 +01:00

60 lines
1.7 KiB
Java

package com.fastasyncworldedit.core;
/**
* An internal FAWE class not meant for public use.
**/
public class FaweVersion {
public final int year;
public final int month;
public final int day;
public final int hash;
public final int build;
public FaweVersion(int year, int month, int day, int hash, int build) {
this.year = year;
this.month = month;
this.day = day;
this.hash = hash;
this.build = build;
}
public FaweVersion(String version, String commit, String date) {
String[] split = version.substring(version.indexOf('=') + 1).split("-");
int build = 0;
try {
build = Integer.parseInt(split[1]);
} catch (NumberFormatException ignored) {
}
this.build = build;
this.hash = Integer.parseInt(commit.substring(commit.indexOf('=') + 1), 16);
String[] split1 = date.substring(date.indexOf('=') + 1).split("\\.");
this.year = Integer.parseInt(split1[0]);
this.month = Integer.parseInt(split1[1]);
this.day = Integer.parseInt(split1[2]);
}
public static FaweVersion tryParse(String version, String commit, String date) {
try {
return new FaweVersion(version, commit, date);
} catch (Exception exception) {
exception.printStackTrace();
return new FaweVersion(0, 0, 0, 0, 0);
}
}
@Override
public String toString() {
if (hash == 0 && build == 0) {
return "FastAsyncWorldEdit-1.17-NoVer-SNAPSHOT";
} else {
return "FastAsyncWorldEdit-1.17" + build;
}
}
public boolean isNewer(FaweVersion other) {
return other.build < this.build;
}
}