mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2025-01-21 21:31:40 +01:00
Remove server version checking
This commit is contained in:
parent
1ad63d1a56
commit
cbda4e02a2
@ -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;
|
||||
}
|
||||
}
|
@ -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.
|
||||
*
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user