Improve API of RegionDataStore, RegionBackups.Backup

This commit is contained in:
2026-03-01 14:05:33 +01:00
parent 92630f4e10
commit 327ea9351a
8 changed files with 38 additions and 37 deletions
@@ -54,14 +54,16 @@ public interface RegionBackups {
@CheckReturnValue
public abstract boolean load();
public abstract void delete();
public abstract long getCreationTime();
@Override
public int compareTo(Backup o) {
return Long.compare(getCreationTime(), o.getCreationTime());
}
@SuppressWarnings("java:S3038") // This forces everybody to implement 'deleteRegion' for Backups!
@Override
public abstract void deleteRegion();
}
@CheckReturnValue
@@ -41,12 +41,12 @@ public abstract class RegionData {
protected RegionData(RegionDataStore store) {
this.store = store;
initialize();
store.loadRegionData(this);
store.loadRegion();
}
public final void setStore(RegionDataStore store) {
this.store = store;
store.saveRegionData(this);
store.saveRegion();
}
protected void initialize() {
@@ -61,7 +61,7 @@ public abstract class RegionData {
public final <T extends Enum<T> & Flag.Value<T>> boolean set(@NonNull Flag<T> flag, @NonNull T value) {
if (has(flag).isWritable()) {
if (flagMap.put(flag, value) != value) {
store.saveRegionData(this);
store.saveRegion();
return true;
}
}
@@ -80,7 +80,7 @@ public abstract class RegionData {
}
}
properties.forEach(property -> property.set(null));
store.saveRegionData(this);
store.saveRegion();
}
public final Map<Flag<?>, Flag.Value<?>> getBackedMap() {
@@ -97,7 +97,7 @@ public abstract class RegionData {
public final void setTestblockSchematic(SchematicNode schematic) {
testblockSchematic.set(schematic);
store.saveRegionData(this);
store.saveRegion();
}
@Override
@@ -19,9 +19,9 @@
package de.steamwar.bausystem.region;
import lombok.NonNull;
public interface RegionDataStore {
void saveRegionData(@NonNull RegionData regionData);
void loadRegionData(@NonNull RegionData regionData);
void saveRegion();
void loadRegion();
default void deleteRegion() {
}
}