Skip to content

Commit 5ccc5e8

Browse files
authored
Merge pull request #3 from davidmayr/main
feat: download page for advanced slime paper
2 parents 955cf51 + aeeef98 commit 5ccc5e8

File tree

13 files changed

+367
-60
lines changed

13 files changed

+367
-60
lines changed

docs_asp/setup.mdx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
sidebar_position: 2
33
---
4+
import AswmDownload from '@site/src/components/aswm-download';
45

56
# Setup
67
This page covers how to quickly get ASP up and running on your server.
@@ -22,24 +23,15 @@ ASP is actively developed for Paper; Pufferfish and Purpur versions are based on
2223

2324
### ASPaper
2425
We recommend using the Paper version for the most stable experience.
26+
AdvancedSlimePaper builds are split into several branches, including main, develop, and various feature or PR branches.
2527

26-
#### Main
27-
Tested and ready for production.
28-
```
29-
Download links will be added later
30-
```
28+
The `main` branch is stable and well-tested, but it may not always include the latest Paper commits. For bleeding-edge updates, see `paper_upstream`, which includes untested automatic changes.
3129

32-
#### Develop
33-
Contains the latest features and bug fixes, but is **BARELY** tested and might not work at all.
34-
```
35-
Download links will be added later
36-
```
30+
The `develop` branch is experimental — it’s generally up-to-date with the latest features and versions, but may include a few bugs.
3731

38-
#### Upstream
39-
Contains the latest patches from Paper, but is **NOT** tested.
40-
```
41-
Download links will be added later
42-
```
32+
All other branches should be considered highly unstable. These may include breaking API changes, incomplete features, or **unsafe third-party code** from pull requests.
33+
34+
<AswmDownload slug={"asp"} github={"https://github.com/InfernalSuite/AdvancedSlimePaper"}></AswmDownload>
4335

