Added BuilderCloudCommand #414
@ -7,7 +7,9 @@ import de.steamwar.bungeecore.sql.Tutorial;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Files;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.function.BooleanSupplier;
|
||||
@ -28,8 +30,7 @@ public class ServerStarter {
|
||||
public static final String WORLDS15_PATH = USER_HOME + "userworlds15/";
|
||||
public static final String WORLDS19_PATH = USER_HOME + "userworlds19/";
|
||||
|
||||
public static final String BUILDER15_PATH = BACKBONE + "builder15/";
|
||||
public static final String BUILDER19_PATH = BACKBONE + "builder19/";
|
||||
public static final String BUILDER_BASE_PATH = USER_HOME + "builder";
|
||||
|
||||
private File directory = null;
|
||||
private String worldDir = null;
|
||||
@ -51,14 +52,6 @@ public class ServerStarter {
|
||||
private final Set<ProxiedPlayer> playersToSend = new HashSet<>();
|
||||
private final Map<String, String> 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);
|
||||
@ -207,6 +200,40 @@ public class ServerStarter {
|
||||
serverNameProvider = port -> bauServerName(SteamwarUser.get(owner));
|
||||
}
|
||||
|
||||
public ServerStarter builder(Version version, String map, File generator) {
|
||||
serverJar = version.getServerJar();
|
||||
directory = version.getServerDirectory("Builder");
|
||||
worldDir = version.getWorldFolder(BUILDER_BASE_PATH);
|
||||
worldName = map;
|
||||
serverNameProvider = port -> "⛏" + map;
|
||||
constructor = (serverName, port, builder, shutdownCallback) -> new Builderserver(serverName, worldName, port, builder, shutdownCallback);
|
||||
|
||||
// Send players to existing server
|
||||
startCondition = () -> {
|
||||
for(Subserver subserver : Subserver.getServerList()) {
|
||||
if(subserver.getType() == Servertype.BUILDER && ((Builderserver)subserver).getMap().equals(worldName)) {
|
||||
for(ProxiedPlayer p : playersToSend)
|
||||
SubserverSystem.sendPlayer(subserver, p);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
if(generator != null) {
|
||||
worldSetup = () -> {
|
||||
File leveldat = new File(new File(worldDir, worldName), "level.dat");
|
||||
try {
|
||||
Files.copy(generator.toPath(), leveldat.toPath());
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServerStarter send(ProxiedPlayer player) {
|
||||
playersToSend.add(player);
|
||||
return this;
|
||||
@ -298,4 +325,30 @@ public class ServerStarter {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Version {
|
||||
SPIGOT_12("spigot-1.12.2.jar", 12),
|
||||
SPIGOT_15("spigot-1.15.2.jar", 15),
|
||||
PAPER_19("paper-1.19.2.jar", 19);
|
||||
|
||||
private final String serverJar;
|
||||
private final int versionSuffix;
|
||||
|
||||
Version(String serverJar, int versionSuffix) {
|
||||
this.serverJar = serverJar;
|
||||
this.versionSuffix = versionSuffix;
|
||||
}
|
||||
|
||||
public String getServerJar() {
|
||||
return serverJar;
|
||||
}
|
||||
|
||||
public String getWorldFolder(String base) {
|
||||
return base + versionSuffix + "/";
|
||||
}
|
||||
|
||||
public File getServerDirectory(String base) {
|
||||
return new File(SERVER_PATH, base + versionSuffix);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,70 +3,119 @@ 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.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BuilderCloudCommand extends SWCommand {
|
||||
|
||||
private final Map<String, String> versionMap = new HashMap<>();
|
||||
private final Map<String, String> pathMap = new HashMap<>();
|
||||
private final Map<String, ServerStarter.Version> versionMap = 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);
|
||||
versionMap.put("15", ServerStarter.Version.SPIGOT_15);
|
||||
versionMap.put("1.15", ServerStarter.Version.SPIGOT_15);
|
||||
versionMap.put("1.15.2", ServerStarter.Version.SPIGOT_15);
|
||||
versionMap.put("19", ServerStarter.Version.PAPER_19);
|
||||
versionMap.put("1.19", ServerStarter.Version.PAPER_19);
|
||||
versionMap.put("1.19.2", ServerStarter.Version.PAPER_19);
|
||||
}
|
||||
|
||||
// /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();
|
||||
public void genericCommand(ProxiedPlayer player, @ErrorMessage("BUILDERCLOUD_VERSION") ServerStarter.Version version, @Mapper("map") String map, @OptionalValue("") @Mapper("generator") Optional<File> generator) {
|
||||
new ServerStarter().builder(version, map, generator.orElse(null)).send(player).start();
|
||||
}
|
||||
|
||||
@ClassMapper(value = ServerStarter.Version.class, local = true)
|
||||
private TypeMapper<ServerStarter.Version> versionTypeMapper() {
|
||||
return new TypeMapper<ServerStarter.Version>() {
|
||||
@Override
|
||||
public ServerStarter.Version map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
return versionMap.get(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
||||
return versionMap.keySet().stream().filter(key -> key.startsWith(s)).collect(Collectors.toList());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Cached(global = true)
|
||||
@ClassMapper(value = File.class, local = true)
|
||||
private TypeMapper<File> mapTypeMapper() {
|
||||
@Mapper(value = "map", local = true)
|
||||
private TypeMapper<String> mapTypeMapper() {
|
||||
|
||||
return new TypeMapper<File>() {
|
||||
return new TypeMapper<String>() {
|
||||
@Override
|
||||
public File map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
String folder = pathMap.get(previousArguments[previousArguments.length - 1]);
|
||||
public String map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
File folder = getWorldFolder(previousArguments, 1);
|
||||
|
||||
if(folder == null)
|
||||
return null;
|
||||
|
||||
File map = new File(folder, s);
|
||||
if(!map.exists() || !map.isDirectory())
|
||||
if(!map.exists() && !map.mkdir())
|
||||
return null;
|
||||
|
||||
return map;
|
||||
return map.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
||||
String folder = pathMap.get(previousArguments[previousArguments.length - 1]);
|
||||
File folder = getWorldFolder(previousArguments, 1);
|
||||
|
||||
String[] files;
|
||||
if(folder == null || (files = folder.list()) == null)
|
||||
return Collections.emptyList();
|
||||
|
||||
return Arrays.stream(files).filter(file -> new File(folder, file).isDirectory()).collect(Collectors.toList());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Cached(global = true)
|
||||
@Mapper(value = "generator", local = true)
|
||||
private TypeMapper<Optional<File>> generatorTypeMapper() {
|
||||
|
||||
return new TypeMapper<Optional<File>>() {
|
||||
@Override
|
||||
public Optional<File> map(CommandSender commandSender, String[] previousArguments, String s) {
|
||||
if(s.equals(""))
|
||||
return Optional.empty();
|
||||
|
||||
File folder = getWorldFolder(previousArguments, 2);
|
||||
|
||||
if(folder == null)
|
||||
return null;
|
||||
|
||||
return Arrays.asList(Objects.requireNonNull(new File(folder).list()));
|
||||
File generator = new File(folder, s + ".dat");
|
||||
if(!generator.exists() || !generator.isFile())
|
||||
return null;
|
||||
|
||||
return Optional.of(generator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
||||
File folder = getWorldFolder(previousArguments, 2);
|
||||
|
||||
String[] files;
|
||||
if(folder == null || (files = folder.list()) == null)
|
||||
return Collections.emptyList();
|
||||
|
||||
return Arrays.stream(files).filter(file -> new File(folder, file).isFile()).filter(file -> file.endsWith(".dat")).map(file -> file.substring(0, file.length() - 4)).collect(Collectors.toList());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private File getWorldFolder(String[] previousArguments, int offset) {
|
||||
ServerStarter.Version v = versionMap.get(previousArguments[previousArguments.length - offset]);
|
||||
if(v == null)
|
||||
return null;
|
||||
return new File(v.getWorldFolder(ServerStarter.BUILDER_BASE_PATH));
|
||||
}
|
||||
}
|
||||
|
@ -632,5 +632,5 @@ 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]
|
||||
BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] §8<§7generator§8>
|
||||
BUILDERCLOUD_VERSION=§cUnknown version.
|
@ -610,5 +610,5 @@ 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]
|
||||
BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] §8<§7Generator§8>
|
||||
BUILDERCLOUD_VERSION=§cUnbekannte Version.
|
In neuem Issue referenzieren
Einen Benutzer sperren