-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
212 lines (198 loc) · 9 KB
/
index.html
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!doctype html>
<html lang="en">
<head>
<title>Minecraft Script Generator</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-light bg-info">
<span class="navbar-brand mb-0 h1">Minecraft Server Script Generator</span>
</nav>
<div class="container mt-5">
<div class="card shadow">
<div class="card-body">
<h4 class="card-title text-center">Choose options</h4>
<div class="container">
<form id="main-form" class="needs-validation" novalidate>
<div class="form-group row justify-content-center align-items-center">
<div class="form-group col-md-5">
<label class="col-form-label" for="arch">Architecture</label>
<select class="form-control" name="arch" id="arch" required>
<option selected disabled value="">Select one</option>
<option value="paper">Paper</option>
<option value="spigot">Spigot</option>
<option value="craftbukkit">CraftBukkit</option>
<option value="vanilla">Vanilla</option>
</select>
<div class="invalid-feedback"> Please selected a server architecture. </div>
</div>
<div class="form-group col-md-5">
<label class="col-form-label" for="version">Version</label>
<select class="form-control" name="version" id="version" required disabled>
<option selected disabled value="">Select one</option>
</select>
<div class="invalid-feedback"> Please select a minecraft version. </div>
</div>
<div class="form-group col-md-2">
<label class="col-form-label" for="ram">RAM</label>
<select class="form-control" name="ram" id="ram" required>
<option selected disabled value="">Select one</option>
<option value="500M">500MB</option>
<option value="1G">1GB</option>
<option value="2G">2GB</option>
<option value="3G">3GB</option>
<option value="4G">4GB</option>
<option value="5G">5GB</option>
<option value="6G">6GB</option>
<option value="7G">7GB</option>
<option value="8G">8GB</option>
<option value="9G">9GB</option>
<option value="10G">10GB</option>
</select>
<div class="invalid-feedback"> Please select an amount of RAM. </div>
</div>
<div class="form-group col-md-4">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" name="flags" id="flags"> Use Aikar's flags </label>
</div>
</div>
<div class="form-group col-md-4">
<div class="form-check float-right">
<label class="form-check-label">
<input type="checkbox" class="form-check-input" name="debug" id="debug"> Enable debugger </label>
</div>
</div>
<div class="form-group col-md-4">
<label for="debug_port">Port</label>
<input type="number" class="form-control" name="debug_port" id="debug_port" value="5005" disabled
required>
<div class="invalid-feedback"> Please selected a valid port number. </div>
</div>
</div>
<div class="form-group row justify-content-center">
<div class="col-md-12 text-center">
<button type="submit" name="generate" id="generate" class="btn btn-success" btn-lg
btn-block">Generate</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"></script>
</body>
<script>
function download(filename, content) {
var element = document.createElement('a')
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content))
element.setAttribute('download', filename)
element.style.display = 'none'
document.body.appendChild(element)
element.click()
document.body.removeChild(element)
}
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function () {
'use strict';
const versions = {
vanilla: [],
spigot: [],
paper: [],
craftbukkit: [],
}
var script = ""
var flags = ""
const DEBUG = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$PORT$"
// debug = debug.replace("$PORT$", "5005")
window.addEventListener('load', () => {
$.get('https://mc-server-versions-api.glitch.me/flags').done(data => {
flags = data
}).fail(err => console.error(err))
$.get('https://mc-server-versions-api.glitch.me/vanilla').done(data => {
data.split('\n').forEach(el => {
versions.vanilla.push(el.split(' ')[0])
})
}).fail(err => console.error(err))
$.get('https://mc-server-versions-api.glitch.me/spigot/versions').done(data => {
data.split('\n').forEach(el => {
versions.spigot.push(el.split(' ')[0])
versions.craftbukkit.push(el.split(' ')[0])
})
}).fail(err => console.error(err))
$.get('https://papermc.io/api/v2/projects/paper/').done(data => {
versions.paper = data.versions.reverse()
}).fail(err => console.error(err))
$.get('https://api.github.com/gists/7738eabd8e4cafe7ac6b0f90d2a457e6').done(({ files }) => {
// console.log(files)
script = files['run.sh'].content
// console.log(script)
}).fail(err => console.error(err))
$("#arch").on("change", el => {
if (el.target.value === "" || Object.keys(versions).indexOf(el.target.value) < 0) {
$("#version")
.empty()
.append('<option selected disabled value="">Select one</option>')
.prop('disabled', true)
.val("")
return
}
$("#version")
.empty()
.append('<option selected disabled value="">Select one</option>')
.val("")
versions[el.target.value].forEach(v => {
$("#version").append('<option>' + v + '</option>')
})
$("#version").prop("disabled", false)
})
$("#debug").on("change", el => {
if (el.target.checked === true) $("#debug_port").prop("disabled", false)
else $("#debug_port").prop("disabled", true)
})
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function (form) {
form.addEventListener('submit', function (event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
else { // form is valid, generating script
event.preventDefault()
let tmp_script = script
.replace(/ARCH=\n/, "ARCH=" + $("#arch").val() + "\n")
.replace(/VERSION=\n/, "VERSION=" + $("#version").val() + "\n")
.replace(/RAM=6G\n/, "RAM=" + $("#ram").val() + "\n")
if ($("#flags").prop("checked"))
tmp_script = tmp_script.replace('-Xmx${RAM} -jar', '-Xmx${RAM} ' + flags + ' -jar')
if ($("#debug").prop("checked")) {
tmp_script = tmp_script.replace("-jar \"${ARCH}", DEBUG + " -jar \"${ARCH}")
tmp_script = tmp_script.replace('$PORT$', $("#debug_port").val())
}
// console.log(tmp_script) // for debugging
download('run.sh', tmp_script)
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
</html>