SteamWar/BauSystem2.0
Archiviert
12
0
Dieser Commit ist enthalten in:
Zeanon 2021-04-18 16:32:52 +02:00
Ursprung c39eb4dda6
Commit 2a29835ecb
2 geänderte Dateien mit 10 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -46,7 +46,7 @@ dependencies {
implementation project(":BauSystem_15") implementation project(":BauSystem_15")
implementation project(":BauSystem_API") implementation project(":BauSystem_API")
implementation 'yoyosource:YAPION:0.25.0' implementation 'yoyosource:YAPION:0.25.1'
compileOnly 'org.projectlombok:lombok:1.18.6' compileOnly 'org.projectlombok:lombok:1.18.6'
testCompileOnly 'org.projectlombok:lombok:1.18.6' testCompileOnly 'org.projectlombok:lombok:1.18.6'

Datei anzeigen

@ -25,24 +25,24 @@ import de.steamwar.bausystem.region.flags.Flag;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import yapion.annotations.object.YAPIONData;
import yapion.hierarchy.api.groups.YAPIONAnyType;
import yapion.hierarchy.types.YAPIONObject;
import yapion.hierarchy.types.YAPIONValue;
@YAPIONData
public class FlagStorage { public class FlagStorage {
protected final Map<Flag, Flag.Value<?>> flags; protected final Map<Flag, Flag.Value<?>> flags;
protected final JsonObject jsonObject;
public FlagStorage(final JsonObject jsonObject) { public FlagStorage() {
flags = new EnumMap<>(Flag.class); flags = new EnumMap<>(Flag.class);
this.jsonObject = jsonObject;
readKeys(); readKeys();
} }
public boolean set(final Flag flagType, final Flag.Value<?> value) { public boolean set(final Flag flagType, final Flag.Value<?> value) {
if (flags.put(flagType, value) != value) { return flags.put(flagType, value) != value;
writeChangedKey(flagType, value);
return true;
}
return false;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -52,12 +52,7 @@ public class FlagStorage {
private void readKeys() { private void readKeys() {
for (final Flag flag : Flag.getFlags()) { for (final Flag flag : Flag.getFlags()) {
final JsonPrimitive flagValue = jsonObject.getAsJsonPrimitive(flag.name().toLowerCase()); flags.put(flag, flag.getDefaultValue());
flags.put(flag, flagValue == null ? flag.getDefaultValue() : flag.getFlagValueOf(flagValue.getAsString().toUpperCase()));
} }
} }
private void writeChangedKey(Flag flag, Flag.Value<?> value) {
jsonObject.add(flag.name().toLowerCase(), new JsonPrimitive(value.getValue().getName()));
}
} }