From 0b325c19aa2fa18a2f4fe75bb7511d0db7431eb4 Mon Sep 17 00:00:00 2001 From: "version-bump[github-action]" <41898282+version-bump[github-action]@users.noreply.github.com> Date: Fri, 12 Jul 2024 22:42:43 +0000 Subject: [PATCH 1/3] Bump version from 1.4.4 to 1.4.4-SNAPSHOT0 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 20f76bc..d837b7c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,7 +24,7 @@ dependencies { group = "me.tigerhix.lib" -version = "1.4.4" +version = "1.4.4-SNAPSHOT0" description = "scoreboard" java.sourceCompatibility = JavaVersion.VERSION_1_8 From 890795d6a816e90135a5327b210dab4960c029f5 Mon Sep 17 00:00:00 2001 From: Tigerpanzer_02 <37453987+Tigerpanzer02@users.noreply.github.com> Date: Sat, 13 Jul 2024 01:20:39 +0200 Subject: [PATCH 2/3] Changed ServerVersion as 1.20.6+ removed package nms --- .../lib/scoreboard/ScoreboardLib.java | 6 +- .../lib/scoreboard/common/EntryBuilder.java | 2 +- .../lib/scoreboard/util/ServerVersion.java | 134 ++++++++---------- 3 files changed, 65 insertions(+), 77 deletions(-) diff --git a/src/main/java/me/tigerhix/lib/scoreboard/ScoreboardLib.java b/src/main/java/me/tigerhix/lib/scoreboard/ScoreboardLib.java index c439a93..329417f 100644 --- a/src/main/java/me/tigerhix/lib/scoreboard/ScoreboardLib.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/ScoreboardLib.java @@ -29,7 +29,7 @@ public static Scoreboard createScoreboard(Player holder) { if(Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport")) { try { int version = ProtocolSupportAPI.getProtocolVersion(holder).getId(); - if(version >= 401 && ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13_R1)) { + if(version >= 401 && ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13)) { //only give player & server higher 1.12 the better scoreboard return new SimpleScoreboard(holder); } @@ -42,14 +42,14 @@ public static Scoreboard createScoreboard(Player holder) { try { ViaAPI api = Via.getAPI(); // Get the API int version = api.getPlayerVersion(holder); // Get the protocol version - if(version >= 401 && ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13_R1)) { + if(version >= 401 && ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13)) { //only give player & server higher 1.12 the better scoreboard return new SimpleScoreboard(holder); } } catch(Exception ignored) { //Not using ViaVersion 4 or unable to get ViaVersion return LegacyBoard! } - } else if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13_R1)) { + } else if(ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_13)) { return new SimpleScoreboard(holder); } return new LegacySimpleScoreboard(holder); diff --git a/src/main/java/me/tigerhix/lib/scoreboard/common/EntryBuilder.java b/src/main/java/me/tigerhix/lib/scoreboard/common/EntryBuilder.java index a91f1b1..d44f885 100755 --- a/src/main/java/me/tigerhix/lib/scoreboard/common/EntryBuilder.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/common/EntryBuilder.java @@ -49,7 +49,7 @@ public List build() { private String adapt(String entry) { // Cut off the exceeded part if needed - if (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_14_R1)) { + if (ServerVersion.Version.isCurrentEqualOrHigher(ServerVersion.Version.v1_14)) { if (entry.length() > 144) entry = entry.substring(0, 143); } else { if (entry.length() > 48) entry = entry.substring(0, 47); diff --git a/src/main/java/me/tigerhix/lib/scoreboard/util/ServerVersion.java b/src/main/java/me/tigerhix/lib/scoreboard/util/ServerVersion.java index 4340dfc..c25c260 100644 --- a/src/main/java/me/tigerhix/lib/scoreboard/util/ServerVersion.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/util/ServerVersion.java @@ -2,6 +2,9 @@ import org.bukkit.Bukkit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + public class ServerVersion { public Version getVersion() { @@ -9,121 +12,106 @@ public Version getVersion() { } public enum Version { - v0_0_R0, - v1_8_R1, - v1_8_R2, - v1_8_R3, - v1_9_R1, - v1_9_R2, - v1_10_R1, - v1_10_R2, - v1_11_R1, - v1_12_R1, - v1_13_R1, - v1_13_R2, - v1_14_R1, - v1_14_R2, - v1_15_R1, - v1_15_R2, - v1_16_R1, - v1_16_R2, - v1_16_R3, - v1_17_R1, - v1_17_R2, - v1_18_R1, - v1_18_R2, - v1_19_R1, - v1_19_R2, - v1_19_R3, - v1_20_R1, - v1_20_R2, - v1_20_R3, - v1_20_R4, - v1_20_R5, - v1_20_R6, - v1_21_R1; - - private final Integer value; - private final String shortVersion; - private final String packageVersion; - private static Version current; + v0_0_0(0, 0), + v1_8_8(8, 4), + v1_9(9, 4), + v1_10(10, 2), + v1_11(11, 0), + v1_12(12, 0), + v1_13(13, 1), + v1_14(14, 0), + v1_15(15, 0), + v1_16(16, 0), + v1_17(17, 0), + v1_18(18, 0), + v1_19(19, 0), + v1_20(20, 0), + v1_21(21, 0); - Version() { - value = Integer.valueOf(name().replaceAll("[^\\d.]", "")); - shortVersion = name().substring(0, name().length() - 3); - packageVersion = Bukkit.getServer().getClass().getPackage().getName().replace('.', ',').split(",")[3]; - } - public Integer getValue() { - return value; + private static Version current; + private final int minor; + private final int minPatch; + + Version(int minor, int minPatch) { + this.minor = minor; + this.minPatch = minPatch; } - public String getShortVersion() { - return shortVersion; + public int getMinor() { + return minor; } - public String getPackageVersion() { - return packageVersion; + public int getMinPatch() { + return minPatch; } public static Version getCurrent() { - if(current != null) + if(current != null) { return current; + } - String[] v = Bukkit.getServer().getClass().getPackage().getName().split("\\."); - String vv = v[v.length - 1]; - for(Version one : values()) { - if(one.name().equalsIgnoreCase(vv)) { - current = one; - break; + Matcher serverVersion = Pattern.compile("^(?\\d+)\\.(?\\d+)(?:\\.(?\\d+))?").matcher(Bukkit.getBukkitVersion()); + if(serverVersion.find()) { + int serverMinor = Integer.parseInt(serverVersion.group("minor")); + String patch = serverVersion.group("patch"); + int serverPatch = Integer.parseInt((patch == null || patch.isEmpty()) ? "0" : patch); + + for(Version value : values()) { + if(value.getMinor() == serverMinor && serverPatch >= value.getMinPatch()) { + current = value; + break; + } } + } else { + throw new IllegalStateException("Cannot parse server version: \"" + Bukkit.getBukkitVersion() + '"'); } - if (current == null) { // If we forgot to add new version to enum - current = Version.v0_0_R0; + if(current == null) { // Fallback + current = Version.v0_0_0; } return current; } public boolean isLower(Version version) { - return getValue() < version.getValue(); + return minor < version.getMinor(); } public boolean isHigher(Version version) { - return getValue() > version.getValue(); + return minor > version.getMinor(); } public boolean isEqual(Version version) { - return getValue().equals(version.getValue()); + return minor == version.getMinor(); } public boolean isEqualOrLower(Version version) { - return getValue() <= version.getValue(); + return minor <= version.getMinor(); } public boolean isEqualOrHigher(Version version) { - return getValue() >= version.getValue(); + return minor >= version.getMinor(); } - public static boolean isCurrentEqualOrHigher(Version v) { - return getCurrent().getValue() >= v.getValue(); + public static boolean isCurrentEqualOrHigher(Version fixedVersion) { + return getCurrent().getMinor() >= fixedVersion.getMinor(); } - public static boolean isCurrentHigher(Version v) { - return getCurrent().getValue() > v.getValue(); + public static boolean isCurrentHigher(Version fixedVersion) { + return getCurrent().getMinor() > fixedVersion.getMinor(); } - public static boolean isCurrentLower(Version v) { - return getCurrent().getValue() < v.getValue(); + public static boolean isCurrentLower(Version fixedVersion) { + return getCurrent().getMinor() < fixedVersion.getMinor(); } - public static boolean isCurrentEqualOrLower(Version v) { - return getCurrent().getValue() <= v.getValue(); + public static boolean isCurrentEqualOrLower(Version fixedVersion) { + return getCurrent().getMinor() <= fixedVersion.getMinor(); } - public static boolean isCurrentEqual(Version v) { - return getCurrent().getValue().equals(v.getValue()); + public static boolean isCurrentEqual(Version fixedVersion) { + return getCurrent().getMinor() == fixedVersion.getMinor(); } } } \ No newline at end of file From 22632a692757bd5637cae9464233c0b23af17d27 Mon Sep 17 00:00:00 2001 From: "version-bump[github-action]" <41898282+version-bump[github-action]@users.noreply.github.com> Date: Fri, 12 Jul 2024 23:21:35 +0000 Subject: [PATCH 3/3] Bump version from 1.4.4-SNAPSHOT0 to 1.4.4-SNAPSHOT1 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index d837b7c..60b91d6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,7 +24,7 @@ dependencies { group = "me.tigerhix.lib" -version = "1.4.4-SNAPSHOT0" +version = "1.4.4-SNAPSHOT1" description = "scoreboard" java.sourceCompatibility = JavaVersion.VERSION_1_8