Updated version code
Changed: - Cleaned up the server protocol checker - Simplified supported game versions in the build script
This commit is contained in:
parent
e0f776760f
commit
017869c38a
|
@ -8,11 +8,11 @@ build-logic/build
|
|||
|
||||
core/build
|
||||
|
||||
platforms/paper/build
|
||||
platforms/paper/run/*
|
||||
platforms/spigot/build
|
||||
platforms/spigot/run/*
|
||||
|
||||
!platforms/paper/run/eula.txt
|
||||
!platforms/paper/run/bukkit.yml
|
||||
!platforms/paper/run/spigot.yml
|
||||
!platforms/paper/run/server.properties
|
||||
!platforms/paper/run/config
|
||||
!platforms/spigot/run/eula.txt
|
||||
!platforms/spigot/run/bukkit.yml
|
||||
!platforms/spigot/run/spigot.yml
|
||||
!platforms/spigot/run/server.properties
|
||||
!platforms/spigot/run/config
|
|
@ -79,15 +79,18 @@ tasks {
|
|||
|
||||
gameVersions.addAll(
|
||||
listOf(
|
||||
"1.8",
|
||||
"1.9",
|
||||
"1.10",
|
||||
"1.11",
|
||||
"1.12",
|
||||
"1.13",
|
||||
"1.14",
|
||||
"1.15",
|
||||
"1.16",
|
||||
"1.17",
|
||||
"1.17.1",
|
||||
"1.18",
|
||||
"1.18.1",
|
||||
"1.18.2",
|
||||
"1.19",
|
||||
"1.19.1",
|
||||
"1.19.2",
|
||||
"1.19.3"
|
||||
"1.19"
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#Minecraft server properties
|
||||
#Thu Jan 19 18:20:50 EST 2023
|
||||
#Sat Feb 18 21:51:37 EST 2023
|
||||
enable-jmx-monitoring=false
|
||||
rcon.port=25575
|
||||
level-seed=
|
||||
|
@ -56,4 +56,4 @@ spawn-monsters=true
|
|||
enforce-whitelist=false
|
||||
spawn-protection=0
|
||||
resource-pack-sha1=
|
||||
max-world-size=29999984
|
||||
max-world-size=29999984
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
package com.badbones69.crazyauctions.api.enums;
|
||||
|
||||
import com.badbones69.crazyauctions.CrazyAuctions;
|
||||
|
||||
/**
|
||||
* @author Badbones69
|
||||
*/
|
||||
public enum ServerProtocol {
|
||||
|
||||
TOO_OLD(1),
|
||||
v1_8_R1(181), v1_8_R2(182), v1_8_R3(183),
|
||||
v1_9_R1(191), v1_9_R2(192),
|
||||
v1_10_R1(1101),
|
||||
v1_11_R1(1111),
|
||||
v1_12_R1(1121),
|
||||
v1_13_R2(1132),
|
||||
v1_14_R1(1141),
|
||||
v1_15_R1(1151),
|
||||
v1_16_R1(1161), v1_16_R2(1162),v1_16_R3(1163),
|
||||
v1_17_R1(1171),
|
||||
v1_18_R2(1182),
|
||||
v1_19_R1(1191),
|
||||
v1_19_R2(1192),
|
||||
v1_19_R3(1192),
|
||||
TOO_NEW(-2);
|
||||
|
||||
private static ServerProtocol currentProtocol;
|
||||
private static ServerProtocol latest;
|
||||
|
||||
private static final CrazyAuctions plugin = CrazyAuctions.getPlugin();
|
||||
|
||||
private final int versionProtocol;
|
||||
|
||||
ServerProtocol(int versionProtocol) {
|
||||
this.versionProtocol = versionProtocol;
|
||||
}
|
||||
|
||||
public static ServerProtocol getCurrentProtocol() {
|
||||
|
||||
String serVer = plugin.getServer().getClass().getPackage().getName();
|
||||
|
||||
int serProt = Integer.parseInt(
|
||||
serVer.substring(
|
||||
serVer.lastIndexOf('.') + 1
|
||||
).replace("_", "").replace("R", "").replace("v", "")
|
||||
);
|
||||
|
||||
for (ServerProtocol protocol : values()) {
|
||||
if (protocol.versionProtocol == serProt) {
|
||||
currentProtocol = protocol;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentProtocol == null) currentProtocol = ServerProtocol.TOO_NEW;
|
||||
|
||||
return currentProtocol;
|
||||
}
|
||||
|
||||
public static boolean isLegacy() {
|
||||
return isOlder(ServerProtocol.v1_13_R2);
|
||||
}
|
||||
|
||||
public static ServerProtocol getLatestProtocol() {
|
||||
|
||||
if (latest != null) return latest;
|
||||
|
||||
ServerProtocol old = ServerProtocol.TOO_OLD;
|
||||
|
||||
for (ServerProtocol protocol : values()) {
|
||||
if (protocol.compare(old) == 1) old = protocol;
|
||||
}
|
||||
|
||||
return old;
|
||||
}
|
||||
|
||||
public static boolean isAtLeast(ServerProtocol protocol) {
|
||||
if (currentProtocol == null) getCurrentProtocol();
|
||||
int proto = currentProtocol.versionProtocol;
|
||||
return proto >= protocol.versionProtocol || proto == -2;
|
||||
}
|
||||
|
||||
public static boolean isNewer(ServerProtocol protocol) {
|
||||
if (currentProtocol == null) getCurrentProtocol();
|
||||
return currentProtocol.versionProtocol > protocol.versionProtocol || currentProtocol.versionProtocol == -2;
|
||||
}
|
||||
|
||||
public static boolean isSame(ServerProtocol protocol) {
|
||||
if (currentProtocol == null) getCurrentProtocol();
|
||||
return currentProtocol.versionProtocol == protocol.versionProtocol;
|
||||
}
|
||||
|
||||
public static boolean isOlder(ServerProtocol protocol) {
|
||||
if (currentProtocol == null) getCurrentProtocol();
|
||||
int proto = currentProtocol.versionProtocol;
|
||||
return proto < protocol.versionProtocol || proto == -1;
|
||||
}
|
||||
|
||||
public int compare(ServerProtocol protocol) {
|
||||
int result = -1;
|
||||
int current = versionProtocol;
|
||||
int check = protocol.versionProtocol;
|
||||
|
||||
if (current > check || check == -2) {
|
||||
result = 1;
|
||||
} else if (current == check) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package com.badbones69.crazyauctions.api.enums;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import java.util.Arrays;
|
||||
|
||||
public enum ServerVersion {
|
||||
|
||||
v1_8(18),
|
||||
v1_9(19),
|
||||
v1_10(110),
|
||||
v1_11(111),
|
||||
v1_12(112),
|
||||
v1_13(113),
|
||||
v1_14(114),
|
||||
v1_15(115),
|
||||
v1_16(116),
|
||||
v1_17(117),
|
||||
v1_18(118),
|
||||
v1_19(119),
|
||||
|
||||
UNKNOWN(-1);
|
||||
|
||||
private static final ServerVersion currentVersion;
|
||||
private static final String bukkitVersion;
|
||||
private static final boolean legacy;
|
||||
|
||||
static {
|
||||
bukkitVersion = Bukkit.getBukkitVersion().split("-")[0];
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
String[] sections = version.split("_");
|
||||
currentVersion = ServerVersion.getSafe(sections[0] + "_" + sections[1]);
|
||||
legacy = isLessThan(ServerVersion.v1_13);
|
||||
}
|
||||
|
||||
private final int code;
|
||||
|
||||
ServerVersion(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public static ServerVersion getSafe(String value) {
|
||||
try {
|
||||
return valueOf(value);
|
||||
} catch (IllegalArgumentException error) {
|
||||
return UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isAtLeast(ServerVersion serverVersion) {
|
||||
return isValidVersion(serverVersion) && currentVersion.code >= serverVersion.code;
|
||||
}
|
||||
|
||||
public static boolean isHigherThan(ServerVersion serverVersion) {
|
||||
return isValidVersion(serverVersion) && currentVersion.code > serverVersion.code;
|
||||
}
|
||||
|
||||
public static boolean isLessThan(ServerVersion serverVersion) {
|
||||
return isValidVersion(serverVersion) && currentVersion.code < serverVersion.code;
|
||||
}
|
||||
|
||||
public static boolean isEquals(ServerVersion serverVersion) {
|
||||
return isValidVersion(serverVersion) && currentVersion.code == serverVersion.code;
|
||||
}
|
||||
|
||||
public static boolean isLegacy() {
|
||||
return legacy;
|
||||
}
|
||||
|
||||
public static String getBukkitVersion() {
|
||||
return bukkitVersion;
|
||||
}
|
||||
|
||||
public static ServerVersion[] getByOrder() {
|
||||
ServerVersion[] versions = Arrays.copyOfRange(values(), 0, currentVersion.ordinal() + 1);
|
||||
|
||||
for (int i = 0; i < versions.length / 2; i++) {
|
||||
ServerVersion temp = versions[i];
|
||||
versions[i] = versions[versions.length - i - 1];
|
||||
versions[versions.length - i - 1] = temp;
|
||||
}
|
||||
|
||||
return versions;
|
||||
}
|
||||
|
||||
private static boolean isValidVersion(ServerVersion compareVersion) {
|
||||
return currentVersion != UNKNOWN && compareVersion != UNKNOWN;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package com.badbones69.crazyauctions.utils;
|
||||
|
||||
import com.badbones69.crazyauctions.api.enums.ServerProtocol;
|
||||
import com.badbones69.crazyauctions.api.enums.ServerVersion;
|
||||
import org.bukkit.Material;
|
||||
|
||||
public class ItemUtils {
|
||||
|
||||
public static Material getMaterial(String newMaterial, String oldMaterial) {
|
||||
return Material.matchMaterial(ServerProtocol.isNewer(ServerProtocol.v1_12_R1) ? newMaterial : oldMaterial);
|
||||
return Material.matchMaterial(ServerVersion.isAtLeast(ServerVersion.v1_12) ? newMaterial : oldMaterial);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.badbones69.crazyauctions.utils.utilities.misc;
|
||||
|
||||
import com.badbones69.crazyauctions.api.enums.ServerProtocol;
|
||||
import com.badbones69.crazyauctions.api.enums.ServerVersion;
|
||||
import com.badbones69.crazyauctions.configs.Config;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import java.util.List;
|
||||
|
@ -11,7 +12,7 @@ public class ColorUtils {
|
|||
private static final Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F\\d]{6}");
|
||||
|
||||
public static String color(String message) {
|
||||
if (ServerProtocol.isNewer(ServerProtocol.v1_15_R1)) {
|
||||
if (ServerVersion.isAtLeast(ServerVersion.v1_15)) {
|
||||
Matcher matcher = HEX_PATTERN.matcher(message);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
|
@ -83,8 +84,7 @@ public class ColorUtils {
|
|||
}
|
||||
|
||||
public static String getPrefix(String string) {
|
||||
return "Fuck Off";
|
||||
//return color(Files.CONFIG.getFile().getString("Settings.Prefix") + string);
|
||||
return Config.PREFIX;
|
||||
}
|
||||
|
||||
public static String getPrefix() {
|
||||
|
|
Loading…
Reference in New Issue