Fix trait serialization. Fixes #342

This commit is contained in:
Sollace 2024-05-16 20:31:42 +01:00
parent 89196c1adc
commit f0b57a2bbf
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 6 additions and 2 deletions

View file

@ -319,7 +319,7 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
public static Stream<Map.Entry<Trait, Float>> streamFromJson(JsonObject traits) {
return traits.entrySet().stream().map(entry -> {
Trait trait = Trait.fromName(entry.getKey()).orElse(null);
Trait trait = Trait.fromId(entry.getKey()).orElse(null);
if (trait == null || !entry.getValue().isJsonPrimitive() && !entry.getValue().getAsJsonPrimitive().isNumber()) {
return null;
}

View file

@ -164,7 +164,11 @@ public enum Trait implements CommandArgumentEnum<Trait> {
}
public static Optional<Trait> fromName(String name) {
return Optional.ofNullable(REGISTRY.getOrDefault(name.toUpperCase(), null));
Trait trait = REGISTRY.getOrDefault(name.toUpperCase(), null);
if (trait == null) {
Unicopia.LOGGER.error("Unknown trait: " + name);
}
return Optional.ofNullable(trait);
}
public static EnumArgumentType<Trait> argument() {