-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
106 lines (85 loc) · 3 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"errors"
"fmt"
"log"
"time"
"github.com/kerogs/KerogsGo/colors"
"github.com/kerogs/Minecraft-Server-AutoCreation/cli"
"github.com/kerogs/Minecraft-Server-AutoCreation/helper"
)
var (
versionChoose string
)
const (
AppVersion string = "1.2.1"
spigotUrlVersion string = "https://getbukkit.org/download/spigot"
)
// main is the entry point of the program.
//
// It displays a welcome message, retrieves Spigot versions from the specified URL,
// prompts the user to choose a version, downloads the corresponding server jar,
// prepares the server for start, starts the server, accepts the EULA automatically,
// and finalizes the server installation and world creation.
//
// No parameters.
// No return values.
func main() {
cli.HelloShow(AppVersion)
// ? Check if JAVA installed
version, errs := cli.Java()
fmt.Println("Java verification...")
if errs != nil {
helper.StopProgram(errors.New("java not installed, please install it -> https://www.oracle.com/fr/java/technologies/downloads/"), "You must install Java.")
} else {
fmt.Println("Java installed, the server can be created -> JAVA version: " + version)
}
// ? Get Spigot versions
fmt.Println(colors.Green + "Connect to the following url : " + spigotUrlVersion + colors.Reset)
var versions []string
var err error
for {
versions, err = cli.Spigot(spigotUrlVersion)
if err != nil {
log.Println(err)
fmt.Println(colors.Red + "Error connecting to server. Retry in 3.5 seconds" + colors.Reset)
time.Sleep(3500 * time.Millisecond)
} else {
break
}
}
versionCount := 0
versionTotal := len(versions)
for _, version := range versions {
if versionCount == versionTotal-1 {
fmt.Println(version)
} else {
fmt.Print(version + ", ")
}
versionCount++
}
// ? Ask version to download
fmt.Print(colors.Orange + "Choose a version : " + colors.Reset)
fmt.Scanln(&versionChoose)
// ? Download server jar
fmt.Println("Try download server jar -> https://download.getbukkit.org/spigot/spigot-" + colors.Magenta + versionChoose + colors.Reset + ".jar")
httperr := cli.SpigotDownload("https://download.getbukkit.org/spigot/spigot-" + versionChoose + ".jar")
if httperr != nil{
helper.StopProgram(errs, "Error downloading server jar -> https://download.getbukkit.org/spigot/spigot-"+versionChoose+".jar")
}
fmt.Println(colors.Green + "Download completed successfully" + colors.Reset)
// ? Prepare server
cli.PrepareStart(versionChoose, AppVersion)
fmt.Println("File start.bat create")
// ? Start bat
fmt.Println(colors.Orange + "WARNING : If you have an error, make sure you have the correct version of java installed on your machine!" + colors.Reset)
fmt.Println("First launch...")
cli.StartBat(versionChoose, AppVersion)
fmt.Println(colors.Green + "First launch successfully completed" + colors.Reset)
// ? Auto accept EULA
fmt.Println("Eula automatically accepted")
cli.AcceptEula()
// ? Finalize
fmt.Println("Finalize server installation and create world...")
cli.StartBat(versionChoose, AppVersion)
}