Skip to content

Commit

Permalink
fix forge maven download url
Browse files Browse the repository at this point in the history
  • Loading branch information
nothub committed Oct 19, 2024
1 parent a39d8ac commit f393b06
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions server/forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ package server

import (
"fmt"
"github.com/nothub/mrpack-install/maven"
"github.com/nothub/mrpack-install/web"
"github.com/nothub/semver"
"log"
"os/exec"
"strings"
)

type ForgeInstaller struct {
Expand All @@ -13,12 +16,43 @@ type ForgeInstaller struct {
}

func (inst *ForgeInstaller) Install(serverDir string, serverFile string) error {

version := inst.ForgeVersion

if version == "" || version == "latest" {

meta, err := maven.FetchMetadata("https://maven.minecraftforge.net/net/minecraftforge/forge/maven-metadata.xml")
if err != nil {
return err
}

var versions []string
for _, ver := range meta.Versioning.Versions {
if !strings.HasPrefix(ver, inst.MinecraftVersion) {
// does not match mc version
continue
}
versions = append(versions, ver)
}

parsed, err := semver.ParseAll(versions)
if err != nil {
return err
}

sorted := semver.SortDesc(parsed)

if len(sorted) <= 0 {
return fmt.Errorf("no forge release version found for mc version %s", inst.MinecraftVersion)
}

version = sorted[0].String()
}

u := fmt.Sprintf(
"https://maven.minecraftforge.net/net/minecraftforge/forge/%s-%s/forge-%s-%s-installer.jar",
inst.MinecraftVersion,
inst.ForgeVersion,
inst.MinecraftVersion,
inst.ForgeVersion,
"https://maven.minecraftforge.net/net/minecraftforge/forge/%s/forge-%s-installer.jar",
version,
version,
)
installerFile, err := web.DefaultClient.DownloadFile(u, ".", "")
if err != nil {
Expand Down

0 comments on commit f393b06

Please sign in to comment.