Skip to content

Commit 5bb8dc6

Browse files
committed
Added a wrapper to easy extract the version components
1 parent e6a05a1 commit 5bb8dc6

2 files changed

Lines changed: 72 additions & 5 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ subprojects {
9393
artifactId = project.name
9494
groupId = project.group.toString()
9595
artifactId = project.name
96-
version = "0.132"
96+
version = "0.133"
9797
pom {
9898
name.set(project.name)
9999
description.set("Description for ${project.name}")

version/src/main/java/org/broken/arrow/library/version/VersionUtil.java

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public boolean versionOlder(double version) {
8080
/**
8181
* Returns the parsed server version as a float.
8282
*
83-
* @deprecated should no longer be used.
8483
* @return the server version number
84+
* @deprecated should no longer be used.
8585
*/
8686
@Deprecated
8787
public double getServerVersion() {
@@ -93,8 +93,74 @@ public double getServerVersion() {
9393
*
9494
* @return a array of the version from major to patch.
9595
*/
96-
public int[] getVersion() {
97-
return new int[]{major, minor, patch};
96+
public Version getVersion() {
97+
return new Version();
98+
}
99+
100+
/**
101+
* Represents the parsed Minecraft server version.
102+
*
103+
* <p>This class provides a simplified view of the server version using
104+
* major, minor, and patch components.</p>
105+
*
106+
* <p><strong>Version format handling:</strong></p>
107+
* <ul>
108+
* <li>For legacy versions (e.g. 1.21.5): major = 1, minor = 21, patch = 5</li>
109+
* <li>For newer versions (e.g. 26.0.1): major = 26, minor = 0, patch = 1</li>
110+
* </ul>
111+
*
112+
* <p>Note: The meaning of minor and patch differs between legacy and newer
113+
* version formats, but their positions remain consistent.
114+
* </p>
115+
*/
116+
public class Version {
117+
118+
/**
119+
* Returns the major version number.
120+
*
121+
* <p>Examples:</p>
122+
* <ul>
123+
* <li>1.21.5 → 1</li>
124+
* <li>26.0.1 → 26</li>
125+
* </ul>
126+
*
127+
* @return the major version
128+
*/
129+
public int getMajor() {
130+
return major;
131+
}
132+
133+
/**
134+
* Returns the minor version number.
135+
*
136+
* <p>Examples:</p>
137+
* <ul>
138+
* <li>1.21.5 → 21</li>
139+
* <li>26.0.1 → 0</li>
140+
* </ul>
141+
*
142+
* @return the minor version
143+
*/
144+
public int getMinor() {
145+
return minor;
146+
}
147+
148+
/**
149+
* Returns the patch version number.
150+
*
151+
* <p>Examples:</p>
152+
* <ul>
153+
* <li>1.21.5 → 5</li>
154+
* <li>26.0.1 → 1</li>
155+
* </ul>
156+
*
157+
* <p>If the patch version cannot be parsed, this may return 0.</p>
158+
*
159+
* @return the patch version
160+
*/
161+
public int getPatch() {
162+
return patch;
163+
}
98164
}
99165

100166
/**
@@ -125,7 +191,7 @@ private void setServerVersion(@Nullable final Plugin plugin) {
125191
} catch (NumberFormatException ignore) {
126192
patch = 0;
127193
}
128-
version = Double.parseDouble(major + "." + minor);
194+
version = Double.parseDouble(major + "." + minor);
129195
return;
130196
}
131197
setVersionLegacy(firstString, versionPieces);
@@ -166,4 +232,5 @@ private int compare(int major, int minor) {
166232

167233
return Integer.compare(this.minor, minor);
168234
}
235+
169236
}

0 commit comments

Comments
 (0)