4436
### ASPufferfish
4537
The Pufferfish version is updated less frequently than Paper.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
"react-dom": "^18.0.0"
2525
},
2626
"devDependencies": {
27-
"@docusaurus/module-type-aliases": "3.4.0",
28-
"@docusaurus/types": "3.4.0",
27+
"@docusaurus/module-type-aliases": "^3.7.0",
28+
"@docusaurus/tsconfig": "^3.7.0",
29+
"@docusaurus/types": "^3.7.0",
30+
"typescript": "^5.8.3",
2931
"wrangler": "^3.60.3"
3032
},
3133
"browserslist": {

src/components/aswm-build.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React, {useMemo} from "react";
2+
import styles from "@site/src/components/downloads.module.css";
3+
import {Build, resolveDownload} from "@site/src/lib/download-api";
4+
5+
export function ASWMBuild({slug, build, github}: { slug: string, build: Build, github: string }) {
6+
const serverDownload = useMemo(() => {
7+
return build.files.find((it) => it.fileName.endsWith(".jar") && it.fileName.includes("server"))
8+
}, [build])
9+
const pluginDownload = useMemo(() => {
10+
return build.files.find((it) => it.fileName.endsWith(".jar") && it.fileName.includes("plugin"))
11+
}, [build])
12+
const date = useMemo(() => {
13+
const d = new Date(build.date)
14+
const now = new Date();
15+
const diff = now.getTime() - d.getTime(), dayMs = 86400000;
16+
17+
if (diff < 7 * dayMs) {
18+
const rtf = new Intl.RelativeTimeFormat('en', {numeric: 'auto'});
19+
const days = Math.floor(diff / dayMs);
20+
return rtf.format(-days, 'day');
21+
}
22+
23+
return d.toLocaleDateString("en");
24+
}, [build])
25+
26+
27+
return <div className={styles.build}>
28+
<div className={styles.downloads}>
29+
{serverDownload &&
30+
<a className={"button button--primary button--sm"}
31+
href={resolveDownload(slug, build.id, serverDownload.id)} target={"_blank"}>Server</a>}
32+
{pluginDownload && <a className={"button button--primary button--sm"}
33+
href={resolveDownload(slug, build.id, pluginDownload.id)}
34+
target={"_blank"}>Plugin</a>}
35+
</div>
36+
<div className={styles.changeList}>
37+
{build.changes.map((it) => {
38+
return <p><a target={"_blank"} href={github + "/commit/" + it.commitHash}>{it.shortCommitHash}</a> {it.commit}</p>
39+
})}
40+
{build.changes.length == 0 && <p>No changes</p>}
41+
</div>
42+
43+
<p className={styles.date}>{date}</p>
44+
45+
</div>
46+
}

src/components/aswm-download.tsx

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import React, {useEffect, useMemo, useState} from "react";
2+
import styles from './downloads.module.css';
3+
import {
4+
BranchInfo,
5+
Build,
6+
findNewestSafeVersion,
7+
findOptimalBranch, getBranchSuffix,
8+
getVersionsSortedDescending
9+
} from "@site/src/lib/download-api";
10+
import {ASWMBuild} from "@site/src/components/aswm-build";
11+
12+
export default function AswmDownload({ slug, github }: { slug: string, github: string }) {
13+
const [branchInfo, setBranchInfo] = useState<BranchInfo | undefined>();
14+
const [selectedVersion, setSelectedVersion] = useState<string>();
15+
const sortedVersions = useMemo(() => getVersionsSortedDescending(branchInfo), [branchInfo]);
16+
17+
const [selectedBranch, setSelectedBranch] = useState<string>();
18+
const [buildInfo, setBuildInfo] = useState<Build[]>();
19+
20+
const optimalVersion = useMemo(() => branchInfo != undefined ? findNewestSafeVersion(branchInfo) : undefined, [branchInfo])
21+
const newerThenOptimal = useMemo(() => sortedVersions.filter((e) => sortedVersions.indexOf(e) < sortedVersions.indexOf(optimalVersion)), [optimalVersion, sortedVersions])
22+
23+
const latestBuilds = useMemo(() => {
24+
if(!buildInfo || !selectedBranch) return []
25+
26+
return buildInfo.filter((it) => it.branch === selectedBranch).sort((b, a) => a.date - b.date).slice(0, 10)
27+
}, [buildInfo, selectedBranch]);
28+
29+
useEffect(() => {
30+
fetch("https://api.infernalsuite.com/v1/projects/" + slug + "/branches").then((res) => res.json()).then((res) => {
31+
setBranchInfo(res)
32+
33+
34+
const version = findNewestSafeVersion(res)
35+
setSelectedVersion(version)
36+
const branches = res[version]
37+
setSelectedBranch(findOptimalBranch(branches))
38+
})
39+
}, [slug])
40+
41+
useEffect(() => {
42+
if(!selectedVersion || !selectedBranch) return
43+
44+
setBuildInfo(undefined)
45+
fetch("https://api.infernalsuite.com/v1/projects/" + slug + "/mcVersion/" + selectedVersion).then((res) => res.json()).then((res) => {
46+
setBuildInfo(res)
47+
})
48+
49+
}, [selectedVersion]);
50+
51+
function changeVersion(e: React.ChangeEvent<HTMLSelectElement>) {
52+
setSelectedVersion(e.target.value)
53+
setSelectedBranch(findOptimalBranch(branchInfo[e.target.value]))
54+
}
55+
56+
57+
return <>
58+
{newerThenOptimal.length > 0 && <div className={"alert alert--warning margin-bottom--md"}>
59+
We have experimental builds for newer Minecraft versions available({newerThenOptimal.join(", ")}), however use them with caution! You can select them in the version switcher.
60+
</div>}
61+
62+
<div className={styles.downloadContainer}>
63+
<div className={styles.downloadHeader}>
64+
<p>Latest builds</p>
65+
66+
<div className={styles.downloadHeaderSelect}>
67+
<select id="version" value={selectedVersion} onChange={(e) => changeVersion(e)}>
68+
{branchInfo && sortedVersions.map((it) => {
69+
return <option value={it}>{it}</option>
70+
})}
71+
</select>
72+
<select id="branch" value={selectedBranch} onChange={(e) => setSelectedBranch(e.target.value)}>
73+
{branchInfo && selectedVersion && branchInfo[selectedVersion] && branchInfo[selectedVersion].map((it) => {
74+
return <option value={it}>{it} {getBranchSuffix(it)}</option>
75+
})}
76+
</select>
77+
</div>
78+
</div>
79+
80+
{/*{!branchInfo || !buildInfo && <p>Loading</p>}*/}
81+
82+
<div className={styles.buildContainer}>
83+
{latestBuilds.map((build) => {
84+
return <ASWMBuild key={build.id} slug={slug} build={build} github={github}/>
85+
})}
86+
</div>
87+
88+
89+
</div>
90+
</>
91+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
2+
3+
:root {
4+
--downloads-header-color: #303846;
5+
--downloads-header-text: #ffffff;
6+
--downloads-body-color: #e1e1e1;
7+
--downloads-entry-hover: #c4c4c4;
8+
}
9+
10+
/* For readability concerns, you should choose a lighter palette in dark mode. */
11+
[data-theme='dark'] {
12+
--downloads-body-color: #272d38;
13+
--downloads-entry-hover: #1f262e;
14+
}
15+
16+
17+
.downloadContainer {
18+
background: var(--downloads-body-color);
19+
border-radius: 5px;
20+
overflow: hidden;
21+
}
22+
23+
.downloadHeader {
24+
background: var(--downloads-header-color);
25+
display: flex;
26+
align-items: center;
27+
justify-content: space-between;
28+
padding: 8px 12px;
29+
}
30+
31+
.downloadHeader select {
32+
padding: 5px 8px;
33+
border-radius: 5px;
34+
}
35+
36+
.downloadHeader p {
37+
color: var(--downloads-header-text)
38+
}
39+
40+
.downloadHeaderSelect {
41+
display: flex;
42+
gap: 5px;
43+
}
44+
45+
.downloadHeader p {
46+
margin: 0;
47+
font-weight: 650;
48+
}
49+
50+
.buildContainer {
51+
display: flex;
52+
flex-direction: column;
53+
gap: 8px;
54+
}
55+
56+
.build {
57+
display: flex;
58+
align-items: center;
59+
justify-content: space-between;
60+
padding: 4px 0;
61+
}
62+
63+
.build:hover {
64+
background-color: var(--downloads-entry-hover);
65+
transition: color;
66+
}
67+
68+
.build .date {
69+
margin: 1px 10px;
70+
}
71+
.build .changeList {
72+
max-width: 100%;
73+
flex-grow: 1;
74+
min-width: 0;
75+
}
76+
77+
.build .changeList p {
78+
margin: 0;
79+
white-space: nowrap;
80+
overflow: hidden;
81+
text-overflow: ellipsis;
82+
}
83+
84+
.build .downloads {
85+
display: flex;
86+
gap: 5px;
87+
margin: 6px 10px
88+
}

src/css/custom.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);
3737
}
3838

