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
BACKUP_REGION_NO_REGION=§cDu bist in keiner Region BACKUP_REGION_NO_REGION=§cDu bist in keiner Region
BACKUP_NO_PERMS=§cDu darfst hier nicht das Backup System verwenden BACKUP_NO_PERMS=§cDu darfst hier nicht das Backup System verwenden
BACKUP_SUCCESS=§7Das Backup wurde erstellt BACKUP_CREATE_SUCCESS=§7Das Backup wurde erstellt
BACKUP_FAILURE=§cDas Backup erstellen ist schiefgegangen BACKUP_CREATE_FAILURE=§cDas Backup erstellen ist schiefgegangen
BACKUP_NO_CHANGE=§7Die Region hat keine Veränderung 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
BAU_COMMAND_HELP1 = §8/§ebau togglewe §8[§7Player§8] §8- §7Editiere die WorldEdit Rechte eines Spielers 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.SWCommand;
import de.steamwar.command.SWCommandUtils; import de.steamwar.command.SWCommandUtils;
import de.steamwar.command.TypeMapper; import de.steamwar.command.TypeMapper;
import net.md_5.bungee.api.chat.ClickEvent;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -71,13 +73,13 @@ public class BackupCommand extends SWCommand {
return; return;
} }
if (!region.get(Tag.CHANGED)) { if (!region.get(Tag.CHANGED)) {
BauSystem.MESSAGE.send("BACKUP_NO_CHANGE", p); BauSystem.MESSAGE.send("BACKUP_CREATE_NO_CHANGE", p);
return; return;
} }
if (region.backup()) { if (region.backup()) {
BauSystem.MESSAGE.send("BACKUP_SUCCESS", p); BauSystem.MESSAGE.send("BACKUP_CREATE_SUCCESS", p);
} else { } 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)) { if (checkGlobalRegion(region, p)) {
return; 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") @Register("list")
@ -97,17 +106,18 @@ public class BackupCommand extends SWCommand {
if (checkGlobalRegion(region, p)) { if (checkGlobalRegion(region, p)) {
return; return;
} }
listbackup(p).forEach(s -> { BauSystem.MESSAGE.send("BACKUP_LIST_HEAD", p);
p.sendMessage("HERE: " + s); 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) @Mapper(value = "backupName", local = true)
public TypeMapper<String> backupMapper() { 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()); Region region = Region.getRegion(p.getLocation());
if (checkGlobalRegion(region, p)) { if (checkGlobalRegion(region, p)) {
return Collections.emptyList(); return Collections.emptyList();

Datei anzeigen

@ -370,6 +370,12 @@ public class Region {
reset(schematic, regionType, regionExtensionType, false); 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 { public void reset(Schematic schematic, RegionType regionType, RegionExtensionType regionExtensionType, boolean ignoreAir) throws IOException {
if (!hasReset(regionType)) { if (!hasReset(regionType)) {
return; return;
@ -485,4 +491,13 @@ public class Region {
definedBackupFolder.mkdirs(); definedBackupFolder.mkdirs();
return Arrays.asList(Objects.requireNonNull(definedBackupFolder.list((dir, name) -> name.endsWith(".schem")))); 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];
}
} }