From 01c90dc4aea81865be26d07653a270472cf6274a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 14 Jul 2023 15:44:52 +0200 Subject: [PATCH] Buildercloud rework, no automatic map generation, renaming, hidden worlds Signed-off-by: Lixfel --- .../commands/BuilderCloudCommand.java | 40 +++++++++++++++++-- .../steamwar/messages/BungeeCore.properties | 7 +++- .../messages/BungeeCore_de.properties | 7 +++- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java index 5436919..84740ba 100644 --- a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -3,10 +3,13 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.ServerStarter; import de.steamwar.command.SWCommand; import de.steamwar.command.TypeMapper; +import de.steamwar.messages.ChatSender; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.util.*; import java.util.stream.Collectors; @@ -25,11 +28,38 @@ public class BuilderCloudCommand extends SWCommand { versionMap.put("1.19.2", ServerStarter.Version.PAPER_19); } - @Register(description = "BUILDERCLOUD_USAGE") - public void genericCommand(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { + @Register(value = "create", description = "BUILDERCLOUD_CREATE_USAGE") + public void create(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") @AllowNull File generator) { new ServerStarter().builder(version, map, generator).send(player).start(); } + @Register(description = "BUILDERCLOUD_USAGE") + public void start(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map) { + if(!mapFile(version, map).exists()) { + ChatSender.of(player).system("BUILDERCLOUD_UNKNOWN_MAP"); + return; + } + + new ServerStarter().builder(version, map, null).send(player).start(); + } + + @Register(value = "rename", description = "BUILDERCLOUD_RENAME_USAGE") + public void rename(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String oldName, String newName) { + File newMap = mapFile(version, newName); + if(newMap.exists()) { + ChatSender.of(player).system("BUILDERCLOUD_EXISTING_MAP"); + return; + } + + try { + Files.move(mapFile(version, oldName).toPath(), newMap.toPath()); + } catch (IOException e) { + throw new SecurityException(e); + } + + ChatSender.of(player).system("BUILDERCLOUD_RENAMED"); + } + @ClassMapper(value = ServerStarter.Version.class, local = true) private TypeMapper versionTypeMapper() { return new TypeMapper() { @@ -72,7 +102,7 @@ public class BuilderCloudCommand extends SWCommand { if(folder == null || (files = folder.list()) == null) return Collections.emptyList(); - return Arrays.stream(files).filter(file -> new File(folder, file).isDirectory()).collect(Collectors.toList()); + return Arrays.stream(files).filter(file -> new File(folder, file).isDirectory()).filter(file -> s.startsWith(".") || !file.startsWith(".")).collect(Collectors.toList()); } }; } @@ -112,6 +142,10 @@ public class BuilderCloudCommand extends SWCommand { }; } + private File mapFile(ServerStarter.Version version, String map) { + return new File(version.getWorldFolder(ServerStarter.BUILDER_BASE_PATH), map); + } + private File getWorldFolder(String[] previousArguments, int offset) { ServerStarter.Version v = versionMap.get(previousArguments[previousArguments.length - offset]); if(v == null) diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 9a3b8ae..f629fdb 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -659,8 +659,13 @@ FIGHT_MERGE_INFO=§e{0}§8: §e{1} LOCK_LOCALE_CHANGED=§aLanguage saved #Builder Cloud -BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] §8<§7generator§8> +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_VERSION=§cUnknown version. +BUILDERCLOUD_EXISTING_MAP=§cMap already exists. +BUILDERCLOUD_UNKNOWN_MAP=§cUnknown map. +BUILDERCLOUD_RENAMED=§7Map rename successful. # Advent Calendar ADVENT_CALENDAR_TITLE=§eAdvent Calendar diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 5f92f3a..1341c53 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -635,8 +635,13 @@ FIGHT_MERGE_OFFLINE=§7Die vorgeschlagene Arena wurde in der Zwischenzeit beende LOCK_LOCALE_CHANGED=§aSprache gespeichert #Builder Cloud -BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] §8<§7Generator§8> +BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] +BUILDERCLOUD_CREATE_USAGE=§8/§7buildercloud create §8[§eVersion§8] §8[§eWelt§8] §8<§7Generator§8> +BUILDERCLOUD_RENAME_USAGE=§8/§7buildercloud rename §8[§eVersion§8] §8[§eWElt§8] §8[§eNeuer Name§8] BUILDERCLOUD_VERSION=§cUnbekannte Version. +BUILDERCLOUD_EXISTING_MAP=§cWelt existiert bereits. +BUILDERCLOUD_UNKNOWN_MAP=§cUnbekannte Welt. +BUILDERCLOUD_RENAMED=§7Umbenennung erfolgreich. # Advent Calendar ADVENT_CALENDAR_TITLE=§eAdventskalender