39+
[data-theme='dark'] :where(.button--primary) {
40+
--ifm-button-color: #ffffff;
41+
}
42+
3943
.hero {
4044
--ifm-hero-background-color: #572245;
4145
--ifm-hero-text-color: #e6e6e6;

src/lib/download-api.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
export interface Build {
3+
date: number
4+
branch: string
5+
paperRef: string
6+
id: string
7+
changes: Change[]
8+
files: File[]
9+
}
10+
11+
export interface Change {
12+
shortCommitHash: string
13+
commit: string
14+
commitHash: string
15+
}
16+
17+
export interface File {
18+
fileName: string
19+
id: string
20+
}
21+
22+
export interface BranchInfo {
23+
[key: string]: string[]
24+
}
25+
26+
27+
export function resolveDownload(slug: string, build: string, file: string) {
28+
return `https://api.infernalsuite.com/v1/projects/${slug}/${build}/download/${file}`
29+
}
30+
31+
32+
export function getVersionsSortedDescending(branchInfo: BranchInfo) {
33+
if (!branchInfo) return [];
34+
const versions = Object.keys(branchInfo);
35+
return versions.sort((b, a) => {
36+
37+
const aParts = a.split('.').map(Number);
38+
const bParts = b.split('.').map(Number);
39+
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
40+
const aPart = aParts[i] || 0;
41+
const bPart = bParts[i] || 0;
42+
if (aPart !== bPart) {
43+
return aPart - bPart;
44+
}
45+
}
46+
return 0;
47+
});
48+
}
49+
50+
export function findNewestSafeVersion(branchInfo: BranchInfo) {
51+
const versions = getVersionsSortedDescending(branchInfo);
52+
53+
for (const version of versions) {
54+
const isSafe = branchInfo[version].includes("main");
55+
if (isSafe) {
56+
return version;
57+
}
58+
}
59+
return versions[0]
60+
}
61+
62+
//Well, at least somewhat safe
63+
const safeBranches = ["paper_upstream", "main"]
64+
65+
export function getBranchSuffix(branch: string): string {
66+
if(branch == "develop")
67+
return "(Experimental)"
68+
69+
if(!safeBranches.includes(branch))
70+
return "(Dangerous)"
71+
return ""
72+
}
73+
74+
export function findOptimalBranch(branches: string[]): string {
75+
if(branches.includes("paper_upstream")) {
76+
return "paper_upstream"
77+
} else if (branches.includes("main")) {
78+
return "main"
79+
} else if (branches.includes("develop")) {
80+
return "develop"
81+
} else {
82+
return branches[0]
83+
}
84+
}

src/pages/download/asp.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)