From 3c3bc338f28bd99c47d6d4153842987a03985b55 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Fri, 7 Jun 2019 01:24:11 -0700 Subject: [PATCH] Add serializer for MaxBonusLevel --- .../gmail/nossr50/config/ConfigManager.java | 2 ++ .../serializers/MaxBonusLevelSerializer.java | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/serializers/MaxBonusLevelSerializer.java diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index 12448c19c..e6cde33e1 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -52,6 +52,7 @@ import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.party.PartyFeature; import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.properties.DamageProperty; +import com.gmail.nossr50.datatypes.skills.properties.MaxBonusLevel; import com.gmail.nossr50.datatypes.skills.properties.SkillCeiling; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.repair.repairables.Repairable; @@ -270,6 +271,7 @@ public final class ConfigManager { customSerializers.registerType(TypeToken.of(DamageProperty.class), new DamagePropertySerializer()); customSerializers.registerType(TypeToken.of(SkillCeiling.class), new SkillCeilingSerializer()); customSerializers.registerType(TypeToken.of(SkillRankProperty.class), new SkillRankPropertySerializer()); + customSerializers.registerType(TypeToken.of(MaxBonusLevel.class), new MaxBonusLevelSerializer()); } /** diff --git a/src/main/java/com/gmail/nossr50/config/hocon/serializers/MaxBonusLevelSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/serializers/MaxBonusLevelSerializer.java new file mode 100644 index 000000000..0322ce0ed --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/serializers/MaxBonusLevelSerializer.java @@ -0,0 +1,33 @@ +package com.gmail.nossr50.config.hocon.serializers; + +import com.gmail.nossr50.datatypes.skills.properties.AbstractMaxBonusLevel; +import com.gmail.nossr50.datatypes.skills.properties.MaxBonusLevel; +import com.google.common.reflect.TypeToken; +import ninja.leaping.configurate.ConfigurationNode; +import ninja.leaping.configurate.objectmapping.ObjectMappingException; +import ninja.leaping.configurate.objectmapping.serialize.TypeSerializer; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +public class MaxBonusLevelSerializer implements TypeSerializer { + + public static final String STANDARD_NODE = "Standard-Max-Bonus-Level"; + public static final String RETRO_NODE = "Retro-Max-Bonus-Level"; + + @Nullable + @Override + public MaxBonusLevel deserialize(@NonNull TypeToken type, @NonNull ConfigurationNode value) throws ObjectMappingException { + int standard = value.getNode(STANDARD_NODE).getValue(TypeToken.of(Integer.class)); + int retro = value.getNode(RETRO_NODE).getValue(TypeToken.of(Integer.class)); + + AbstractMaxBonusLevel maxBonusLevel = new AbstractMaxBonusLevel(standard, retro); + return maxBonusLevel; + } + + @Override + public void serialize(@NonNull TypeToken type, @Nullable MaxBonusLevel obj, @NonNull ConfigurationNode value) throws ObjectMappingException { + value.getNode(STANDARD_NODE).setValue(obj.getStandardScaleValue()); + value.getNode(RETRO_NODE).setValue(obj.getRetroScaleValue()); + } + +}