File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
src/main/java/net/raphimc/vialoader/util Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -31,4 +31,21 @@ public static List<ProtocolVersion> getProtocolsNewToOld() {
3131 return Collections .unmodifiableList (protocolVersions );
3232 }
3333
34+ /**
35+ * Returns true if first is closer to version than second
36+ *
37+ * @param version The version to compare to
38+ * @param first The first version
39+ * @param second The second version
40+ * @return true if first is closer to version than second
41+ */
42+ public static boolean isCloserTo (final ProtocolVersion version , final ProtocolVersion first , final ProtocolVersion second ) {
43+ if (version .getVersionType () == first .getVersionType () || version .getVersionType () == second .getVersionType ()) {
44+ return Math .abs (version .getVersion () - first .getVersion ()) < Math .abs (version .getVersion () - second .getVersion ());
45+ } else {
46+ final int ordinal = version .getVersionType ().ordinal ();
47+ return Math .abs (ordinal - first .getVersionType ().ordinal ()) < Math .abs (ordinal - second .getVersionType ().ordinal ());
48+ }
49+ }
50+
3451}
You can’t perform that action at this time.
0 commit comments