Custom Serializer for DamageProperty

This commit is contained in:
nossr50
2019-06-03 01:02:45 -07:00
parent 7a0ef0d4ed
commit 8c1c17fa17
5 changed files with 35 additions and 3 deletions

View File

@ -5,9 +5,9 @@ import com.gmail.nossr50.datatypes.party.PartyFeature;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.commands.CommandUtils;
import com.gmail.nossr50.util.player.UserManager;
import com.google.common.collect.ImmutableList;
import com.gmail.nossr50.util.commands.CommandUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;

View File

@ -48,6 +48,7 @@ import com.gmail.nossr50.datatypes.experience.CustomXPPerk;
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.mcMMO;
import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable;
@ -260,6 +261,7 @@ public final class ConfigManager {
customSerializers.registerType(TypeToken.of(Salvageable.class), new SalvageableSerializer());
customSerializers.registerType(TypeToken.of(MinecraftMaterialWrapper.class), new MinecraftMaterialWrapperSerializer());
customSerializers.registerType(TypeToken.of(CustomXPPerk.class), new CustomXPPerkSerializer());
customSerializers.registerType(TypeToken.of(DamageProperty.class), new DamagePropertySerializer());
}
/**

View File

@ -0,0 +1,31 @@
package com.gmail.nossr50.config.hocon;
import com.gmail.nossr50.datatypes.skills.properties.AbstractDamageProperty;
import com.gmail.nossr50.datatypes.skills.properties.DamageProperty;
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 DamagePropertySerializer implements TypeSerializer<DamageProperty> {
public static final String PVP_NODE = "PVP";
public static final String PVE_NODE = "PVE";
@Nullable
@Override
public DamageProperty deserialize(@NonNull TypeToken<?> type, @NonNull ConfigurationNode value) throws ObjectMappingException {
Float pvp = value.getNode(PVP_NODE).getValue(TypeToken.of(Float.class));
Float pve = value.getNode(PVE_NODE).getValue(TypeToken.of(Float.class));
DamageProperty damageProperty = new AbstractDamageProperty(pve, pvp);
return damageProperty;
}
@Override
public void serialize(@NonNull TypeToken<?> type, @Nullable DamageProperty obj, @NonNull ConfigurationNode value) throws ObjectMappingException {
value.getNode(PVP_NODE).setValue(obj.getPVPModifier());
value.getNode(PVE_NODE).setValue(obj.getPVEModifier());
}
}

View File

@ -1,6 +1,5 @@
package com.gmail.nossr50.config.hocon.skills.axes;
import com.gmail.nossr50.datatypes.skills.SubSkillType;
import com.gmail.nossr50.datatypes.skills.properties.AbstractDamageProperty;
import com.gmail.nossr50.datatypes.skills.properties.AbstractMaximumProgressionLevel;
import com.gmail.nossr50.datatypes.skills.properties.DamageProperty;