Initial rudimentary implementation (not done) of PlotRegionBackups

This commit is contained in:
2026-03-08 08:19:46 +01:00
parent 12af4d0af1
commit 1d42f04e9a
4 changed files with 98 additions and 14 deletions
@@ -27,6 +27,7 @@ import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
public interface RegionBackups {
@@ -39,7 +40,6 @@ public interface RegionBackups {
public final int maxBackups;
}
@RequiredArgsConstructor
@Getter
abstract class Backup implements RegionDataStore, Comparable<Backup> {
@NonNull
@@ -49,7 +49,13 @@ public interface RegionBackups {
private final String name;
@NonNull
private final RegionData regionData;
protected final RegionData regionData;
protected Backup(@NonNull BackupType type, @NonNull String name, @NonNull Function<Backup, RegionData> regionDataConstructor) {
this.type = type;
this.name = name;
regionData = regionDataConstructor.apply(this);
}
@CheckReturnValue
public abstract boolean load();
@@ -73,7 +79,7 @@ public interface RegionBackups {
List<Backup> list();
@Nullable
Backup get(String name);
Backup get(@NonNull String name);
RegionBackups EMPTY = new RegionBackups() {
@Override
@@ -88,7 +94,7 @@ public interface RegionBackups {
@Nullable
@Override
public Backup get(String name) {
public Backup get(@NonNull String name) {
return null;
}
};
@@ -34,6 +34,7 @@ public abstract class RegionData {
private final List<Property<?, ?>> properties = new ArrayList<>();
protected final Map<Flag<?>, Flag.Value<?>> flagMap = new HashMap<>();
// TODO: These should be turned into an ECS like System because not every Region has them or should have them!
protected final Property<SchematicNode, Integer> testblockSchematic = new Property<>("testblockSchematic", SchematicNode::byId, SchematicNode::getId);
protected RegionData(RegionDataStore store) {
@@ -103,6 +104,18 @@ public abstract class RegionData {
});
}
/**
* This method only copies all flags and properties from this into other without saving other afterward.
*/
public final void copyInto(RegionData other) {
if (this == other) return;
other.flagMap.clear();
other.flagMap.putAll(flagMap);
// TODO: This might not be correct, needs to be investigated
other.properties.clear();
other.properties.addAll(properties);
}
public final Map<Flag<?>, Flag.Value<?>> getBackedMap() {
return flagMap;
}