forked from SteamWar/SteamWar
Implement more in PlotRegionBackups
This commit is contained in:
@@ -43,10 +43,10 @@ public interface RegionBackups {
|
|||||||
@Getter
|
@Getter
|
||||||
abstract class Backup implements RegionDataStore, Comparable<Backup> {
|
abstract class Backup implements RegionDataStore, Comparable<Backup> {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final BackupType type;
|
protected final BackupType type;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final String name;
|
protected final String name;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
protected final RegionData regionData;
|
protected final RegionData regionData;
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ public abstract class RegionData {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method only copies all flags and properties from this into other without saving other afterward.
|
* This method only copies all flags and properties from this into other without saving other afterward.
|
||||||
|
* TODO: If {@link #connectedRegions()} is overridden this method will not work correctly!
|
||||||
*/
|
*/
|
||||||
public final void copyInto(RegionData other) {
|
public final void copyInto(RegionData other) {
|
||||||
if (this == other) return;
|
if (this == other) return;
|
||||||
|
|||||||
+1
-1
@@ -290,7 +290,7 @@ public class DynamicRegionRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private static void deleteDir(File file) {
|
public static void deleteDir(File file) {
|
||||||
Files.walkFileTree(file.toPath(), new SimpleFileVisitor<>() {
|
Files.walkFileTree(file.toPath(), new SimpleFileVisitor<>() {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
|
|||||||
+8
-5
@@ -50,10 +50,13 @@ public class PasteUtils {
|
|||||||
editSession.close();
|
editSession.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void paste(File file, Point minPoint, int rotate) {
|
public static EditSession paste(File file, Point minPoint, int rotate) {
|
||||||
Clipboard clipboard = FlatteningWrapper.impl.loadSchematic(file);
|
try (Clipboard clipboard = FlatteningWrapper.impl.loadSchematic(file)) {
|
||||||
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin());
|
||||||
BlockVector3 to = minPoint.toBlockVector3().subtract(offset);
|
BlockVector3 to = minPoint.toBlockVector3().subtract(offset);
|
||||||
clipboard.paste(BukkitAdapter.adapt(Bukkit.getWorlds().get(0)), to, false, true, new AffineTransform().rotateY(rotate));
|
return clipboard.paste(BukkitAdapter.adapt(Bukkit.getWorlds().get(0)), to, false, true, new AffineTransform().rotateY(rotate));
|
||||||
|
} catch (SecurityException exception) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-6
@@ -19,15 +19,18 @@
|
|||||||
|
|
||||||
package de.steamwar.bausystem.region.dynamic.modes;
|
package de.steamwar.bausystem.region.dynamic.modes;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.EditSession;
|
||||||
import de.steamwar.bausystem.region.RegionBackups;
|
import de.steamwar.bausystem.region.RegionBackups;
|
||||||
import de.steamwar.bausystem.region.RegionData;
|
import de.steamwar.bausystem.region.RegionData;
|
||||||
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
import de.steamwar.bausystem.region.dynamic.DynamicRegion;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.DynamicRegionRepository;
|
||||||
|
import de.steamwar.bausystem.region.dynamic.PasteUtils;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class PlotRegionBackups implements RegionBackups {
|
public class PlotRegionBackups implements RegionBackups {
|
||||||
|
|
||||||
@@ -57,7 +60,7 @@ public class PlotRegionBackups implements RegionBackups {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create backup and save!
|
// Create backup and save!
|
||||||
Backup backup = new BackupImpl(backupType, "", regionDataConstructor);
|
Backup backup = new BackupImpl(this, backupType, "", regionDataConstructor, region);
|
||||||
// Create schematic and stuff?
|
// Create schematic and stuff?
|
||||||
backup.save();
|
backup.save();
|
||||||
backupList.add(backup);
|
backupList.add(backup);
|
||||||
@@ -70,7 +73,7 @@ public class PlotRegionBackups implements RegionBackups {
|
|||||||
return backups.values()
|
return backups.values()
|
||||||
.stream()
|
.stream()
|
||||||
.flatMap(List::stream)
|
.flatMap(List::stream)
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -85,13 +88,28 @@ public class PlotRegionBackups implements RegionBackups {
|
|||||||
|
|
||||||
private final class BackupImpl extends Backup {
|
private final class BackupImpl extends Backup {
|
||||||
|
|
||||||
public BackupImpl(@NonNull BackupType type, @NonNull String name, @NonNull Function<Backup, RegionData> regionDataConstructor) {
|
private static final String SCHEM_FILE = "backup.schem";
|
||||||
|
|
||||||
|
private final PlotRegionBackups parent;
|
||||||
|
private final File folder;
|
||||||
|
private final DynamicRegion region;
|
||||||
|
|
||||||
|
public BackupImpl(PlotRegionBackups parent, @NonNull BackupType type, @NonNull String name, @NonNull Function<Backup, RegionData> regionDataConstructor, DynamicRegion region) {
|
||||||
super(type, name, regionDataConstructor);
|
super(type, name, regionDataConstructor);
|
||||||
|
this.parent = parent;
|
||||||
|
folder = new File("");
|
||||||
|
this.region = region;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean load() {
|
public boolean load() {
|
||||||
throw new UnsupportedOperationException();
|
File file = new File(folder, SCHEM_FILE);
|
||||||
|
if (!file.exists()) return false;
|
||||||
|
EditSession editSession = PasteUtils.paste(file, region.getArea().getMinPoint(false), 0);
|
||||||
|
if (editSession == null) return false;
|
||||||
|
region.getHistory().remember(editSession);
|
||||||
|
regionData.copyInto(region.getRegionData());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,7 +119,9 @@ public class PlotRegionBackups implements RegionBackups {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete() {
|
public void delete() {
|
||||||
throw new UnsupportedOperationException();
|
parent.backups.getOrDefault(type, Collections.emptyList())
|
||||||
|
.remove(this);
|
||||||
|
DynamicRegionRepository.deleteDir(folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user