From c82f60e08b96245e57f44f2201311b41a6adcb2b Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 3 Jun 2019 01:09:06 -0700 Subject: [PATCH] Custom serializer for SkillCeiling --- .../gmail/nossr50/config/ConfigManager.java | 2 ++ .../config/hocon/CustomXPPerkSerializer.java | 2 +- .../config/hocon/SkillCeilingSerializer.java | 31 +++++++++++++++++++ .../config/hocon/skills/axes/ConfigAxes.java | 4 +-- .../axes/ConfigAxesCriticalStrikes.java | 6 ++-- ...onLevel.java => AbstractSkillCeiling.java} | 4 +-- ...rogressionLevel.java => SkillCeiling.java} | 2 +- 7 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/config/hocon/SkillCeilingSerializer.java rename src/main/java/com/gmail/nossr50/datatypes/skills/properties/{AbstractMaximumProgressionLevel.java => AbstractSkillCeiling.java} (70%) rename src/main/java/com/gmail/nossr50/datatypes/skills/properties/{MaximumProgressionLevel.java => SkillCeiling.java} (91%) diff --git a/src/main/java/com/gmail/nossr50/config/ConfigManager.java b/src/main/java/com/gmail/nossr50/config/ConfigManager.java index fc69be57d..e1242ab0b 100644 --- a/src/main/java/com/gmail/nossr50/config/ConfigManager.java +++ b/src/main/java/com/gmail/nossr50/config/ConfigManager.java @@ -49,6 +49,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.SkillCeiling; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; @@ -262,6 +263,7 @@ public final class ConfigManager { customSerializers.registerType(TypeToken.of(MinecraftMaterialWrapper.class), new MinecraftMaterialWrapperSerializer()); customSerializers.registerType(TypeToken.of(CustomXPPerk.class), new CustomXPPerkSerializer()); customSerializers.registerType(TypeToken.of(DamageProperty.class), new DamagePropertySerializer()); + customSerializers.registerType(TypeToken.of(SkillCeiling.class), new SkillCeilingSerializer()); } /** diff --git a/src/main/java/com/gmail/nossr50/config/hocon/CustomXPPerkSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/CustomXPPerkSerializer.java index 157d982e7..b8d152a78 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/CustomXPPerkSerializer.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/CustomXPPerkSerializer.java @@ -27,7 +27,7 @@ public class CustomXPPerkSerializer implements TypeSerializer { if (primarySkillType.isChildSkill()) continue; //Child skills gross - float boostValue = configurationNode.getNode("XP-Multiplier").getValue(TypeToken.of(Float.class)); + Float boostValue = configurationNode.getNode("XP-Multiplier").getValue(TypeToken.of(Float.class)); customXPPerk.setCustomXPValue(primarySkillType, boostValue); } catch (InvalidSkillException e) { mcMMO.p.getLogger().info("Custom XP perk has a skill defined that was not found, did you misspell it?"); diff --git a/src/main/java/com/gmail/nossr50/config/hocon/SkillCeilingSerializer.java b/src/main/java/com/gmail/nossr50/config/hocon/SkillCeilingSerializer.java new file mode 100644 index 000000000..2613e6ee5 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/config/hocon/SkillCeilingSerializer.java @@ -0,0 +1,31 @@ +package com.gmail.nossr50.config.hocon; + +import com.gmail.nossr50.datatypes.skills.properties.AbstractSkillCeiling; +import com.gmail.nossr50.datatypes.skills.properties.SkillCeiling; +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 SkillCeilingSerializer implements TypeSerializer { + + public static final String STANDARD_MAX_LEVEL = "Standard-Max-Level"; + public static final String RETRO_MAX_LEVEL = "Retro-Max-Level"; + + @Nullable + @Override + public SkillCeiling deserialize(@NonNull TypeToken type, @NonNull ConfigurationNode value) throws ObjectMappingException { + Integer standardCeiling = value.getNode(STANDARD_MAX_LEVEL).getValue(TypeToken.of(Integer.class)); + Integer retroCeiling = value.getNode(RETRO_MAX_LEVEL).getValue(TypeToken.of(Integer.class)); + AbstractSkillCeiling skillCeiling = new AbstractSkillCeiling(standardCeiling, retroCeiling); + return skillCeiling; + } + + @Override + public void serialize(@NonNull TypeToken type, @Nullable SkillCeiling obj, @NonNull ConfigurationNode value) throws ObjectMappingException { + value.getNode(STANDARD_MAX_LEVEL).setValue(obj.getStandardMaxLevel()); + value.getNode(RETRO_MAX_LEVEL).setValue(obj.getRetroMaxLevel()); + } +} diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxes.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxes.java index 753f9ac39..d7c3399bf 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxes.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxes.java @@ -1,6 +1,6 @@ package com.gmail.nossr50.config.hocon.skills.axes; -import com.gmail.nossr50.datatypes.skills.properties.AbstractMaximumProgressionLevel; +import com.gmail.nossr50.datatypes.skills.properties.AbstractSkillCeiling; import com.gmail.nossr50.datatypes.skills.properties.DamageProperty; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -28,7 +28,7 @@ public class ConfigAxes { return configAxesCriticalStrikes.getMaxActivationChance(); } - public AbstractMaximumProgressionLevel getCriticalStrikesMaximumProgressionLevel() { + public AbstractSkillCeiling getCriticalStrikesMaximumProgressionLevel() { return configAxesCriticalStrikes.getMaximumProgressionLevel(); } diff --git a/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxesCriticalStrikes.java b/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxesCriticalStrikes.java index 83a25c9b2..8ff334d36 100644 --- a/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxesCriticalStrikes.java +++ b/src/main/java/com/gmail/nossr50/config/hocon/skills/axes/ConfigAxesCriticalStrikes.java @@ -1,7 +1,7 @@ package com.gmail.nossr50.config.hocon.skills.axes; import com.gmail.nossr50.datatypes.skills.properties.AbstractDamageProperty; -import com.gmail.nossr50.datatypes.skills.properties.AbstractMaximumProgressionLevel; +import com.gmail.nossr50.datatypes.skills.properties.AbstractSkillCeiling; import com.gmail.nossr50.datatypes.skills.properties.DamageProperty; import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; @@ -17,7 +17,7 @@ public class ConfigAxesCriticalStrikes { @Setting(value = "Maximum-Level", comment = "This is the level at which full benefits for this skill will be reached." + "\nProperties of this skill may or may not scale with level, but those that do will gradually increase until max level is achieved.") - private AbstractMaximumProgressionLevel maximumProgressionLevel = new AbstractMaximumProgressionLevel(100, 1000); + private AbstractSkillCeiling maximumProgressionLevel = new AbstractSkillCeiling(100, 1000); @Setting(value = "Damage-Modifiers", comment = "Damage dealt is multiplied by these values when this skill is successfully activated.") private DamageProperty damageProperty = new AbstractDamageProperty(1.5, 2.0); @@ -26,7 +26,7 @@ public class ConfigAxesCriticalStrikes { return maxActivationChance; } - public AbstractMaximumProgressionLevel getMaximumProgressionLevel() { + public AbstractSkillCeiling getMaximumProgressionLevel() { return maximumProgressionLevel; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/properties/AbstractMaximumProgressionLevel.java b/src/main/java/com/gmail/nossr50/datatypes/skills/properties/AbstractSkillCeiling.java similarity index 70% rename from src/main/java/com/gmail/nossr50/datatypes/skills/properties/AbstractMaximumProgressionLevel.java rename to src/main/java/com/gmail/nossr50/datatypes/skills/properties/AbstractSkillCeiling.java index d573116d4..c1642c6c9 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/properties/AbstractMaximumProgressionLevel.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/properties/AbstractSkillCeiling.java @@ -1,11 +1,11 @@ package com.gmail.nossr50.datatypes.skills.properties; -public class AbstractMaximumProgressionLevel implements MaximumProgressionLevel { +public class AbstractSkillCeiling implements SkillCeiling { private int standardMaxLevel; private int retroMaxLevel; - public AbstractMaximumProgressionLevel(int standardMaxLevel, int retroMaxLevel) { + public AbstractSkillCeiling(int standardMaxLevel, int retroMaxLevel) { this.standardMaxLevel = standardMaxLevel; this.retroMaxLevel = retroMaxLevel; } diff --git a/src/main/java/com/gmail/nossr50/datatypes/skills/properties/MaximumProgressionLevel.java b/src/main/java/com/gmail/nossr50/datatypes/skills/properties/SkillCeiling.java similarity index 91% rename from src/main/java/com/gmail/nossr50/datatypes/skills/properties/MaximumProgressionLevel.java rename to src/main/java/com/gmail/nossr50/datatypes/skills/properties/SkillCeiling.java index d26553375..9c2c7662e 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/skills/properties/MaximumProgressionLevel.java +++ b/src/main/java/com/gmail/nossr50/datatypes/skills/properties/SkillCeiling.java @@ -4,7 +4,7 @@ package com.gmail.nossr50.datatypes.skills.properties; * Represents the level at which skill properties for this skill that scale based on level will reach their maximum benefits * If a player is this level or higher, they will have the full-power version of this skill */ -public interface MaximumProgressionLevel extends SkillProperty { +public interface SkillCeiling extends SkillProperty { /** * The maximum level for this skill in Retro * Defaults to 1000