|
|
|
@ -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<ServerStarter.Version> versionTypeMapper() {
|
|
|
|
|
return new TypeMapper<ServerStarter.Version>() {
|
|
|
|
@ -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)
|
|
|
|
|