Add serializer for MaxBonusLevel

This commit is contained in:
nossr50 2019-06-07 01:24:11 -07:00
parent 80beb92a06
commit 3c3bc338f2
2 changed files with 35 additions and 0 deletions

View File

@ -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());
}
/**

View File

@ -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<MaxBonusLevel> {
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());
}
}