Remove server version checking

This commit is contained in:
Ryder Belserion 2023-02-28 03:15:35 -05:00
parent 1ad63d1a56
commit cbda4e02a2
No known key found for this signature in database
GPG Key ID: 8FC2E6C54BBF05FE
3 changed files with 5 additions and 101 deletions

View File

@ -1,88 +0,0 @@
package us.crazycrew.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;
}
}

View File

@ -7,10 +7,6 @@ import java.util.Arrays;
public class ItemUtils {
public static Material getMaterial(String newMaterial, String oldMaterial) {
return Material.matchMaterial(ServerVersion.isAtLeast(ServerVersion.v1_12) ? newMaterial : oldMaterial);
}
/**
* Converts a string to an ItemBuilder with a placeholder for errors.
*

View File

@ -11,18 +11,14 @@ public class ColorUtils {
private static final Pattern HEX_PATTERN = Pattern.compile("#[a-fA-F\\d]{6}");
public static String color(String message) {
if (ServerVersion.isAtLeast(ServerVersion.v1_15)) {
Matcher matcher = HEX_PATTERN.matcher(message);
StringBuilder buffer = new StringBuilder();
Matcher matcher = HEX_PATTERN.matcher(message);
StringBuilder buffer = new StringBuilder();
while (matcher.find()) {
matcher.appendReplacement(buffer, ChatColor.valueOf(matcher.group()).toString());
}
return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString());
while (matcher.find()) {
matcher.appendReplacement(buffer, ChatColor.valueOf(matcher.group()).toString());
}
return ChatColor.translateAlternateColorCodes('&', message);
return ChatColor.translateAlternateColorCodes('&', matcher.appendTail(buffer).toString());
}
public static void color(List<Color> colors, String colorString) {