2020-04-16 04:52:39 +02:00
|
|
|
/*
|
2022-06-15 20:17:17 +02:00
|
|
|
* PlotSquared, a land and world management plugin for Minecraft.
|
|
|
|
* Copyright (C) IntellectualSites <https://intellectualsites.com>
|
|
|
|
* Copyright (C) IntellectualSites team and contributors
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2020-04-16 04:52:39 +02:00
|
|
|
*
|
2022-06-15 20:17:17 +02:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-04-16 04:52:39 +02:00
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core;
|
2017-08-09 07:04:59 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
|
|
|
|
|
|
public final class PlotVersion {
|
|
|
|
|
2020-04-30 11:17:19 +02:00
|
|
|
public final int year, month, day, hash;
|
|
|
|
public final String versionString;
|
|
|
|
public final int[] version;
|
2020-05-01 16:53:40 +02:00
|
|
|
public final String suffix;
|
2017-08-09 07:04:59 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public PlotVersion(
|
|
|
|
final int year,
|
|
|
|
final int month,
|
|
|
|
final int day,
|
|
|
|
final int hash,
|
|
|
|
final String rawVersion
|
|
|
|
) {
|
|
|
|
String versionString = rawVersion;
|
2020-02-20 20:08:25 +01:00
|
|
|
this.year = year;
|
|
|
|
this.month = month;
|
|
|
|
this.day = day;
|
|
|
|
this.hash = hash;
|
2020-05-01 16:53:40 +02:00
|
|
|
int dash = versionString.indexOf('-');
|
|
|
|
if (dash != -1) {
|
|
|
|
suffix = versionString.substring(dash);
|
|
|
|
versionString = versionString.substring(0, dash);
|
|
|
|
} else {
|
|
|
|
suffix = "";
|
|
|
|
}
|
2020-04-30 11:17:19 +02:00
|
|
|
this.versionString = versionString.substring(versionString.indexOf('=') + 1);
|
|
|
|
version = new int[3];
|
|
|
|
String[] verArray = versionString.substring(versionString.indexOf('=') + 1).split("\\.");
|
|
|
|
version[0] = verArray.length > 0 ? Integer.parseInt(verArray[0]) : 0;
|
|
|
|
version[1] = verArray.length > 1 ? Integer.parseInt(verArray[1]) : 0;
|
|
|
|
version[2] = verArray.length > 2 ? Integer.parseInt(verArray[2]) : 0;
|
2020-02-20 20:08:25 +01:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public PlotVersion(
|
|
|
|
final String rawVersion,
|
|
|
|
final String commit,
|
|
|
|
final String date
|
|
|
|
) {
|
|
|
|
String versionString = rawVersion;
|
2020-05-01 16:53:40 +02:00
|
|
|
int dash = versionString.indexOf('-');
|
|
|
|
if (dash != -1) {
|
|
|
|
suffix = versionString.substring(dash);
|
|
|
|
versionString = versionString.substring(0, dash);
|
|
|
|
} else {
|
|
|
|
suffix = "";
|
|
|
|
}
|
2020-04-30 11:17:19 +02:00
|
|
|
this.versionString = versionString.substring(versionString.indexOf('=') + 1);
|
|
|
|
version = new int[3];
|
|
|
|
String[] verArray = this.versionString.split("\\.");
|
|
|
|
version[0] = verArray.length > 0 ? Integer.parseInt(verArray[0]) : 0;
|
|
|
|
version[1] = verArray.length > 1 ? Integer.parseInt(verArray[1]) : 0;
|
|
|
|
version[2] = verArray.length > 2 ? Integer.parseInt(verArray[2]) : 0;
|
|
|
|
|
2019-01-03 18:32:21 +01:00
|
|
|
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]);
|
2017-08-09 07:04:59 +02:00
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public static @NonNull PlotVersion tryParse(
|
|
|
|
final @NonNull String versionString,
|
|
|
|
final @NonNull String commit,
|
|
|
|
final @NonNull String date
|
|
|
|
) {
|
2020-02-20 20:08:25 +01:00
|
|
|
try {
|
2020-04-30 11:17:19 +02:00
|
|
|
return new PlotVersion(versionString, commit, date);
|
2020-02-20 20:08:25 +01:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
2020-04-30 11:17:19 +02:00
|
|
|
return new PlotVersion(0, 0, 0, 0, "0");
|
2020-02-20 20:08:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
public @NonNull String versionString() {
|
2020-04-30 11:17:19 +02:00
|
|
|
if (hash == 0 && versionString == null) {
|
2020-02-20 20:08:25 +01:00
|
|
|
return "NoVer-SNAPSHOT";
|
|
|
|
} else {
|
2020-05-01 16:56:35 +02:00
|
|
|
return versionString + suffix;
|
2020-02-20 20:08:25 +01:00
|
|
|
}
|
|
|
|
}
|
2020-04-30 11:17:19 +02:00
|
|
|
|
2021-01-09 22:28:41 +01:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
2020-04-30 11:17:19 +02:00
|
|
|
if (hash == 0 && versionString == null) {
|
2019-05-05 12:58:45 +02:00
|
|
|
return "PlotSquared-NoVer-SNAPSHOT";
|
2018-04-07 20:52:19 +02:00
|
|
|
} else {
|
2020-05-01 16:53:40 +02:00
|
|
|
return "PlotSquared-" + versionString + suffix;
|
2020-04-30 11:17:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare a given version string with the one cached here.
|
|
|
|
*
|
|
|
|
* @param versionString the version to compare
|
2022-01-24 21:41:54 +01:00
|
|
|
* @return {@code true} if the given version is a "later" version
|
2020-04-30 11:17:19 +02:00
|
|
|
*/
|
2021-01-09 22:28:41 +01:00
|
|
|
public boolean isLaterVersion(final @NonNull String versionString) {
|
2020-05-01 16:53:40 +02:00
|
|
|
int dash = versionString.indexOf('-');
|
|
|
|
String[] verArray =
|
2021-01-09 22:28:41 +01:00
|
|
|
versionString.substring(0, dash == -1 ? versionString.length() : dash).split("\\.");
|
2020-04-30 11:17:19 +02:00
|
|
|
int one = Integer.parseInt(verArray[0]);
|
|
|
|
int two = Integer.parseInt(verArray[1]);
|
|
|
|
int three = Integer.parseInt(verArray[2]);
|
|
|
|
if (one > version[0]) {
|
|
|
|
return true;
|
|
|
|
} else if (one == version[0] && two > version[1]) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return one == version[0] && two == version[1] && three > version[2];
|
2018-04-07 20:52:19 +02:00
|
|
|
}
|
2017-08-09 07:04:59 +02:00
|
|
|
}
|
2020-04-30 11:17:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare a given version with the one cached here.
|
|
|
|
*
|
|
|
|
* @param verArray the version to compare
|
2022-01-24 21:41:54 +01:00
|
|
|
* @return {@code true} if the given version is a "later" version
|
2020-04-30 11:17:19 +02:00
|
|
|
*/
|
|
|
|
public boolean isLaterVersion(int[] verArray) {
|
|
|
|
if (verArray[0] > version[0]) {
|
|
|
|
return true;
|
|
|
|
} else if (verArray[0] == version[0] && verArray[1] > version[1]) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return verArray[0] == version[0] && verArray[1] == version[1]
|
2021-01-09 22:28:41 +01:00
|
|
|
&& verArray[2] > version[2];
|
2020-04-30 11:17:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 20:52:19 +02:00
|
|
|
}
|