Custom serializer for SkillCeiling

This commit is contained in:
nossr50 2019-06-03 01:09:06 -07:00
parent 8c1c17fa17
commit c82f60e08b
7 changed files with 42 additions and 9 deletions

View File

@ -49,6 +49,7 @@ import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.party.PartyFeature; import com.gmail.nossr50.datatypes.party.PartyFeature;
import com.gmail.nossr50.datatypes.skills.PrimarySkillType; import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import com.gmail.nossr50.datatypes.skills.properties.DamageProperty; 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.mcMMO;
import com.gmail.nossr50.skills.repair.repairables.Repairable; import com.gmail.nossr50.skills.repair.repairables.Repairable;
import com.gmail.nossr50.skills.salvage.salvageables.Salvageable; 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(MinecraftMaterialWrapper.class), new MinecraftMaterialWrapperSerializer());
customSerializers.registerType(TypeToken.of(CustomXPPerk.class), new CustomXPPerkSerializer()); customSerializers.registerType(TypeToken.of(CustomXPPerk.class), new CustomXPPerkSerializer());
customSerializers.registerType(TypeToken.of(DamageProperty.class), new DamagePropertySerializer()); customSerializers.registerType(TypeToken.of(DamageProperty.class), new DamagePropertySerializer());
customSerializers.registerType(TypeToken.of(SkillCeiling.class), new SkillCeilingSerializer());
} }
/** /**

View File

@ -27,7 +27,7 @@ public class CustomXPPerkSerializer implements TypeSerializer<CustomXPPerk> {
if (primarySkillType.isChildSkill()) if (primarySkillType.isChildSkill())
continue; //Child skills gross 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); customXPPerk.setCustomXPValue(primarySkillType, boostValue);
} catch (InvalidSkillException e) { } catch (InvalidSkillException e) {
mcMMO.p.getLogger().info("Custom XP perk has a skill defined that was not found, did you misspell it?"); mcMMO.p.getLogger().info("Custom XP perk has a skill defined that was not found, did you misspell it?");

View File

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

View File

@ -1,6 +1,6 @@
package com.gmail.nossr50.config.hocon.skills.axes; 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 com.gmail.nossr50.datatypes.skills.properties.DamageProperty;
import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
@ -28,7 +28,7 @@ public class ConfigAxes {
return configAxesCriticalStrikes.getMaxActivationChance(); return configAxesCriticalStrikes.getMaxActivationChance();
} }
public AbstractMaximumProgressionLevel getCriticalStrikesMaximumProgressionLevel() { public AbstractSkillCeiling getCriticalStrikesMaximumProgressionLevel() {
return configAxesCriticalStrikes.getMaximumProgressionLevel(); return configAxesCriticalStrikes.getMaximumProgressionLevel();
} }

View File

@ -1,7 +1,7 @@
package com.gmail.nossr50.config.hocon.skills.axes; package com.gmail.nossr50.config.hocon.skills.axes;
import com.gmail.nossr50.datatypes.skills.properties.AbstractDamageProperty; 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 com.gmail.nossr50.datatypes.skills.properties.DamageProperty;
import ninja.leaping.configurate.objectmapping.Setting; import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; 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." + @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.") "\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.") @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); private DamageProperty damageProperty = new AbstractDamageProperty(1.5, 2.0);
@ -26,7 +26,7 @@ public class ConfigAxesCriticalStrikes {
return maxActivationChance; return maxActivationChance;
} }
public AbstractMaximumProgressionLevel getMaximumProgressionLevel() { public AbstractSkillCeiling getMaximumProgressionLevel() {
return maximumProgressionLevel; return maximumProgressionLevel;
} }

View File

@ -1,11 +1,11 @@
package com.gmail.nossr50.datatypes.skills.properties; package com.gmail.nossr50.datatypes.skills.properties;
public class AbstractMaximumProgressionLevel implements MaximumProgressionLevel { public class AbstractSkillCeiling implements SkillCeiling {
private int standardMaxLevel; private int standardMaxLevel;
private int retroMaxLevel; private int retroMaxLevel;
public AbstractMaximumProgressionLevel(int standardMaxLevel, int retroMaxLevel) { public AbstractSkillCeiling(int standardMaxLevel, int retroMaxLevel) {
this.standardMaxLevel = standardMaxLevel; this.standardMaxLevel = standardMaxLevel;
this.retroMaxLevel = retroMaxLevel; this.retroMaxLevel = retroMaxLevel;
} }

View File

@ -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 * 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 * 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 * The maximum level for this skill in Retro
* Defaults to 1000 * Defaults to 1000