Skip to content

Commit 1ee2910

Browse files
Merge pull request #220 from Doc94/feature/improvement-paper-archive-version-check
feat: improve version comparison for Paper
2 parents 695a984 + 58982ec commit 1ee2910

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

src/utils/github.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,24 @@ export const getProjectRepository = (project: string, version: string): string =
5252
if (project !== "paper") return `https://github.com/PaperMC/${project}`;
5353
if (project === "paper" && version === "1.7.10") return "https://github.com/PaperMC/Paper-1.7";
5454

55-
const baseVersion = [21, 4]; // 1.21.4 is after the hardfork
56-
const isBelowBaseVersion = version
57-
.replace(/^1\./, "")
58-
.split(".")
59-
.map(Number)
60-
.some((v, i) => v < (baseVersion[i] || 0));
61-
62-
return isBelowBaseVersion ? "https://github.com/PaperMC/Paper-Archive" : "https://github.com/PaperMC/Paper";
55+
const baseVersion = "1.21.4"; // after the hardfork
56+
57+
return isVersionBelow(version, baseVersion) ? "https://github.com/PaperMC/Paper-Archive" : "https://github.com/PaperMC/Paper";
6358
};
59+
60+
function isVersionBelow(version: string, base: string): boolean {
61+
const v = version.split(".").map(Number);
62+
const b = base.split(".").map(Number);
63+
64+
const len = Math.max(v.length, b.length);
65+
66+
for (let i = 0; i < len; i++) {
67+
const vi = v[i] ?? 0;
68+
const bi = b[i] ?? 0;
69+
70+
if (vi < bi) return true;
71+
if (vi > bi) return false;
72+
}
73+
74+
return false;
75+
}

0 commit comments

Comments
 (0)