SteamWar/BauSystem2.0
Archiviert
12
0

Fix Region.linkedRegion

Dieser Commit ist enthalten in:
yoyosource 2021-04-19 20:33:15 +02:00
Ursprung cf551cdbab
Commit a36267a14e

Datei anzeigen

@ -38,6 +38,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Predicate;
@Getter @Getter
public class Region { public class Region {
@ -92,9 +93,7 @@ public class Region {
REGION_LIST.add(this); REGION_LIST.add(this);
} }
if (regionConfig.containsKey("linkedWith")) { linkedRegionName = regionConfig.getPlainValueOrDefault("optionsLinkedWith", null);
linkedRegionName = regionConfig.getPlainValue("linkedWith");
}
prototypes = new HashSet<>(); prototypes = new HashSet<>();
if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) { if (regionConfig.containsKey("prototypes", YAPIONType.ARRAY)) {
@ -199,18 +198,24 @@ public class Region {
return prototype != null ? prototype.getDisplayName() : ""; return prototype != null ? prototype.getDisplayName() : "";
} }
private void setLinkedRegion(Consumer<Region> regionConsumer) { private void setLinkedRegion(Predicate<Region> regionConsumer) {
if (linkedRegionName == null) { if (linkedRegionName == null) {
return; return;
} }
if (linkedRegion != null) { if (linkedRegion != null) {
regionConsumer.accept(linkedRegion); if (regionConsumer.test(linkedRegion)) {
linkedRegion.regionData.add("flagStorage", FlagStorage.toYAPION(linkedRegion.flagStorage));
RegionLoader.save();
}
return; return;
} }
for (Region region : REGION_LIST) { for (Region region : REGION_LIST) {
if (region.name.equals(name)) { if (region.name.equals(linkedRegionName)) {
linkedRegion = region; linkedRegion = region;
regionConsumer.accept(linkedRegion); if (regionConsumer.test(linkedRegion)) {
linkedRegion.regionData.add("flagStorage", FlagStorage.toYAPION(linkedRegion.flagStorage));
RegionLoader.save();
}
return; return;
} }
} }
@ -220,11 +225,15 @@ public class Region {
if (this.prototype == null) { if (this.prototype == null) {
return; return;
} }
if (!prototypes.contains(prototype)) {
return;
}
regionData.add("prototype", prototype.getName()); regionData.add("prototype", prototype.getName());
generatePrototypeData(prototype, minPoint); generatePrototypeData(prototype, minPoint);
setLinkedRegion(region -> { setLinkedRegion(region -> {
region.regionData.add("prototype", prototype.getName()); region.regionData.add("prototype", prototype.getName());
region.generatePrototypeData(prototype, region.minPoint); region.generatePrototypeData(prototype, region.minPoint);
return true;
}); });
} }
@ -233,7 +242,7 @@ public class Region {
regionData.add("flagStorage", FlagStorage.toYAPION(flagStorage)); regionData.add("flagStorage", FlagStorage.toYAPION(flagStorage));
RegionLoader.save(); RegionLoader.save();
} }
setLinkedRegion(region -> region.set(flagType, value)); setLinkedRegion(region -> region.flagStorage.set(flagType, value));
} }
public <T extends Enum<T> & Flag.Value<T>> Flag.Value<T> get(Flag flagType) { public <T extends Enum<T> & Flag.Value<T>> Flag.Value<T> get(Flag flagType) {