From 229cf77035bf2b7861e232b17242a6b2d99a11f9 Mon Sep 17 00:00:00 2001 From: MoBrot <90271578+MoBrot@users.noreply.github.com> Date: Thu, 28 Jul 2022 18:00:02 +0200 Subject: [PATCH] Added BuilderCloudCommand Added BungeeCore.properties message Added BungeeCore_de.properties message Added ServerStarter for the BuilderCloud --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + src/de/steamwar/bungeecore/ServerStarter.java | 13 +++- .../commands/BuilderCloudCommand.java | 72 +++++++++++++++++++ .../steamwar/messages/BungeeCore.properties | 6 +- .../messages/BungeeCore_de.properties | 6 +- 5 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 8518c97..93a1d63 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -149,6 +149,7 @@ public class BungeeCore extends Plugin { new RankCommand(); new LocalCommand(); new SetLocaleCommand(); + new BuilderCloudCommand(); // Punishment Commands: new PunishmentCommand("ban", Punishment.PunishmentType.Ban); diff --git a/src/de/steamwar/bungeecore/ServerStarter.java b/src/de/steamwar/bungeecore/ServerStarter.java index 35a97dd..cc2baa6 100644 --- a/src/de/steamwar/bungeecore/ServerStarter.java +++ b/src/de/steamwar/bungeecore/ServerStarter.java @@ -28,6 +28,9 @@ public class ServerStarter { public static final String TUTORIAL_PATH = BACKBONE + "tutorials/"; public static final String WORLDS19_PATH = BACKBONE + "userworlds19/"; + public static final String BUILDER15_PATH = BACKBONE + "builder15/"; + public static final String BUILDER19_PATH = BACKBONE + "builder19/"; + private File directory = null; private String worldDir = null; @@ -48,6 +51,14 @@ public class ServerStarter { private final Set playersToSend = new HashSet<>(); private final Map arguments = new HashMap<>(); + public ServerStarter builderCloud(String serverJar, String map) { + this.serverJar = serverJar; + this.worldName = map; + + this.directory = new File(SERVER_PATH); + return this; + } + public ServerStarter arena(ArenaMode mode, String map) { portrange = ARENA_PORTS; serverNameProvider = port -> mode.getDisplayName() + (port - portrange.start); @@ -287,4 +298,4 @@ public class ServerStarter { return result; } } -} +} \ No newline at end of file diff --git a/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java new file mode 100644 index 0000000..c84af0f --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java @@ -0,0 +1,72 @@ +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.util.*; + +public class BuilderCloudCommand extends SWCommand { + + private final Map versionMap = new HashMap<>(); + private final Map pathMap = new HashMap<>(); + + public BuilderCloudCommand() { + super("buildercloud", "bungeecore.server.team"); + + versionMap.put("1.19", "spigot-1.19.jar"); + versionMap.put("19", "spigot-1.19.jar"); + versionMap.put("1.15", "spigot-1.15.2.jar"); + versionMap.put("15", "spigot-1.15.2.jar"); + versionMap.put("1.15.2", "spigot-1.15.2.jar"); + + pathMap.put("19", ServerStarter.BUILDER19_PATH); + pathMap.put("1.19", ServerStarter.BUILDER19_PATH); + pathMap.put("15", ServerStarter.BUILDER15_PATH); + pathMap.put("1.15", ServerStarter.BUILDER15_PATH); + pathMap.put("1.15.2", ServerStarter.BUILDER15_PATH); + } + + // /buildercloud [version] [map] + + @Register(description = "BUILDERCLOUD_USAGE") + public void genericCommand(ProxiedPlayer player, @StaticValue({"19", "1.19", "15", "1.15.2", "1.15"}) @ErrorMessage("BUILDERCLOUD_VERSION") String version, File map) { + String jar = this.versionMap.get(version); + new ServerStarter().builderCloud(jar, map.getName()).start(); + } + + @Cached(global = true) + @ClassMapper(value = File.class, local = true) + private TypeMapper mapTypeMapper() { + + return new TypeMapper() { + @Override + public File map(CommandSender commandSender, String[] previousArguments, String s) { + String folder = pathMap.get(previousArguments[previousArguments.length - 1]); + + if(folder == null) + return null; + + File map = new File(folder, s); + if(!map.exists() || !map.isDirectory()) + return null; + + return map; + } + + @Override + public Collection tabCompletes(CommandSender sender, String[] previousArguments, String s) { + String folder = pathMap.get(previousArguments[previousArguments.length - 1]); + + if(folder == null) + return null; + + return Arrays.asList(Objects.requireNonNull(new File(folder).list())); + } + }; + } +} diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index 7dfaa7c..ba8072c 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -631,4 +631,8 @@ FIGHT_MERGE_OFFLINE=§7The proposed arena has been terminated in the meantime, a FIGHT_MERGE_INFO=§e{0}§8: §e{1} #Locale Locking -LOCK_LOCALE_CHANGED=§aLanguage saved \ No newline at end of file +LOCK_LOCALE_CHANGED=§aLanguage saved + +#Builder Cloud +BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] +BUILDERCLOUD_VERSION=§cUnknown version. \ No newline at end of file diff --git a/src/de/steamwar/messages/BungeeCore_de.properties b/src/de/steamwar/messages/BungeeCore_de.properties index 6fc780b..d9fad23 100644 --- a/src/de/steamwar/messages/BungeeCore_de.properties +++ b/src/de/steamwar/messages/BungeeCore_de.properties @@ -609,4 +609,8 @@ FIGHT_MERGE_INFO_LORE_1=§8Von: §e{0} FIGHT_MERGE_OFFLINE=§7Die vorgeschlagene Arena wurde in der Zwischenzeit beendet, es wird eine neue Arena gestartet. #Locale Locking -LOCK_LOCALE_CHANGED=§aSprache gespeichert \ No newline at end of file +LOCK_LOCALE_CHANGED=§aSprache gespeichert + +#Builder Cloud +BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] +BUILDERCLOUD_VERSION=§cUnbekannte Version. \ No newline at end of file