Last active
October 16, 2020 05:28
-
-
Save yonderbread/75549244e5691145a856823cc639c926 to your computer and use it in GitHub Desktop.
Create basic bungeecord setup easy!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
import requests | |
import subprocess as sp | |
import shutil | |
import time | |
BUNGEECORD_LATEST = 'https://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/BungeeCord.jar' | |
BUILDTOOLS_LATEST = 'https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar' | |
BUILDTOOLS_DIRNAME = '_Buildtools' | |
BUNGEECORD_DIRNAME = 'Bungeecord' | |
RUN_SCRIPT = 'java -DIReallyKnowWhatIAmDoingISwear -jar -Xmx{0}G -Xms{1}G {2}' | |
def downloadTo(url, fp): | |
res = requests.get(url) | |
with open(fp, 'wb') as f: | |
f.write(res.content) | |
f.close() | |
class Logger: | |
def info(message): | |
print(f"[Info] {message}") | |
def warn(message): | |
print(f"[Warn] {message}") | |
def err(message): | |
print(f"[Error] {message}") | |
if __name__ == '__main__': | |
action = sys.argv[1] | |
root_dirname = sys.argv[2] | |
server_type = 'spigot' | |
server_ram = sys.argv[3] | |
server_names = sys.argv[4:] | |
log = Logger | |
if action == 'new': | |
log.info('Setting up...') | |
os.mkdir(root_dirname) | |
buildtools_path = os.path.join(os.getcwd(), root_dirname, BUILDTOOLS_DIRNAME) | |
buildtools_jar_path = os.path.join(buildtools_path, 'BuildTools.jar') | |
os.mkdir(buildtools_path) | |
bungeecord_path = os.path.join(os.getcwd(), root_dirname, BUNGEECORD_DIRNAME) | |
bungeecord_jar_path = os.path.join(bungeecord_path, 'Bungeecord.jar') | |
os.mkdir(bungeecord_path) | |
log.info('Downloading Bungeecord...') | |
downloadTo(BUNGEECORD_LATEST, bungeecord_jar_path) | |
log.info('Downloadig BuildTools...') | |
downloadTo(BUILDTOOLS_LATEST, buildtools_jar_path) | |
log.info('Generating server folders...') | |
server_dir_paths = [] | |
for server_name in server_names: | |
p = os.path.join(os.getcwd(), root_dirname, server_name) | |
os.mkdir(p) | |
server_dir_paths.append(p) | |
log.info('Running BuildTools...') | |
os.chdir(buildtools_path) | |
bt_proc = sp.run(['java', '-jar', 'BuildTools.jar']) | |
log.info(f'Done. Setting up {server_type} servers...') | |
spigot_jar_path = None | |
for filename in os.listdir('.'): | |
if 'spigot' in filename: | |
spigot_jar_path = os.path.join(buildtools_path, filename) | |
log.info('Found spigot jar...') | |
log.info(spigot_jar_path) | |
break | |
if not spigot_jar_path: | |
log.err('Error finding spigot jar file. Aborting.') | |
sys.exit() | |
os.chdir('..') | |
log.info('Copying server jar to each server...') | |
log.warn('BY CREATING A MINECRAFT SERVER YOU AGREE TO MOJANGS EULA') | |
for server_dir in server_dir_paths: | |
fp = shutil.copy(spigot_jar_path, server_dir) | |
time.sleep(3) | |
os.rename(fp, os.path.join(fp, 'spigot.jar')) | |
log.info('Copied to ' + server_dir + ', creating start script..') | |
with open(os.path.join(server_dir, 'run.sh', 'w')) as f: | |
f.write(RUN_SCRIPT.format(server_ram, server_ram, server_type + '.jar')) | |
f.close() | |
with open(os.path.join(server_dir, 'eula.txt', 'w')) as f_eula: | |
f_eula.write('eula=true') | |
f_eula.close() | |
print('Finished setting up ' + len(server_names) + ' ' + server_type + ' servers.') | |
print('Goodbye :)') | |
sys.exit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Syntax goes as follows: | |
python bungeecord-create.py new <foldername> <ram in gb integer> <list of server names> | |
Will download the latest Bungeecord jar and BuildTools jar. Compiles spigot and creates new server instances for you to configure, | |
alongside a bungeecord folder of course :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment