From 5aa402d6e8f6faa1b3820da3657c925df70f7d3a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 19 Aug 2023 12:39:58 +0200 Subject: [PATCH] Deploy arena command Signed-off-by: Lixfel --- deployarena.py | 85 +++++++++++++++++++ src/de/steamwar/bungeecore/ArenaMode.java | 12 ++- src/de/steamwar/bungeecore/ServerStarter.java | 4 + .../commands/BuilderCloudCommand.java | 13 +++ .../steamwar/messages/BungeeCore.properties | 1 + steamwarci.yml | 1 + 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100755 deployarena.py diff --git a/deployarena.py b/deployarena.py new file mode 100755 index 00000000..68bf0234 --- /dev/null +++ b/deployarena.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +import datetime +import os +import shutil +import sys +import tarfile +from os import path + +# Non stdlib +import yaml +from nbt import nbt + +if __name__ == "__main__": + configfile = f'/configs/GameModes/{sys.argv[1]}' + version = int(sys.argv[2]) + worldname = sys.argv[3] + + with open(configfile, 'r') as file: + gamemode = yaml.load(configfile, Loader=yaml.CLoader) + + builderworld = path.expanduser(f'~/builder{version}/{worldname}') + arenaworld = f'/servers/{gamemode["Server"]["Folder"]}/arenas/{worldname}' + + if path.exists(arenaworld): + backupworld = path.expanduser(f'~/backup/arenas/{datetime.datetime.now()}-{worldname}-{version}.tar.xz') + with tarfile.open(backupworld, 'w:xz') as tar: + tar.add(arenaworld, arcname=worldname) + + shutil.rmtree(arenaworld) + else: + gamemode['Server']['Maps'].append(worldname) + + with open(configfile, 'w') as file: + yaml.dump(gamemode, file) + + + level = nbt.NBTFile(f'{builderworld}/level.dat') + level['Data']['Difficulty'] = nbt.TAG_Byte(2) + gameRules = level['Data']['GameRules'] + gameRules['announceAdvancements'] = nbt.TAG_String('false') + gameRules['disableRaids'] = nbt.TAG_String('true') + gameRules['doDaylightCycle'] = nbt.TAG_String('false') + gameRules['doEntityDrops'] = nbt.TAG_String('false') + gameRules['doFireTick'] = nbt.TAG_String('true') + gameRules['doImmediateRespawn'] = nbt.TAG_String('true') + gameRules['doInsomnia'] = nbt.TAG_String('false') + gameRules['doLimitedCrafting'] = nbt.TAG_String('false') + gameRules['doMobLoot'] = nbt.TAG_String('false') + gameRules['doMobSpawning'] = nbt.TAG_String('false') + gameRules['doPatrolSpawning'] = nbt.TAG_String('false') + gameRules['doTileDrops'] = nbt.TAG_String('true') + gameRules['doTraderSpawning'] = nbt.TAG_String('false') + gameRules['doWardenSpawning'] = nbt.TAG_String('false') + gameRules['doWeatherCycle'] = nbt.TAG_String('false') + gameRules['drowningDamage'] = nbt.TAG_String('true') + gameRules['fallDamage'] = nbt.TAG_String('true') + gameRules['fireDamage'] = nbt.TAG_String('true') + gameRules['freezeDamage'] = nbt.TAG_String('true') + gameRules['keepInventory'] = nbt.TAG_String('true') + gameRules['lavaSourceConversion'] = nbt.TAG_String('false') + gameRules['maxEntityCramming'] = nbt.TAG_String('24') + gameRules['mobGriefing'] = nbt.TAG_String('false') + gameRules['naturalRegeneration'] = nbt.TAG_String('false') + gameRules['randomTickSpeed'] = nbt.TAG_String('3') + gameRules['reducedDebugInfo'] = nbt.TAG_String('true') + gameRules['snowAccumulationHeight'] = nbt.TAG_String('1') + gameRules['spawnRadius'] = nbt.TAG_String('0') + gameRules['spectatorsGenerateChunks'] = nbt.TAG_String('true') + gameRules['waterSourceConversion'] = nbt.TAG_String('true') + level.write_file() + + if path.exists(arenaworld): + shutil.rmtree(arenaworld) + + os.makedirs(f'{arenaworld}/backup') + shutil.copy2(f'{builderworld}/level.dat', f'{arenaworld}/backup/level.dat') + shutil.copytree(f'{builderworld}/region', f'{arenaworld}/backup/region') + + shutil.copy2(f'{builderworld}/level.dat', f'{arenaworld}/level.dat') + shutil.copytree(f'{builderworld}/region', f'{arenaworld}/region') + shutil.copy2(f'{builderworld}/config.yml', f'{arenaworld}/config.yml') + + if path.exists(f'{builderworld}/paper-world.yml'): + shutil.copy2(f'{builderworld}/paper-world.yml', f'{arenaworld}/backup/paper-world.yml') + shutil.copy2(f'{builderworld}/paper-world.yml', f'{arenaworld}/paper-world.yml') diff --git a/src/de/steamwar/bungeecore/ArenaMode.java b/src/de/steamwar/bungeecore/ArenaMode.java index d33aeeb8..d3a8d8b6 100644 --- a/src/de/steamwar/bungeecore/ArenaMode.java +++ b/src/de/steamwar/bungeecore/ArenaMode.java @@ -32,13 +32,23 @@ import java.util.stream.Collectors; public class ArenaMode { + private static final Random random = new Random(); + private static final Map byChat = new HashMap<>(); private static final Map byInternal = new HashMap<>(); private static final Map bySchemType = new HashMap<>(); private static final List allModes = new LinkedList<>(); - private static final Random random = new Random(); static { + init(); + } + + public static void init() { + byChat.clear(); + byInternal.clear(); + bySchemType.clear(); + allModes.clear(); + File folder = new File(ProxyServer.getInstance().getPluginsFolder(), "FightSystem"); for(File configFile : Arrays.stream(folder.listFiles((file, name) -> name.endsWith(".yml") && !name.endsWith(".kits.yml"))).sorted().collect(Collectors.toList())) { diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index 25af0cbf..2363169c 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -352,6 +352,10 @@ public class ServerStarter { return serverJar; } + public int getVersionSuffix() { + return versionSuffix; + } + public String getWorldFolder(String base) { return base + versionSuffix + "/"; } diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index cb5eb1ba..f34c622c 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -1,5 +1,7 @@ package de.steamwar.bungeecore.commands; +import de.steamwar.bungeecore.ArenaMode; +import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; @@ -70,6 +72,17 @@ public class BuilderCloudCommand extends SWCommand { ChatSender.of(player).system("BUILDERCLOUD_RENAMED"); } + @Register(value = "deploy", description = "BUILDERCLOUD_DEPLOY_USAGE") + public void deploy(ProxiedPlayer player, @Mapper("nonHistoricArenaMode") ArenaMode arenaMode, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) { + if(!mapFile(version, map).exists()) { + ChatSender.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + return; + } + + BungeeCore.local.execute("/binaries/deployarena.py", arenaMode.getConfig(), Integer.toString(version.getVersionSuffix()), map); + ArenaMode.init(); + } + @ClassMapper(value = ServerStarter.Version.class, local = true) private TypeMapper versionTypeMapper() { return new TypeMapper() { diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 9223a253..30ce2090 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -662,6 +662,7 @@ LOCK_LOCALE_CHANGED=§aLanguage saved BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] BUILDERCLOUD_CREATE_USAGE=§8/§7buildercloud create §8[§eversion§8] §8[§emap§8] §8<§7generator§8> BUILDERCLOUD_RENAME_USAGE=§8/§7buildercloud rename §8[§eversion§8] §8[§emap§8] §8[§enew name§8] +BUILDERCLOUD_DEPLOY_USAGE=§8/§7deployarena §8[§egamemode§8] §8[§eversion§8] §8[§emap§8] BUILDERCLOUD_VERSION=§cUnknown version. BUILDERCLOUD_EXISTING_MAP=§cMap already exists. BUILDERCLOUD_UNKNOWN_MAP=§cUnknown map. diff --git a/steamwarci.yml b/steamwarci.yml index 2b3f672e..76aa0038 100644 --- a/steamwarci.yml +++ b/steamwarci.yml @@ -4,3 +4,4 @@ build: artifacts: "/binarys/bungeecore.jar": "build/libs/bungeecore.jar" + "/binarys/deployarena.py": "deployarena.py"