forked from SteamWar/SteamWar
Improve API of RegionDataStore, RegionBackups.Backup
This commit is contained in:
@@ -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() {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user