SteamWar/BauSystem2.0
Archiviert
12
0

Add BackupCommand

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-07-10 18:12:30 +02:00
Ursprung 859ddc0a3a
Commit dff8909925
3 geänderte Dateien mit 40 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -102,9 +102,13 @@ AUTOSTART_MESSAGE_RESULT3 = §7Positiv, wenn zu wenig, negativ wenn zu viel
# Backup
BACKUP_REGION_NO_REGION=§cDu bist in keiner Region
BACKUP_NO_PERMS=§cDu darfst hier nicht das Backup System verwenden
BACKUP_SUCCESS=§7Das Backup wurde erstellt
BACKUP_FAILURE=§cDas Backup erstellen ist schiefgegangen
BACKUP_NO_CHANGE=§7Die Region hat keine Veränderung
BACKUP_CREATE_SUCCESS=§7Das Backup wurde erstellt
BACKUP_CREATE_FAILURE=§cDas Backup erstellen ist schiefgegangen
BACKUP_CREATE_NO_CHANGE=§7Die Region hat keine Veränderung
BACKUP_LIST_HEAD=§7---=== (§eBackup§7) ===---
BACKUP_LIST_ENTRY=§7{0} §e[Laden]
BACKUP_LOAD_FAILURE=§cDas Backup laden ist schiefgegangen
BACKUP_LOAD=§7Backup geladen
# Bau
BAU_COMMAND_HELP1 = §8/§ebau togglewe §8[§7Player§8] §8- §7Editiere die WorldEdit Rechte eines Spielers

Datei anzeigen

@ -28,8 +28,10 @@ import de.steamwar.bausystem.region.tags.Tag;
import de.steamwar.command.SWCommand;
import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@ -71,13 +73,13 @@ public class BackupCommand extends SWCommand {
return;
}
if (!region.get(Tag.CHANGED)) {
BauSystem.MESSAGE.send("BACKUP_NO_CHANGE", p);
BauSystem.MESSAGE.send("BACKUP_CREATE_NO_CHANGE", p);
return;
}
if (region.backup()) {
BauSystem.MESSAGE.send("BACKUP_SUCCESS", p);
BauSystem.MESSAGE.send("BACKUP_CREATE_SUCCESS", p);
} else {
BauSystem.MESSAGE.send("BACKUP_FAILURE", p);
BauSystem.MESSAGE.send("BACKUP_CREATE_FAILURE", p);
}
}
@ -88,7 +90,14 @@ public class BackupCommand extends SWCommand {
if (checkGlobalRegion(region, p)) {
return;
}
System.out.println(backupName);
File backupFile = region.getBackupFile(backupName);
if (backupFile == null) {
BauSystem.MESSAGE.send("BACKUP_LOAD_FAILURE", p);
return;
}
region.reset(backupFile);
BauSystem.MESSAGE.send("BACKUP_LOAD", p);
}
@Register("list")
@ -97,17 +106,18 @@ public class BackupCommand extends SWCommand {
if (checkGlobalRegion(region, p)) {
return;
}
listbackup(p).forEach(s -> {
p.sendMessage("HERE: " + s);
BauSystem.MESSAGE.send("BACKUP_LIST_HEAD", p);
listBackup(p).forEach(s -> {
BauSystem.MESSAGE.send("BACKUP_LIST_ENTRY", p, "/backup load " + s, new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/backup load " + s), s);
});
}
@Mapper(value = "backupName", local = true)
public TypeMapper<String> backupMapper() {
return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listbackup((Player) commandSender));
return SWCommandUtils.createMapper(s -> s, (commandSender, s) -> listBackup((Player) commandSender));
}
private List<String> listbackup(Player p) {
private List<String> listBackup(Player p) {
Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) {
return Collections.emptyList();

Datei anzeigen

@ -370,6 +370,12 @@ public class Region {
reset(schematic, regionType, regionExtensionType, false);
}
public void reset(File file) {
EditSession editSession = paste(file, minPoint.add(prototype.getSizeX() / 2, 0, prototype.getSizeZ() / 2), new PasteOptions(false, false, Color.YELLOW, true, getMinPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), getMaxPoint(RegionType.NORMAL, RegionExtensionType.NORMAL), waterLevel));
initSessions();
undoSessions.push(editSession);
}
public void reset(Schematic schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException {
if (!hasReset(regionType)) {
return;
@ -485,4 +491,13 @@ public class Region {
definedBackupFolder.mkdirs();
return Arrays.asList(Objects.requireNonNull(definedBackupFolder.list((dir, name) -> name.endsWith(".schem"))));
}
public File getBackupFile(String backupName) {
final File definedBackupFolder = new File(new File(backupFolder, prototype.getName()), name);
//noinspection ResultOfMethodCallIgnored
definedBackupFolder.mkdirs();
File[] files = definedBackupFolder.listFiles((dir, name) -> name.equals(backupName + ".schem"));
if (files == null || files.length == 0) return null;
return files[0];
}
}