geforkt von SteamWar/BungeeCore
Merge pull request 'Added BuilderCloudCommand' (#414) from BuilderCloud into master
Reviewed-on: SteamWar/BungeeCore#414 Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Commit
143a9aed4a
@ -150,6 +150,7 @@ public class BungeeCore extends Plugin {
|
||||
new RankCommand();
|
||||
new LocalCommand();
|
||||
new SetLocaleCommand();
|
||||
new BuilderCloudCommand();
|
||||
|
||||
// Punishment Commands:
|
||||
new PunishmentCommand("ban", Punishment.PunishmentType.Ban);
|
||||
|
@ -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,6 +30,8 @@ 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 BUILDER_BASE_PATH = USER_HOME + "builder";
|
||||
|
||||
private File directory = null;
|
||||
private String worldDir = null;
|
||||
|
||||
@ -196,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;
|
||||
@ -287,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);
|
||||
}
|
||||
}
|
||||
}
|
121
src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java
Normale Datei
121
src/de/steamwar/bungeecore/commands/BuilderCloudCommand.java
Normale Datei
@ -0,0 +1,121 @@
|
||||
package de.steamwar.bungeecore.commands;
|
||||
|
||||
import de.steamwar.bungeecore.ServerStarter;
|
||||
import de.steamwar.command.SWCommand;
|
||||
import de.steamwar.command.TypeMapper;
|
||||
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, ServerStarter.Version> versionMap = new HashMap<>();
|
||||
|
||||
public BuilderCloudCommand() {
|
||||
super("buildercloud", "bungeecore.server.team");
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Register(description = "BUILDERCLOUD_USAGE")
|
||||
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)
|
||||
@Mapper(value = "map", local = true)
|
||||
private TypeMapper<String> mapTypeMapper() {
|
||||
|
||||
return new TypeMapper<String>() {
|
||||
@Override
|
||||
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.mkdir())
|
||||
return null;
|
||||
|
||||
return map.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> tabCompletes(CommandSender sender, String[] previousArguments, String s) {
|
||||
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;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
@ -629,4 +629,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
|
||||
LOCK_LOCALE_CHANGED=§aLanguage saved
|
||||
|
||||
#Builder Cloud
|
||||
BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eversion§8] §8[§emap§8] §8<§7generator§8>
|
||||
BUILDERCLOUD_VERSION=§cUnknown version.
|
@ -607,4 +607,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
|
||||
LOCK_LOCALE_CHANGED=§aSprache gespeichert
|
||||
|
||||
#Builder Cloud
|
||||
BUILDERCLOUD_USAGE=§8/§7buildercloud §8[§eVersion§8] §8[§eWelt§8] §8<§7Generator§8>
|
||||
BUILDERCLOUD_VERSION=§cUnbekannte Version.
|
In neuem Issue referenzieren
Einen Benutzer sperren