FlagStorage?
Dieser Commit ist enthalten in:
Ursprung
c39eb4dda6
Commit
2a29835ecb
@ -46,7 +46,7 @@ dependencies {
|
||||
implementation project(":BauSystem_15")
|
||||
implementation project(":BauSystem_API")
|
||||
|
||||
implementation 'yoyosource:YAPION:0.25.0'
|
||||
implementation 'yoyosource:YAPION:0.25.1'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.6'
|
||||
testCompileOnly 'org.projectlombok:lombok:1.18.6'
|
||||
|
@ -25,24 +25,24 @@ import de.steamwar.bausystem.region.flags.Flag;
|
||||
|
||||
import java.util.EnumMap;
|
||||
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 {
|
||||
|
||||
protected final Map<Flag, Flag.Value<?>> flags;
|
||||
protected final JsonObject jsonObject;
|
||||
|
||||
public FlagStorage(final JsonObject jsonObject) {
|
||||
public FlagStorage() {
|
||||
flags = new EnumMap<>(Flag.class);
|
||||
this.jsonObject = jsonObject;
|
||||
readKeys();
|
||||
}
|
||||
|
||||
public boolean set(final Flag flagType, final Flag.Value<?> value) {
|
||||
if (flags.put(flagType, value) != value) {
|
||||
writeChangedKey(flagType, value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return flags.put(flagType, value) != value;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -52,12 +52,7 @@ public class FlagStorage {
|
||||
|
||||
private void readKeys() {
|
||||
for (final Flag flag : Flag.getFlags()) {
|
||||
final JsonPrimitive flagValue = jsonObject.getAsJsonPrimitive(flag.name().toLowerCase());
|
||||
flags.put(flag, flagValue == null ? flag.getDefaultValue() : flag.getFlagValueOf(flagValue.getAsString().toUpperCase()));
|
||||
flags.put(flag, flag.getDefaultValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeChangedKey(Flag flag, Flag.Value<?> value) {
|
||||
jsonObject.add(flag.name().toLowerCase(), new JsonPrimitive(value.getValue().getName()));
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren