forked from SteamWar/SteamWar
Finish FixedFlagStorage
This commit is contained in:
+16
-1
@@ -24,8 +24,10 @@ import de.steamwar.bausystem.region.FlagStorage;
|
|||||||
import de.steamwar.bausystem.region.RegionFlagPolicy;
|
import de.steamwar.bausystem.region.RegionFlagPolicy;
|
||||||
import de.steamwar.bausystem.region.flags.Flag;
|
import de.steamwar.bausystem.region.flags.Flag;
|
||||||
import de.steamwar.bausystem.region.flags.TestblockMode;
|
import de.steamwar.bausystem.region.flags.TestblockMode;
|
||||||
|
import de.steamwar.bausystem.worlddata.WorldData;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
import yapion.hierarchy.types.YAPIONObject;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -34,9 +36,20 @@ public class FixedFlagStorage implements FlagStorage {
|
|||||||
|
|
||||||
private TestblockMode testBlockMode;
|
private TestblockMode testBlockMode;
|
||||||
private Map<Flag<?>, Flag.Value<?>> flagMap = new HashMap<>();
|
private Map<Flag<?>, Flag.Value<?>> flagMap = new HashMap<>();
|
||||||
|
private YAPIONObject data;
|
||||||
|
|
||||||
public FixedFlagStorage(TestblockMode testblockMode) {
|
public FixedFlagStorage(TestblockMode testblockMode, YAPIONObject data) {
|
||||||
this.testBlockMode = testblockMode;
|
this.testBlockMode = testblockMode;
|
||||||
|
this.data = data;
|
||||||
|
for (final Flag flag : Flag.getFlags()) {
|
||||||
|
if (!has(flag).isWritable()) continue;
|
||||||
|
try {
|
||||||
|
String s = data.getPlainValue(flag.name());
|
||||||
|
flagMap.put(flag, flag.valueOfValue(s));
|
||||||
|
} catch (Exception e) {
|
||||||
|
flagMap.put(flag, (Flag.Value<?>) flag.getDefaultValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,6 +69,8 @@ public class FixedFlagStorage implements FlagStorage {
|
|||||||
@Override
|
@Override
|
||||||
public <T extends Enum<T> & Flag.Value<T>> boolean set(@NonNull Flag<T> flag, @NonNull T value) {
|
public <T extends Enum<T> & Flag.Value<T>> boolean set(@NonNull Flag<T> flag, @NonNull T value) {
|
||||||
if (has(flag).isWritable()) {
|
if (has(flag).isWritable()) {
|
||||||
|
data.put(flag.name(), value.name());
|
||||||
|
WorldData.write();
|
||||||
return flagMap.put(flag, value) != value;
|
return flagMap.put(flag, value) != value;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user